@oodle-ai/mobile-sdk-reactnative 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/OodleMobileSdkReactNative.podspec +24 -0
- package/README.md +191 -2
- package/android/build.gradle +55 -0
- package/android/proguard-rules.pro +5 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/ai/oodle/rum/Connectivity.kt +19 -0
- package/android/src/main/java/ai/oodle/rum/CrashReporter.kt +88 -0
- package/android/src/main/java/ai/oodle/rum/DeviceInfo.kt +50 -0
- package/android/src/main/java/ai/oodle/rum/ExitReasons.kt +104 -0
- package/android/src/main/java/ai/oodle/rum/NativeEvents.kt +24 -0
- package/android/src/main/java/ai/oodle/rum/OodleRumModule.kt +96 -0
- package/android/src/main/java/ai/oodle/rum/OodleRumPackage.kt +26 -0
- package/android/src/main/java/ai/oodle/rum/Storage.kt +84 -0
- package/android/src/main/java/ai/oodle/rum/Vitals.kt +188 -0
- package/android/src/main/java/ai/oodle/rum/Watchdog.kt +81 -0
- package/android/src/main/java/ai/oodle/rum/WireframeCapture.kt +398 -0
- package/bin/oodle-rum-upload.mjs +104 -0
- package/ios/OodleCrashReporter.h +16 -0
- package/ios/OodleCrashReporter.m +202 -0
- package/ios/OodleRum.h +18 -0
- package/ios/OodleRum.mm +129 -0
- package/ios/OodleRumImpl.swift +450 -0
- package/ios/WireframeWalker.swift +279 -0
- package/lib/core/clock.d.ts +19 -0
- package/lib/core/clock.js +47 -0
- package/lib/core/clock.js.map +1 -0
- package/lib/core/config.d.ts +142 -0
- package/lib/core/config.js +178 -0
- package/lib/core/config.js.map +1 -0
- package/lib/core/consent.d.ts +5 -0
- package/lib/core/consent.js +33 -0
- package/lib/core/consent.js.map +1 -0
- package/lib/core/context.d.ts +36 -0
- package/lib/core/context.js +172 -0
- package/lib/core/context.js.map +1 -0
- package/lib/core/flags.d.ts +3 -0
- package/lib/core/flags.js +20 -0
- package/lib/core/flags.js.map +1 -0
- package/lib/core/ids.d.ts +7 -0
- package/lib/core/ids.js +40 -0
- package/lib/core/ids.js.map +1 -0
- package/lib/core/internal.d.ts +6 -0
- package/lib/core/internal.js +10 -0
- package/lib/core/internal.js.map +1 -0
- package/lib/core/logger.d.ts +8 -0
- package/lib/core/logger.js +38 -0
- package/lib/core/logger.js.map +1 -0
- package/lib/core/native.d.ts +71 -0
- package/lib/core/native.js +156 -0
- package/lib/core/native.js.map +1 -0
- package/lib/core/rate-limiter.d.ts +7 -0
- package/lib/core/rate-limiter.js +31 -0
- package/lib/core/rate-limiter.js.map +1 -0
- package/lib/core/session.d.ts +51 -0
- package/lib/core/session.js +196 -0
- package/lib/core/session.js.map +1 -0
- package/lib/core/size.d.ts +15 -0
- package/lib/core/size.js +68 -0
- package/lib/core/size.js.map +1 -0
- package/lib/core/tags.d.ts +10 -0
- package/lib/core/tags.js +33 -0
- package/lib/core/tags.js.map +1 -0
- package/lib/core/telemetry.d.ts +6 -0
- package/lib/core/telemetry.js +37 -0
- package/lib/core/telemetry.js.map +1 -0
- package/lib/core/tracing.d.ts +9 -0
- package/lib/core/tracing.js +57 -0
- package/lib/core/tracing.js.map +1 -0
- package/lib/core/transport.d.ts +76 -0
- package/lib/core/transport.js +560 -0
- package/lib/core/transport.js.map +1 -0
- package/lib/core/user.d.ts +12 -0
- package/lib/core/user.js +41 -0
- package/lib/core/user.js.map +1 -0
- package/lib/events/actions.d.ts +13 -0
- package/lib/events/actions.js +147 -0
- package/lib/events/actions.js.map +1 -0
- package/lib/events/emit.d.ts +21 -0
- package/lib/events/emit.js +144 -0
- package/lib/events/emit.js.map +1 -0
- package/lib/events/errors.d.ts +19 -0
- package/lib/events/errors.js +257 -0
- package/lib/events/errors.js.map +1 -0
- package/lib/events/lifecycle.d.ts +7 -0
- package/lib/events/lifecycle.js +101 -0
- package/lib/events/lifecycle.js.map +1 -0
- package/lib/events/longtasks.d.ts +2 -0
- package/lib/events/longtasks.js +42 -0
- package/lib/events/longtasks.js.map +1 -0
- package/lib/events/resources.d.ts +15 -0
- package/lib/events/resources.js +156 -0
- package/lib/events/resources.js.map +1 -0
- package/lib/events/tap-target.d.ts +42 -0
- package/lib/events/tap-target.js +191 -0
- package/lib/events/tap-target.js.map +1 -0
- package/lib/events/view-state.d.ts +13 -0
- package/lib/events/view-state.js +25 -0
- package/lib/events/view-state.js.map +1 -0
- package/lib/events/views.d.ts +21 -0
- package/lib/events/views.js +347 -0
- package/lib/events/views.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +24 -0
- package/lib/index.js.map +1 -0
- package/lib/navigation/react-navigation.d.ts +33 -0
- package/lib/navigation/react-navigation.js +61 -0
- package/lib/navigation/react-navigation.js.map +1 -0
- package/lib/react/OodlePrivacy.d.ts +15 -0
- package/lib/react/OodlePrivacy.js +13 -0
- package/lib/react/OodlePrivacy.js.map +1 -0
- package/lib/react/OodleProvider.d.ts +18 -0
- package/lib/react/OodleProvider.js +72 -0
- package/lib/react/OodleProvider.js.map +1 -0
- package/lib/replay/recorder.d.ts +22 -0
- package/lib/replay/recorder.js +317 -0
- package/lib/replay/recorder.js.map +1 -0
- package/lib/replay/rrweb.d.ts +105 -0
- package/lib/replay/rrweb.js +335 -0
- package/lib/replay/rrweb.js.map +1 -0
- package/lib/rum.d.ts +52 -0
- package/lib/rum.js +281 -0
- package/lib/rum.js.map +1 -0
- package/lib/specs/NativeOodleRum.d.ts +43 -0
- package/lib/specs/NativeOodleRum.js +5 -0
- package/lib/specs/NativeOodleRum.js.map +1 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +6 -0
- package/lib/version.js.map +1 -0
- package/package.json +91 -4
- package/react-native.config.js +10 -0
- package/src/core/clock.ts +43 -0
- package/src/core/config.ts +344 -0
- package/src/core/consent.ts +32 -0
- package/src/core/context.ts +189 -0
- package/src/core/flags.ts +15 -0
- package/src/core/ids.ts +35 -0
- package/src/core/internal.ts +6 -0
- package/src/core/logger.ts +37 -0
- package/src/core/native.ts +201 -0
- package/src/core/rate-limiter.ts +34 -0
- package/src/core/session.ts +209 -0
- package/src/core/size.ts +79 -0
- package/src/core/tags.ts +30 -0
- package/src/core/telemetry.ts +35 -0
- package/src/core/tracing.ts +60 -0
- package/src/core/transport.ts +590 -0
- package/src/core/user.ts +45 -0
- package/src/events/actions.ts +157 -0
- package/src/events/emit.ts +131 -0
- package/src/events/errors.ts +283 -0
- package/src/events/lifecycle.ts +102 -0
- package/src/events/longtasks.ts +40 -0
- package/src/events/resources.ts +167 -0
- package/src/events/tap-target.ts +210 -0
- package/src/events/view-state.ts +30 -0
- package/src/events/views.ts +356 -0
- package/src/index.ts +34 -0
- package/src/navigation/react-navigation.ts +72 -0
- package/src/react/OodlePrivacy.tsx +25 -0
- package/src/react/OodleProvider.tsx +88 -0
- package/src/replay/recorder.ts +310 -0
- package/src/replay/rrweb.ts +460 -0
- package/src/rum.ts +295 -0
- package/src/specs/NativeOodleRum.ts +51 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isForeground = isForeground;
|
|
4
|
+
exports.installLifecycle = installLifecycle;
|
|
5
|
+
exports.uninstallLifecycle = uninstallLifecycle;
|
|
6
|
+
const react_native_1 = require("react-native");
|
|
7
|
+
const context_1 = require("../core/context");
|
|
8
|
+
const session_1 = require("../core/session");
|
|
9
|
+
const transport_1 = require("../core/transport");
|
|
10
|
+
const emit_1 = require("./emit");
|
|
11
|
+
const errors_1 = require("./errors");
|
|
12
|
+
const longtasks_1 = require("./longtasks");
|
|
13
|
+
const views_1 = require("./views");
|
|
14
|
+
/**
|
|
15
|
+
* The app state field of the OpenTelemetry `device.app.lifecycle` event
|
|
16
|
+
* (`android.app.state` or `ios.app.state`). The collector maps the state
|
|
17
|
+
* to the visibility the replay player shows.
|
|
18
|
+
*/
|
|
19
|
+
const APP_STATE_FIELD = react_native_1.Platform.OS === 'ios' ? 'ios_app_state' : 'android_app_state';
|
|
20
|
+
/** How often ANR and hang records are collected from native code. */
|
|
21
|
+
const NATIVE_DRAIN_MS = 5000;
|
|
22
|
+
let subscription = null;
|
|
23
|
+
let drainTimer = null;
|
|
24
|
+
let foreground = true;
|
|
25
|
+
let hooks = {};
|
|
26
|
+
function isForeground() {
|
|
27
|
+
return foreground;
|
|
28
|
+
}
|
|
29
|
+
function startDrain() {
|
|
30
|
+
if (drainTimer)
|
|
31
|
+
return;
|
|
32
|
+
drainTimer = setInterval(errors_1.drainNativeEvents, NATIVE_DRAIN_MS);
|
|
33
|
+
}
|
|
34
|
+
function stopDrain() {
|
|
35
|
+
if (drainTimer)
|
|
36
|
+
clearInterval(drainTimer);
|
|
37
|
+
drainTimer = null;
|
|
38
|
+
}
|
|
39
|
+
function toBackground() {
|
|
40
|
+
if (!foreground)
|
|
41
|
+
return;
|
|
42
|
+
foreground = false;
|
|
43
|
+
(0, longtasks_1.stopLongTaskTracking)();
|
|
44
|
+
stopDrain();
|
|
45
|
+
(0, errors_1.drainNativeEvents)();
|
|
46
|
+
(0, views_1.flushActiveView)();
|
|
47
|
+
(0, emit_1.emit)({ event_type: 'visibility', [APP_STATE_FIELD]: 'background' }, false);
|
|
48
|
+
(0, views_1.pauseViews)();
|
|
49
|
+
hooks.onBackground?.();
|
|
50
|
+
(0, context_1.saveLastContext)();
|
|
51
|
+
(0, session_1.flushSession)();
|
|
52
|
+
(0, transport_1.flush)();
|
|
53
|
+
// The OS can end a background app without warning.
|
|
54
|
+
(0, transport_1.persistOutbox)();
|
|
55
|
+
}
|
|
56
|
+
function toForeground() {
|
|
57
|
+
if (foreground)
|
|
58
|
+
return;
|
|
59
|
+
foreground = true;
|
|
60
|
+
const newSession = (0, session_1.isSessionExpired)();
|
|
61
|
+
(0, context_1.refreshConnectivity)();
|
|
62
|
+
// In a new session the hide belongs to the old one, so there is no
|
|
63
|
+
// return to pair it with.
|
|
64
|
+
if (!newSession)
|
|
65
|
+
(0, emit_1.emit)({ event_type: 'visibility', [APP_STATE_FIELD]: 'foreground' });
|
|
66
|
+
(0, views_1.resumeViews)();
|
|
67
|
+
hooks.onForeground?.(newSession);
|
|
68
|
+
(0, errors_1.drainNativeEvents)();
|
|
69
|
+
startDrain();
|
|
70
|
+
(0, longtasks_1.startLongTaskTracking)();
|
|
71
|
+
}
|
|
72
|
+
function onChange(state) {
|
|
73
|
+
if (!(0, emit_1.canRecord)())
|
|
74
|
+
return;
|
|
75
|
+
// iOS reports 'inactive' for the app switcher and system sheets; the
|
|
76
|
+
// app is still on screen, so only 'background' counts as leaving.
|
|
77
|
+
if (state === 'background')
|
|
78
|
+
toBackground();
|
|
79
|
+
else if (state === 'active')
|
|
80
|
+
toForeground();
|
|
81
|
+
}
|
|
82
|
+
function installLifecycle(h) {
|
|
83
|
+
hooks = h;
|
|
84
|
+
if (subscription)
|
|
85
|
+
return;
|
|
86
|
+
foreground = react_native_1.AppState.currentState !== 'background';
|
|
87
|
+
subscription = react_native_1.AppState.addEventListener('change', onChange);
|
|
88
|
+
if (foreground) {
|
|
89
|
+
startDrain();
|
|
90
|
+
(0, longtasks_1.startLongTaskTracking)();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function uninstallLifecycle() {
|
|
94
|
+
subscription?.remove();
|
|
95
|
+
subscription = null;
|
|
96
|
+
stopDrain();
|
|
97
|
+
(0, longtasks_1.stopLongTaskTracking)();
|
|
98
|
+
hooks = {};
|
|
99
|
+
foreground = true;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/events/lifecycle.ts"],"names":[],"mappings":";;;;;AAAA,+CAAqG;AACrG,6CAAuE;AACvE,6CAAiE;AACjE,iDAAyD;AACzD,iCAAyC;AACzC,qCAA6C;AAC7C,2CAA0E;AAC1E,mCAAmE;AA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Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startLongTaskTracking = startLongTaskTracking;
|
|
4
|
+
exports.stopLongTaskTracking = stopLongTaskTracking;
|
|
5
|
+
const config_1 = require("../core/config");
|
|
6
|
+
const emit_1 = require("./emit");
|
|
7
|
+
const clock_1 = require("../core/clock");
|
|
8
|
+
/**
|
|
9
|
+
* A timer that should fire every TICK_MS. When the JS thread is busy the
|
|
10
|
+
* timer fires late, and the delay is the time the thread was blocked.
|
|
11
|
+
* A timer is used rather than a frame callback so an idle app does not
|
|
12
|
+
* wake the JS thread on every frame.
|
|
13
|
+
*/
|
|
14
|
+
const TICK_MS = 50;
|
|
15
|
+
let timer = null;
|
|
16
|
+
let expected = 0;
|
|
17
|
+
function tick() {
|
|
18
|
+
const now = Date.now();
|
|
19
|
+
const blocked = now - expected;
|
|
20
|
+
const threshold = (0, config_1.getConfig)()?.longTaskThresholdMs ?? 0;
|
|
21
|
+
if (threshold > 0 && blocked >= threshold) {
|
|
22
|
+
(0, emit_1.emit)({
|
|
23
|
+
event_type: 'long_task',
|
|
24
|
+
timestamp: (0, clock_1.isoTime)(now - blocked),
|
|
25
|
+
long_task_duration_ms: blocked,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
expected = now + TICK_MS;
|
|
29
|
+
timer = setTimeout(tick, TICK_MS);
|
|
30
|
+
}
|
|
31
|
+
function startLongTaskTracking() {
|
|
32
|
+
if (timer || !((0, config_1.getConfig)()?.longTaskThresholdMs ?? 0))
|
|
33
|
+
return;
|
|
34
|
+
expected = Date.now() + TICK_MS;
|
|
35
|
+
timer = setTimeout(tick, TICK_MS);
|
|
36
|
+
}
|
|
37
|
+
function stopLongTaskTracking() {
|
|
38
|
+
if (timer)
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
timer = null;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=longtasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"longtasks.js","sourceRoot":"","sources":["../../src/events/longtasks.ts"],"names":[],"mappings":";;;;AAAA,2CAA2C;AAC3C,iCAA8B;AAC9B,yCAAwC;AAExC;;;;;GAKG;AACH,MAAM,OAAO,GAAG,EAAE,CAAC;AAEnB,IAAI,KAAK,GAAyC,IAAI,CAAC;AACvD,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB,SAAS,IAAI;IACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,OAAO,GAAG,GAAG,GAAG,QAAQ,CAAC;IAC/B,MAAM,SAAS,GAAG,IAAA,kBAAS,GAAE,EAAE,mBAAmB,IAAI,CAAC,CAAC;IACxD,IAAI,SAAS,GAAG,CAAC,IAAI,OAAO,IAAI,SAAS,EAAE,CAAC;QAC1C,IAAA,WAAI,EAAC;YACH,UAAU,EAAE,WAAW;YACvB,SAAS,EAAE,IAAA,eAAO,EAAC,GAAG,GAAG,OAAO,CAAC;YACjC,qBAAqB,EAAE,OAAO;SAC/B,CAAC,CAAC;IACL,CAAC;IACD,QAAQ,GAAG,GAAG,GAAG,OAAO,CAAC;IACzB,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC;AAED;IACE,IAAI,KAAK,IAAI,CAAC,CAAC,IAAA,kBAAS,GAAE,EAAE,mBAAmB,IAAI,CAAC,CAAC;QAAE,OAAO;IAC9D,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;IAChC,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC;AAED;IACE,IAAI,KAAK;QAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IAC/B,KAAK,GAAG,IAAI,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The URL without query string or fragment, which can hold tokens. */
|
|
2
|
+
/** The trace of a W3C `traceparent` header (version 00), or null. */
|
|
3
|
+
export declare function parseTraceparent(value: string): {
|
|
4
|
+
traceId: string;
|
|
5
|
+
spanId: string;
|
|
6
|
+
sampled: boolean;
|
|
7
|
+
} | null;
|
|
8
|
+
export declare function stripQuery(url: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* React Native's fetch runs on XMLHttpRequest, so patching XHR records
|
|
11
|
+
* both. `responseType` tells them apart: the fetch polyfill asks for a
|
|
12
|
+
* blob, and app code that uses XHR directly rarely does.
|
|
13
|
+
*/
|
|
14
|
+
export declare function installResourceTracking(): void;
|
|
15
|
+
export declare function uninstallResourceTracking(): void;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseTraceparent = parseTraceparent;
|
|
4
|
+
exports.stripQuery = stripQuery;
|
|
5
|
+
exports.installResourceTracking = installResourceTracking;
|
|
6
|
+
exports.uninstallResourceTracking = uninstallResourceTracking;
|
|
7
|
+
const config_1 = require("../core/config");
|
|
8
|
+
const internal_1 = require("../core/internal");
|
|
9
|
+
const tracing_1 = require("../core/tracing");
|
|
10
|
+
const emit_1 = require("./emit");
|
|
11
|
+
let originals = null;
|
|
12
|
+
function now() {
|
|
13
|
+
const p = globalThis.performance;
|
|
14
|
+
return typeof p?.now === 'function' ? p.now() : Date.now();
|
|
15
|
+
}
|
|
16
|
+
/** The URL without query string or fragment, which can hold tokens. */
|
|
17
|
+
/** The trace of a W3C `traceparent` header (version 00), or null. */
|
|
18
|
+
function parseTraceparent(value) {
|
|
19
|
+
const m = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/i.exec(value.trim());
|
|
20
|
+
if (!m || /^0+$/.test(m[1]) || /^0+$/.test(m[2]))
|
|
21
|
+
return null;
|
|
22
|
+
return { traceId: m[1].toLowerCase(), spanId: m[2].toLowerCase(), sampled: (parseInt(m[3], 16) & 1) === 1 };
|
|
23
|
+
}
|
|
24
|
+
function stripQuery(url) {
|
|
25
|
+
const cut = url.search(/[?#]/);
|
|
26
|
+
return cut >= 0 ? url.slice(0, cut) : url;
|
|
27
|
+
}
|
|
28
|
+
function isCollectorUrl(url) {
|
|
29
|
+
const endpoint = (0, config_1.getConfig)()?.endpoint;
|
|
30
|
+
return Boolean(endpoint && url.startsWith(endpoint));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* React Native's fetch runs on XMLHttpRequest, so patching XHR records
|
|
34
|
+
* both. `responseType` tells them apart: the fetch polyfill asks for a
|
|
35
|
+
* blob, and app code that uses XHR directly rarely does.
|
|
36
|
+
*/
|
|
37
|
+
function installResourceTracking() {
|
|
38
|
+
const XHR = globalThis
|
|
39
|
+
.XMLHttpRequest;
|
|
40
|
+
if (!XHR || originals)
|
|
41
|
+
return;
|
|
42
|
+
const proto = XHR.prototype;
|
|
43
|
+
originals = { open: proto.open, send: proto.send, setRequestHeader: proto.setRequestHeader };
|
|
44
|
+
const orig = originals;
|
|
45
|
+
proto.open = function (...args) {
|
|
46
|
+
const method = typeof args[0] === 'string' ? args[0].toUpperCase() : 'GET';
|
|
47
|
+
const url = typeof args[1] === 'string' ? args[1] : String(args[1] ?? '');
|
|
48
|
+
this.__oodle = { method, url, headers: new Map() };
|
|
49
|
+
return orig.open.apply(this, args);
|
|
50
|
+
};
|
|
51
|
+
proto.setRequestHeader = function (name, value) {
|
|
52
|
+
this.__oodle?.headers.set(String(name).toLowerCase(), String(value));
|
|
53
|
+
return orig.setRequestHeader.call(this, name, value);
|
|
54
|
+
};
|
|
55
|
+
proto.send = function (body) {
|
|
56
|
+
const info = this.__oodle;
|
|
57
|
+
const config = (0, config_1.getConfig)();
|
|
58
|
+
if (!info || this[internal_1.INTERNAL_REQUEST] || !config || isCollectorUrl(info.url)) {
|
|
59
|
+
return orig.send.call(this, body);
|
|
60
|
+
}
|
|
61
|
+
let traceId = '';
|
|
62
|
+
let spanId = '';
|
|
63
|
+
const rule = config.tracingUrls.find((r) => r.test(info.url));
|
|
64
|
+
const existing = info.headers.get('traceparent');
|
|
65
|
+
if (existing !== undefined) {
|
|
66
|
+
// The app or another tracing SDK set the header. It is kept, and the
|
|
67
|
+
// resource gets its trace, so RUM links to the same backend trace.
|
|
68
|
+
const parent = parseTraceparent(existing);
|
|
69
|
+
if (parent?.sampled) {
|
|
70
|
+
traceId = parent.traceId;
|
|
71
|
+
spanId = parent.spanId;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (rule) {
|
|
75
|
+
const ids = (0, tracing_1.newTraceIds)(config.traceSampleRate);
|
|
76
|
+
for (const [k, v] of Object.entries((0, tracing_1.tracingHeaders)(ids, rule.propagators))) {
|
|
77
|
+
if (!info.headers.has(k))
|
|
78
|
+
orig.setRequestHeader.call(this, k, v);
|
|
79
|
+
}
|
|
80
|
+
if (ids.sampled) {
|
|
81
|
+
traceId = ids.traceId;
|
|
82
|
+
spanId = ids.spanId;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const start = now();
|
|
86
|
+
let reported = false;
|
|
87
|
+
const done = () => {
|
|
88
|
+
if (reported)
|
|
89
|
+
return;
|
|
90
|
+
reported = true;
|
|
91
|
+
const status = this.status || 0;
|
|
92
|
+
const duration = Math.round(now() - start);
|
|
93
|
+
let size = 0;
|
|
94
|
+
try {
|
|
95
|
+
const len = this.getResponseHeader?.('content-length');
|
|
96
|
+
if (len)
|
|
97
|
+
size = parseInt(len, 10) || 0;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// header access can throw after an abort
|
|
101
|
+
}
|
|
102
|
+
const type = this.responseType === 'blob' ? 'fetch' : 'xhr';
|
|
103
|
+
const data = {
|
|
104
|
+
event_type: 'resource',
|
|
105
|
+
url_full: stripQuery(info.url),
|
|
106
|
+
http_request_method: info.method,
|
|
107
|
+
http_response_status_code: status,
|
|
108
|
+
resource_duration_ms: duration,
|
|
109
|
+
http_response_body_size: size,
|
|
110
|
+
resource_type: type,
|
|
111
|
+
};
|
|
112
|
+
if (traceId) {
|
|
113
|
+
data.trace_id = traceId;
|
|
114
|
+
data.span_id = spanId;
|
|
115
|
+
}
|
|
116
|
+
(0, emit_1.emit)(data);
|
|
117
|
+
if (status === 0) {
|
|
118
|
+
(0, emit_1.emit)({
|
|
119
|
+
event_type: 'error',
|
|
120
|
+
exception_message: `${info.method} ${stripQuery(info.url)} failed: network error`,
|
|
121
|
+
exception_type: 'NetworkError',
|
|
122
|
+
exception_stacktrace: '',
|
|
123
|
+
error_source: 'network',
|
|
124
|
+
error_is_crash: 0,
|
|
125
|
+
url_full: stripQuery(info.url),
|
|
126
|
+
http_request_method: info.method,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
try {
|
|
131
|
+
this.addEventListener('loadend', done);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// older XHR without addEventListener: fall back to readyState
|
|
135
|
+
const prev = this.onreadystatechange;
|
|
136
|
+
this.onreadystatechange = function (ev) {
|
|
137
|
+
if (this.readyState === 4)
|
|
138
|
+
done();
|
|
139
|
+
if (prev)
|
|
140
|
+
return prev.call(this, ev);
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return orig.send.call(this, body);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function uninstallResourceTracking() {
|
|
147
|
+
const XHR = globalThis
|
|
148
|
+
.XMLHttpRequest;
|
|
149
|
+
if (!XHR || !originals)
|
|
150
|
+
return;
|
|
151
|
+
XHR.prototype.open = originals.open;
|
|
152
|
+
XHR.prototype.send = originals.send;
|
|
153
|
+
XHR.prototype.setRequestHeader = originals.setRequestHeader;
|
|
154
|
+
originals = null;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/events/resources.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA2C;AAC3C,+CAAoD;AACpD,6CAA8D;AAC9D,iCA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I,UAAsE;SAChF,cAAc,CAAC;IAClB,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS;QAAE,OAAO;IAC/B,GAAG,CAAC,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IACpC,GAAG,CAAC,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;IACpC,GAAG,CAAC,SAAS,CAAC,gBAAgB,GAAG,SAAS,CAAC,gBAAgB,CAAC;IAC5D,SAAS,GAAG,IAAI,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds what a tap hit by walking the React fiber tree from the touched
|
|
3
|
+
* host view. React does not expose fibers as public API, so every field
|
|
4
|
+
* read here is guarded, and a failure yields a generic name instead of an
|
|
5
|
+
* exception.
|
|
6
|
+
*/
|
|
7
|
+
export interface FiberLike {
|
|
8
|
+
tag?: number;
|
|
9
|
+
type?: unknown;
|
|
10
|
+
elementType?: unknown;
|
|
11
|
+
memoizedProps?: unknown;
|
|
12
|
+
return?: FiberLike | null;
|
|
13
|
+
child?: FiberLike | null;
|
|
14
|
+
sibling?: FiberLike | null;
|
|
15
|
+
}
|
|
16
|
+
export interface TapTarget {
|
|
17
|
+
/** `Pressable ("Notifications, 1 unread")` */
|
|
18
|
+
name: string;
|
|
19
|
+
/** `Pressable` */
|
|
20
|
+
component: string;
|
|
21
|
+
/** `Notifications, 1 unread`, or empty */
|
|
22
|
+
label: string;
|
|
23
|
+
/** Component path above the target, outermost first. */
|
|
24
|
+
path: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ResolveOptions {
|
|
27
|
+
actionNameAttribute: string;
|
|
28
|
+
useAccessibilityLabel: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare function componentName(type: unknown): string;
|
|
31
|
+
/**
|
|
32
|
+
* Name of the component a fiber renders. `memo(forwardRef(Fn))` makes two
|
|
33
|
+
* fibers that share one props object, and only the outer one may carry a
|
|
34
|
+
* `displayName`. Release builds can rename functions, so a `displayName`
|
|
35
|
+
* on any of the wrappers wins over a function name.
|
|
36
|
+
*/
|
|
37
|
+
export declare function fiberName(f: FiberLike): string;
|
|
38
|
+
/** Text rendered under a fiber, in order, for a button without a label. */
|
|
39
|
+
export declare function collectText(root: FiberLike | null | undefined): string;
|
|
40
|
+
export declare function resolveTapTarget(start: FiberLike | null | undefined, opts: ResolveOptions): TapTarget | null;
|
|
41
|
+
/** Gets the fiber of the touched view from a React Native touch event. */
|
|
42
|
+
export declare function fiberFromEvent(event: unknown): FiberLike | null;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Finds what a tap hit by walking the React fiber tree from the touched
|
|
4
|
+
* host view. React does not expose fibers as public API, so every field
|
|
5
|
+
* read here is guarded, and a failure yields a generic name instead of an
|
|
6
|
+
* exception.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.componentName = componentName;
|
|
10
|
+
exports.fiberName = fiberName;
|
|
11
|
+
exports.collectText = collectText;
|
|
12
|
+
exports.resolveTapTarget = resolveTapTarget;
|
|
13
|
+
exports.fiberFromEvent = fiberFromEvent;
|
|
14
|
+
const MAX_DEPTH = 40;
|
|
15
|
+
const MAX_TEXT_NODES = 40;
|
|
16
|
+
const MAX_LABEL_CHARS = 100;
|
|
17
|
+
const HANDLER_PROPS = ['onPress', 'onLongPress', 'onValueChange', 'onPressIn'];
|
|
18
|
+
const BUTTON_ROLES = new Set([
|
|
19
|
+
'button',
|
|
20
|
+
'link',
|
|
21
|
+
'switch',
|
|
22
|
+
'checkbox',
|
|
23
|
+
'radio',
|
|
24
|
+
'tab',
|
|
25
|
+
'menuitem',
|
|
26
|
+
'togglebutton',
|
|
27
|
+
'imagebutton',
|
|
28
|
+
]);
|
|
29
|
+
/** Host component names that say nothing about what was tapped. */
|
|
30
|
+
const GENERIC_HOSTS = new Set(['RCTView', 'View', 'RCTText', 'Text', 'RCTScrollView', 'AndroidHorizontalScrollView']);
|
|
31
|
+
function props(f) {
|
|
32
|
+
const p = f.memoizedProps;
|
|
33
|
+
return p && typeof p === 'object' ? p : {};
|
|
34
|
+
}
|
|
35
|
+
function componentName(type) {
|
|
36
|
+
if (typeof type === 'string')
|
|
37
|
+
return type;
|
|
38
|
+
if (!type || (typeof type !== 'function' && typeof type !== 'object'))
|
|
39
|
+
return '';
|
|
40
|
+
const t = type;
|
|
41
|
+
if (typeof t.displayName === 'string' && t.displayName)
|
|
42
|
+
return t.displayName;
|
|
43
|
+
if (typeof t.name === 'string' && t.name)
|
|
44
|
+
return t.name;
|
|
45
|
+
if (t.render) {
|
|
46
|
+
if (typeof t.render.displayName === 'string' && t.render.displayName)
|
|
47
|
+
return t.render.displayName;
|
|
48
|
+
if (typeof t.render.name === 'string' && t.render.name)
|
|
49
|
+
return t.render.name;
|
|
50
|
+
}
|
|
51
|
+
if (t.type && t.type !== type)
|
|
52
|
+
return componentName(t.type);
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
function displayNameOf(type) {
|
|
56
|
+
if (!type || (typeof type !== 'function' && typeof type !== 'object'))
|
|
57
|
+
return '';
|
|
58
|
+
const d = type.displayName;
|
|
59
|
+
return typeof d === 'string' ? d : '';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Name of the component a fiber renders. `memo(forwardRef(Fn))` makes two
|
|
63
|
+
* fibers that share one props object, and only the outer one may carry a
|
|
64
|
+
* `displayName`. Release builds can rename functions, so a `displayName`
|
|
65
|
+
* on any of the wrappers wins over a function name.
|
|
66
|
+
*/
|
|
67
|
+
function fiberName(f) {
|
|
68
|
+
let fallback = '';
|
|
69
|
+
let cur = f;
|
|
70
|
+
for (let i = 0; cur && i < 4; i++) {
|
|
71
|
+
const d = displayNameOf(cur.type) || displayNameOf(cur.elementType);
|
|
72
|
+
if (d)
|
|
73
|
+
return d;
|
|
74
|
+
if (!fallback)
|
|
75
|
+
fallback = componentName(cur.type) || componentName(cur.elementType);
|
|
76
|
+
const parent = cur.return;
|
|
77
|
+
if (!parent || parent.memoizedProps !== cur.memoizedProps)
|
|
78
|
+
break;
|
|
79
|
+
cur = parent;
|
|
80
|
+
}
|
|
81
|
+
return fallback;
|
|
82
|
+
}
|
|
83
|
+
function isPressable(f) {
|
|
84
|
+
const p = props(f);
|
|
85
|
+
for (const h of HANDLER_PROPS)
|
|
86
|
+
if (typeof p[h] === 'function')
|
|
87
|
+
return true;
|
|
88
|
+
const role = p.accessibilityRole ?? p.role;
|
|
89
|
+
return typeof role === 'string' && BUTTON_ROLES.has(role) && typeof f.type !== 'string';
|
|
90
|
+
}
|
|
91
|
+
function stringProp(p, key) {
|
|
92
|
+
const v = p[key];
|
|
93
|
+
return typeof v === 'string' && v.trim() ? v.trim() : '';
|
|
94
|
+
}
|
|
95
|
+
function clipLabel(s) {
|
|
96
|
+
const one = s.replace(/\s+/g, ' ').trim();
|
|
97
|
+
return one.length > MAX_LABEL_CHARS ? one.slice(0, MAX_LABEL_CHARS - 1) + '…' : one;
|
|
98
|
+
}
|
|
99
|
+
/** Text rendered under a fiber, in order, for a button without a label. */
|
|
100
|
+
function collectText(root) {
|
|
101
|
+
if (!root)
|
|
102
|
+
return '';
|
|
103
|
+
const parts = [];
|
|
104
|
+
const stack = root.child ? [root.child] : [];
|
|
105
|
+
let visited = 0;
|
|
106
|
+
while (stack.length > 0 && parts.length < MAX_TEXT_NODES && visited < 500) {
|
|
107
|
+
const f = stack.pop();
|
|
108
|
+
visited++;
|
|
109
|
+
if (f.sibling)
|
|
110
|
+
stack.push(f.sibling);
|
|
111
|
+
const p = f.memoizedProps;
|
|
112
|
+
// Host text fibers keep the string itself as their props.
|
|
113
|
+
if (typeof p === 'string' || typeof p === 'number') {
|
|
114
|
+
if (String(p).trim())
|
|
115
|
+
parts.push(String(p));
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (f.child)
|
|
119
|
+
stack.push(f.child);
|
|
120
|
+
}
|
|
121
|
+
return clipLabel(parts.join(' '));
|
|
122
|
+
}
|
|
123
|
+
function resolveTapTarget(start, opts) {
|
|
124
|
+
if (!start)
|
|
125
|
+
return null;
|
|
126
|
+
let pressable = null;
|
|
127
|
+
let explicitName = '';
|
|
128
|
+
let a11yLabel = '';
|
|
129
|
+
const names = [];
|
|
130
|
+
// Levels walked above the button. The name attribute may sit on a
|
|
131
|
+
// wrapper a little higher up, so the walk goes on for a few levels.
|
|
132
|
+
let above = 0;
|
|
133
|
+
let f = start;
|
|
134
|
+
for (let depth = 0; f && depth < MAX_DEPTH; depth++, f = f.return) {
|
|
135
|
+
const p = props(f);
|
|
136
|
+
if (!explicitName)
|
|
137
|
+
explicitName = stringProp(p, opts.actionNameAttribute);
|
|
138
|
+
if (!pressable && opts.useAccessibilityLabel && !a11yLabel) {
|
|
139
|
+
a11yLabel = stringProp(p, 'accessibilityLabel') || stringProp(p, 'aria-label');
|
|
140
|
+
}
|
|
141
|
+
if (!pressable && isPressable(f)) {
|
|
142
|
+
pressable = f;
|
|
143
|
+
// A button's own label beats one found on a child below it.
|
|
144
|
+
if (opts.useAccessibilityLabel) {
|
|
145
|
+
a11yLabel =
|
|
146
|
+
stringProp(p, 'accessibilityLabel') || stringProp(p, 'aria-label') || a11yLabel;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (typeof f.type !== 'string') {
|
|
150
|
+
const n = componentName(f.type);
|
|
151
|
+
if (n && names.length < 6 && names[names.length - 1] !== n)
|
|
152
|
+
names.push(n);
|
|
153
|
+
}
|
|
154
|
+
if (pressable && (explicitName || ++above > 3))
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
const target = pressable ?? start;
|
|
158
|
+
let component = fiberName(target);
|
|
159
|
+
if (!component || GENERIC_HOSTS.has(component)) {
|
|
160
|
+
component = pressable ? component || 'Touchable' : 'View';
|
|
161
|
+
}
|
|
162
|
+
const tp = props(target);
|
|
163
|
+
const label = clipLabel(explicitName ||
|
|
164
|
+
a11yLabel ||
|
|
165
|
+
stringProp(tp, 'title') ||
|
|
166
|
+
stringProp(tp, 'label') ||
|
|
167
|
+
collectText(target));
|
|
168
|
+
// A tap on something that does not respond to taps is not an action.
|
|
169
|
+
if (!pressable && !explicitName)
|
|
170
|
+
return null;
|
|
171
|
+
return {
|
|
172
|
+
name: explicitName ? explicitName : label ? `${component} ("${label}")` : component,
|
|
173
|
+
component,
|
|
174
|
+
label,
|
|
175
|
+
path: names.slice().reverse().join(' > '),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/** Gets the fiber of the touched view from a React Native touch event. */
|
|
179
|
+
function fiberFromEvent(event) {
|
|
180
|
+
if (!event || typeof event !== 'object')
|
|
181
|
+
return null;
|
|
182
|
+
const e = event;
|
|
183
|
+
if (e._targetInst)
|
|
184
|
+
return e._targetInst;
|
|
185
|
+
const t = e.target;
|
|
186
|
+
if (t && typeof t === 'object') {
|
|
187
|
+
return t.__internalInstanceHandle ?? t._internalFiberInstanceHandleDEV ?? null;
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=tap-target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tap-target.js","sourceRoot":"","sources":["../../src/events/tap-target.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;AA4BH,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,eAAe,GAAG,GAAG,CAAC;AAC5B,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,CAAC,CAAC;AAC/E,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,QAAQ;IACR,MAAM;IACN,QAAQ;IACR,UAAU;IACV,OAAO;IACP,KAAK;IACL,UAAU;IACV,cAAc;IACd,aAAa;CACd,CAAC,CAAC;AACH,mEAAmE;AACn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AC;IACzB,MAAM,KAAK,GAAG,SAAS,CACrB,YAAY;QACV,SAAS;QACT,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC;QACvB,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC;QACvB,WAAW,CAAC,MAAM,CAAC,CACtB,CAAC;IACF,qEAAqE;IACrE,IAAI,CAAC,SAAS,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAC7C,OAAO;QACL,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS;QACnF,SAAS;QACT,KAAK;QACL,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED,0EAA0E;AAC1E,wBAA+B,KAAc;IAC3C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACrD,MAAM,CAAC,GAAG,KAGT,CAAC;IACF,IAAI,CAAC,CAAC,WAAW;QAAE,OAAO,CAAC,CAAC,WAAW,CAAC;IACxC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,CAAC,wBAAwB,IAAI,CAAC,CAAC,+BAA+B,IAAI,IAAI,CAAC;IACjF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The screen on display. Kept apart from views.ts so the event context can read it without an import cycle. */
|
|
2
|
+
export interface ViewInfo {
|
|
3
|
+
id: string;
|
|
4
|
+
key: string;
|
|
5
|
+
name: string;
|
|
6
|
+
url: string;
|
|
7
|
+
path: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function setCurrentViewInfo(next: ViewInfo | null): void;
|
|
10
|
+
export declare function getCurrentViewInfo(): ViewInfo | null;
|
|
11
|
+
/** The screen shown before the current one (`app.screen.previous.name`). */
|
|
12
|
+
export declare function getPreviousScreenName(): string;
|
|
13
|
+
export declare function resetViewInfo(): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setCurrentViewInfo = setCurrentViewInfo;
|
|
4
|
+
exports.getCurrentViewInfo = getCurrentViewInfo;
|
|
5
|
+
exports.getPreviousScreenName = getPreviousScreenName;
|
|
6
|
+
exports.resetViewInfo = resetViewInfo;
|
|
7
|
+
let current = null;
|
|
8
|
+
let previousName = '';
|
|
9
|
+
function setCurrentViewInfo(next) {
|
|
10
|
+
if (current && next && current.id !== next.id)
|
|
11
|
+
previousName = current.name;
|
|
12
|
+
current = next;
|
|
13
|
+
}
|
|
14
|
+
function getCurrentViewInfo() {
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
/** The screen shown before the current one (`app.screen.previous.name`). */
|
|
18
|
+
function getPreviousScreenName() {
|
|
19
|
+
return previousName;
|
|
20
|
+
}
|
|
21
|
+
function resetViewInfo() {
|
|
22
|
+
current = null;
|
|
23
|
+
previousName = '';
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=view-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-state.js","sourceRoot":"","sources":["../../src/events/view-state.ts"],"names":[],"mappings":";;;;;;AASA,IAAI,OAAO,GAAoB,IAAI,CAAC;AACpC,IAAI,YAAY,GAAG,EAAE,CAAC;AAEtB,4BAAmC,IAAqB;IACtD,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE;QAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3E,OAAO,GAAG,IAAI,CAAC;AACjB,CAAC;AAED;IACE,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,4EAA4E;AAC5E;IACE,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;IACE,OAAO,GAAG,IAAI,CAAC;IACf,YAAY,GAAG,EAAE,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ViewInfo } from './view-state';
|
|
2
|
+
export declare function onViewStart(fn: (v: ViewInfo) => void): void;
|
|
3
|
+
export declare function startView(key: string, name?: string, attributes?: Record<string, unknown>, startMs?: number): void;
|
|
4
|
+
export declare function stopView(key?: string): void;
|
|
5
|
+
export declare function getActiveView(): ViewInfo | null;
|
|
6
|
+
/** Marks the current view as loaded. Sets `view_loading_time_ms`. */
|
|
7
|
+
export declare function reportViewLoaded(overwrite?: boolean): void;
|
|
8
|
+
/** Time to full display: the app start until its first screen has its data. */
|
|
9
|
+
export declare function reportAppFullyDisplayed(): void;
|
|
10
|
+
/** Time since the current view started, or -1 when there is none. */
|
|
11
|
+
export declare function viewElapsedMs(): number;
|
|
12
|
+
export declare function addViewAttributes(attrs: Record<string, unknown>): void;
|
|
13
|
+
/** Ends the view while the app is in the background, so time away is not counted. */
|
|
14
|
+
export declare function pauseViews(): void;
|
|
15
|
+
/** Starts the paused view again as a new view instance. */
|
|
16
|
+
export declare function resumeViews(): void;
|
|
17
|
+
/** Session ended: the open view belongs to the old session. */
|
|
18
|
+
export declare function restartViewForNewSession(sessionId: string): void;
|
|
19
|
+
export declare function flushActiveView(): void;
|
|
20
|
+
/** Test hook. */
|
|
21
|
+
export declare function resetViews(): void;
|