@metarouter/react-native-sdk 1.7.0 → 1.9.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.
Files changed (66) hide show
  1. package/README.md +302 -61
  2. package/android/build.gradle +2 -0
  3. package/android/src/main/java/com/metarouter/reactnative/MetaRouterClockModule.kt +24 -0
  4. package/android/src/main/java/com/metarouter/reactnative/MetaRouterPackage.kt +3 -1
  5. package/android/src/main/java/com/metarouter/reactnative/MetaRouterWebViewSupportModule.kt +27 -0
  6. package/ios/MetaRouterClock.m +31 -0
  7. package/lib/analytics/MetaRouterAnalyticsClient.d.ts +71 -2
  8. package/lib/analytics/MetaRouterAnalyticsClient.d.ts.map +1 -1
  9. package/lib/analytics/MetaRouterAnalyticsClient.js +313 -51
  10. package/lib/analytics/init.d.ts +7 -0
  11. package/lib/analytics/init.d.ts.map +1 -1
  12. package/lib/analytics/init.js +210 -37
  13. package/lib/analytics/lifecycle/lifecycleEvents.d.ts +52 -0
  14. package/lib/analytics/lifecycle/lifecycleEvents.d.ts.map +1 -0
  15. package/lib/analytics/lifecycle/lifecycleEvents.js +66 -0
  16. package/lib/analytics/proxy/proxyClient.d.ts +31 -0
  17. package/lib/analytics/proxy/proxyClient.d.ts.map +1 -1
  18. package/lib/analytics/proxy/proxyClient.js +153 -6
  19. package/lib/analytics/session/sessionManager.d.ts +108 -0
  20. package/lib/analytics/session/sessionManager.d.ts.map +1 -0
  21. package/lib/analytics/session/sessionManager.js +193 -0
  22. package/lib/analytics/types.d.ts +108 -1
  23. package/lib/analytics/types.d.ts.map +1 -1
  24. package/lib/analytics/utils/appContext.d.ts +22 -0
  25. package/lib/analytics/utils/appContext.d.ts.map +1 -0
  26. package/lib/analytics/utils/appContext.js +23 -0
  27. package/lib/analytics/utils/contextInfo.d.ts +7 -3
  28. package/lib/analytics/utils/contextInfo.d.ts.map +1 -1
  29. package/lib/analytics/utils/contextInfo.js +12 -9
  30. package/lib/analytics/utils/enrichEvent.d.ts +6 -2
  31. package/lib/analytics/utils/enrichEvent.d.ts.map +1 -1
  32. package/lib/analytics/utils/enrichEvent.js +20 -3
  33. package/lib/analytics/utils/initOptions.d.ts +22 -0
  34. package/lib/analytics/utils/initOptions.d.ts.map +1 -0
  35. package/lib/analytics/utils/initOptions.js +107 -0
  36. package/lib/analytics/utils/lifecycleStorage.d.ts +13 -0
  37. package/lib/analytics/utils/lifecycleStorage.d.ts.map +1 -0
  38. package/lib/analytics/utils/lifecycleStorage.js +35 -0
  39. package/lib/analytics/utils/monotonicClock.d.ts +15 -0
  40. package/lib/analytics/utils/monotonicClock.d.ts.map +1 -0
  41. package/lib/analytics/utils/monotonicClock.js +52 -0
  42. package/lib/analytics/utils/sessionStorage.d.ts +27 -0
  43. package/lib/analytics/utils/sessionStorage.d.ts.map +1 -0
  44. package/lib/analytics/utils/sessionStorage.js +85 -0
  45. package/lib/analytics/webview/bridgeDedupStore.d.ts +37 -0
  46. package/lib/analytics/webview/bridgeDedupStore.d.ts.map +1 -0
  47. package/lib/analytics/webview/bridgeDedupStore.js +63 -0
  48. package/lib/analytics/webview/bridgeEnvelope.d.ts +68 -0
  49. package/lib/analytics/webview/bridgeEnvelope.d.ts.map +1 -0
  50. package/lib/analytics/webview/bridgeEnvelope.js +140 -0
  51. package/lib/analytics/webview/bridgeMessageProcessor.d.ts +38 -0
  52. package/lib/analytics/webview/bridgeMessageProcessor.d.ts.map +1 -0
  53. package/lib/analytics/webview/bridgeMessageProcessor.js +67 -0
  54. package/lib/analytics/webview/bridgeWrapperScript.d.ts +53 -0
  55. package/lib/analytics/webview/bridgeWrapperScript.d.ts.map +1 -0
  56. package/lib/analytics/webview/bridgeWrapperScript.js +161 -0
  57. package/lib/analytics/webview/webViewBridge.d.ts +39 -0
  58. package/lib/analytics/webview/webViewBridge.d.ts.map +1 -0
  59. package/lib/analytics/webview/webViewBridge.js +211 -0
  60. package/lib/analytics/webview/webViewSupport.d.ts +16 -0
  61. package/lib/analytics/webview/webViewSupport.d.ts.map +1 -0
  62. package/lib/analytics/webview/webViewSupport.js +52 -0
  63. package/lib/index.d.ts +4 -4
  64. package/lib/index.d.ts.map +1 -1
  65. package/lib/index.js +3 -3
  66. package/package.json +11 -3
@@ -0,0 +1,108 @@
1
+ import { saveSession, type StoredSession } from '../utils/sessionStorage';
2
+ /**
3
+ * Emitted when a new session is minted and `fireSessionStarted` is on. The
4
+ * name matches the web SDK's session-management sync verbatim (the pipeline
5
+ * snake_cases it to `session_started`), so mappings keyed on the event name
6
+ * treat every platform as one.
7
+ */
8
+ export declare const SESSION_STARTED_EVENT = "Session Started";
9
+ export declare const DEFAULT_SESSION_TIMEOUT_MINUTES = 30;
10
+ /**
11
+ * The persisted last-activity only matters across a process restart, where its
12
+ * precision competes with a timeout of at least one minute — a write per event
13
+ * is pure AsyncStorage churn under a chatty producer (rapid screen tracking).
14
+ * Under a monotone wall clock, a crash loses at most this much of the window.
15
+ */
16
+ export declare const PERSIST_THROTTLE_MS = 5000;
17
+ /**
18
+ * The session an event belongs to.
19
+ * - `sessionId`: epoch ms of the session's first activity, as a string — the
20
+ * format the web SDK's MetaRouter session mints.
21
+ * - `sessionCount`: lifetime session ordinal for this install, from 1.
22
+ * - `startedNewSession`: true exactly once per session, on the touch that
23
+ * minted it.
24
+ */
25
+ export interface SessionInfo {
26
+ sessionId: string;
27
+ sessionCount: number;
28
+ startedNewSession: boolean;
29
+ }
30
+ export interface SessionManagerDeps {
31
+ load?: () => Promise<StoredSession>;
32
+ saveSession?: typeof saveSession;
33
+ wallClockMs?: () => number;
34
+ monotonicClockMs?: () => number;
35
+ }
36
+ /**
37
+ * Owns the sliding-inactivity session: mints, extends and rolls it over, with
38
+ * the same rules as the iOS and Android SessionManager.
39
+ *
40
+ * A session ends after `timeoutMinutes` of inactivity, where activity is any
41
+ * touch() — one per outbound event. The window slides: steady activity extends
42
+ * the session indefinitely (web MetaRouter session and GA4's app-session
43
+ * model), NOT the web GA4 injector's from-start cap.
44
+ *
45
+ * Two clocks, on purpose:
46
+ * - In-process inactivity is measured on a monotonic clock that counts through
47
+ * sleep. Wall-clock can jump minutes either way (NTP, user changes the time)
48
+ * and would end or immortalize a session that saw no real inactivity.
49
+ * - Across restarts only wall-clock survives, so the persisted last-activity is
50
+ * epoch ms. A persisted reading from the future (clock set back since) is
51
+ * treated as expired: resuming would make the session immortal until the
52
+ * clock catches up, while minting costs one extra session.
53
+ *
54
+ * Rollover uses `>` (exactly `timeout` old is still the same session) to stay
55
+ * boundary-identical with web, iOS and Android.
56
+ *
57
+ * AsyncStorage is async but enrichment is not, so the persisted state is read
58
+ * once by load() — which init() awaits before any event can be enriched — and
59
+ * every write after that is fire-and-forget. JS is single-threaded, so the
60
+ * native locks have no counterpart here.
61
+ */
62
+ export declare class SessionManager {
63
+ private readonly timeoutMs;
64
+ private readonly load;
65
+ private readonly persistSession;
66
+ private readonly wallClockMs;
67
+ private readonly monotonicClockMs;
68
+ private stored;
69
+ private sessionId;
70
+ private sessionCount;
71
+ private lastActivityMono;
72
+ private lastActivityWall;
73
+ private lastPersistedMono;
74
+ private onSessionStart;
75
+ constructor(timeoutMinutes?: number, deps?: SessionManagerDeps);
76
+ /**
77
+ * Reads the persisted session so the first touch can resume it. Must settle
78
+ * before the first touch(); a touch without it mints a new session over the
79
+ * stored one. A no-op once this process has a session.
80
+ */
81
+ loadPersisted(): Promise<void>;
82
+ /**
83
+ * Writes the latest activity now, skipping the throttle. Called on reset():
84
+ * the next client resumes from storage, and a write held back by the
85
+ * throttle would leave it up to a throttle window short.
86
+ */
87
+ persistActivity(): void;
88
+ /**
89
+ * Handler for "a new session was minted". Set before events can flow: a
90
+ * handler installed after the install's first mint drops its Session
91
+ * Started, which never recurs for that session.
92
+ */
93
+ setOnSessionStart(handler: ((info: SessionInfo) => void) | null): void;
94
+ /**
95
+ * Records activity and returns the session it belongs to, minting or rolling
96
+ * over first when the inactivity window has lapsed. Call once per outbound
97
+ * event.
98
+ */
99
+ touch(): SessionInfo;
100
+ /**
101
+ * The current session without recording activity — a read must not extend
102
+ * the window, or a diagnostics poller could keep a session alive forever.
103
+ * Null before the first touch() of the process.
104
+ */
105
+ peek(): SessionInfo | null;
106
+ private mint;
107
+ }
108
+ //# sourceMappingURL=sessionManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessionManager.d.ts","sourceRoot":"","sources":["../../../src/analytics/session/sessionManager.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,WAAW,EACX,KAAK,aAAa,EACnB,MAAM,yBAAyB,CAAC;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAEvD,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,OAAQ,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,OAAO,WAAW,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,MAAM,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA+B;IACpD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAqB;IACpD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAe;IAEhD,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,cAAc,CAA8C;gBAGlE,cAAc,GAAE,MAAwC,EACxD,IAAI,GAAE,kBAAuB;IAc/B;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAKpC;;;;OAIG;IACH,eAAe,IAAI,IAAI;IASvB;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI;IAItE;;;;OAIG;IACH,KAAK,IAAI,WAAW;IAgEpB;;;;OAIG;IACH,IAAI,IAAI,WAAW,GAAG,IAAI;IAS1B,OAAO,CAAC,IAAI;CAkBb"}
@@ -0,0 +1,193 @@
1
+ import { continuousMillis } from '../utils/monotonicClock';
2
+ import { loadSession, saveSession, } from '../utils/sessionStorage';
3
+ /**
4
+ * Emitted when a new session is minted and `fireSessionStarted` is on. The
5
+ * name matches the web SDK's session-management sync verbatim (the pipeline
6
+ * snake_cases it to `session_started`), so mappings keyed on the event name
7
+ * treat every platform as one.
8
+ */
9
+ export const SESSION_STARTED_EVENT = 'Session Started';
10
+ export const DEFAULT_SESSION_TIMEOUT_MINUTES = 30;
11
+ /**
12
+ * The persisted last-activity only matters across a process restart, where its
13
+ * precision competes with a timeout of at least one minute — a write per event
14
+ * is pure AsyncStorage churn under a chatty producer (rapid screen tracking).
15
+ * Under a monotone wall clock, a crash loses at most this much of the window.
16
+ */
17
+ export const PERSIST_THROTTLE_MS = 5000;
18
+ /**
19
+ * Owns the sliding-inactivity session: mints, extends and rolls it over, with
20
+ * the same rules as the iOS and Android SessionManager.
21
+ *
22
+ * A session ends after `timeoutMinutes` of inactivity, where activity is any
23
+ * touch() — one per outbound event. The window slides: steady activity extends
24
+ * the session indefinitely (web MetaRouter session and GA4's app-session
25
+ * model), NOT the web GA4 injector's from-start cap.
26
+ *
27
+ * Two clocks, on purpose:
28
+ * - In-process inactivity is measured on a monotonic clock that counts through
29
+ * sleep. Wall-clock can jump minutes either way (NTP, user changes the time)
30
+ * and would end or immortalize a session that saw no real inactivity.
31
+ * - Across restarts only wall-clock survives, so the persisted last-activity is
32
+ * epoch ms. A persisted reading from the future (clock set back since) is
33
+ * treated as expired: resuming would make the session immortal until the
34
+ * clock catches up, while minting costs one extra session.
35
+ *
36
+ * Rollover uses `>` (exactly `timeout` old is still the same session) to stay
37
+ * boundary-identical with web, iOS and Android.
38
+ *
39
+ * AsyncStorage is async but enrichment is not, so the persisted state is read
40
+ * once by load() — which init() awaits before any event can be enriched — and
41
+ * every write after that is fire-and-forget. JS is single-threaded, so the
42
+ * native locks have no counterpart here.
43
+ */
44
+ export class SessionManager {
45
+ constructor(timeoutMinutes = DEFAULT_SESSION_TIMEOUT_MINUTES, deps = {}) {
46
+ var _a, _b, _c, _d;
47
+ this.stored = null;
48
+ this.sessionId = null;
49
+ this.sessionCount = 0;
50
+ this.lastActivityMono = 0;
51
+ this.lastActivityWall = 0;
52
+ this.lastPersistedMono = 0;
53
+ this.onSessionStart = null;
54
+ // Clamped with a warning at the InitOptions boundary; by here a
55
+ // non-positive timeout is SDK-internal misuse, not user input.
56
+ if (!(timeoutMinutes > 0)) {
57
+ throw new Error('timeoutMinutes must be > 0');
58
+ }
59
+ this.timeoutMs = timeoutMinutes * 60000;
60
+ this.load = (_a = deps.load) !== null && _a !== void 0 ? _a : loadSession;
61
+ this.persistSession = (_b = deps.saveSession) !== null && _b !== void 0 ? _b : saveSession;
62
+ this.wallClockMs = (_c = deps.wallClockMs) !== null && _c !== void 0 ? _c : Date.now;
63
+ this.monotonicClockMs = (_d = deps.monotonicClockMs) !== null && _d !== void 0 ? _d : continuousMillis;
64
+ }
65
+ /**
66
+ * Reads the persisted session so the first touch can resume it. Must settle
67
+ * before the first touch(); a touch without it mints a new session over the
68
+ * stored one. A no-op once this process has a session.
69
+ */
70
+ async loadPersisted() {
71
+ if (this.sessionId !== null)
72
+ return;
73
+ this.stored = await this.load();
74
+ }
75
+ /**
76
+ * Writes the latest activity now, skipping the throttle. Called on reset():
77
+ * the next client resumes from storage, and a write held back by the
78
+ * throttle would leave it up to a throttle window short.
79
+ */
80
+ persistActivity() {
81
+ if (this.sessionId === null)
82
+ return;
83
+ this.persistSession(this.sessionId, this.sessionCount, this.lastActivityWall);
84
+ }
85
+ /**
86
+ * Handler for "a new session was minted". Set before events can flow: a
87
+ * handler installed after the install's first mint drops its Session
88
+ * Started, which never recurs for that session.
89
+ */
90
+ setOnSessionStart(handler) {
91
+ this.onSessionStart = handler;
92
+ }
93
+ /**
94
+ * Records activity and returns the session it belongs to, minting or rolling
95
+ * over first when the inactivity window has lapsed. Call once per outbound
96
+ * event.
97
+ */
98
+ touch() {
99
+ var _a;
100
+ const wallNow = this.wallClockMs();
101
+ const monoNow = this.monotonicClockMs();
102
+ let info;
103
+ if (this.sessionId !== null) {
104
+ if (monoNow - this.lastActivityMono > this.timeoutMs) {
105
+ info = this.mint(wallNow, monoNow);
106
+ }
107
+ else {
108
+ this.lastActivityMono = monoNow;
109
+ this.lastActivityWall = wallNow;
110
+ if (monoNow - this.lastPersistedMono >= PERSIST_THROTTLE_MS) {
111
+ this.persistSession(this.sessionId, this.sessionCount, wallNow);
112
+ this.lastPersistedMono = monoNow;
113
+ }
114
+ info = {
115
+ sessionId: this.sessionId,
116
+ sessionCount: this.sessionCount,
117
+ startedNewSession: false,
118
+ };
119
+ }
120
+ }
121
+ else {
122
+ // First touch of this process: resume the persisted session when the
123
+ // restart happened inside the inactivity window.
124
+ const stored = this.stored;
125
+ if ((stored === null || stored === void 0 ? void 0 : stored.id) != null &&
126
+ stored.lastActivityMs != null &&
127
+ stored.lastActivityMs <= wallNow &&
128
+ wallNow - stored.lastActivityMs <= this.timeoutMs) {
129
+ this.sessionId = stored.id;
130
+ this.sessionCount = (_a = stored.count) !== null && _a !== void 0 ? _a : 1;
131
+ this.lastActivityMono = monoNow;
132
+ this.lastActivityWall = wallNow;
133
+ // Once per process — no throttle; skipping it would leave the
134
+ // pre-restart timestamp in place for up to a throttle window.
135
+ this.persistSession(this.sessionId, this.sessionCount, wallNow);
136
+ this.lastPersistedMono = monoNow;
137
+ info = {
138
+ sessionId: stored.id,
139
+ sessionCount: this.sessionCount,
140
+ startedNewSession: false,
141
+ };
142
+ }
143
+ else {
144
+ info = this.mint(wallNow, monoNow);
145
+ }
146
+ }
147
+ if (info.startedNewSession) {
148
+ // Deferred so the event that minted the session is enqueued first, as on
149
+ // iOS and Android, where Session Started rides a later task. Its own
150
+ // enrichment re-enters touch() and sees startedNewSession=false, so the
151
+ // handler cannot loop.
152
+ const handler = this.onSessionStart;
153
+ if (handler) {
154
+ Promise.resolve(info)
155
+ .then(handler)
156
+ .catch(() => { });
157
+ }
158
+ }
159
+ return info;
160
+ }
161
+ /**
162
+ * The current session without recording activity — a read must not extend
163
+ * the window, or a diagnostics poller could keep a session alive forever.
164
+ * Null before the first touch() of the process.
165
+ */
166
+ peek() {
167
+ if (this.sessionId === null)
168
+ return null;
169
+ return {
170
+ sessionId: this.sessionId,
171
+ sessionCount: this.sessionCount,
172
+ startedNewSession: false,
173
+ };
174
+ }
175
+ mint(wallNow, monoNow) {
176
+ var _a, _b;
177
+ // Continue the persisted lifetime counter even when the session itself
178
+ // expired — the ordinal is per install, not per session chain.
179
+ const previousCount = this.sessionCount > 0 ? this.sessionCount : ((_b = (_a = this.stored) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0);
180
+ const newId = String(wallNow);
181
+ this.sessionId = newId;
182
+ this.sessionCount = previousCount + 1;
183
+ this.lastActivityMono = monoNow;
184
+ this.lastActivityWall = wallNow;
185
+ this.persistSession(newId, this.sessionCount, wallNow);
186
+ this.lastPersistedMono = monoNow;
187
+ return {
188
+ sessionId: newId,
189
+ sessionCount: this.sessionCount,
190
+ startedNewSession: true,
191
+ };
192
+ }
193
+ }
@@ -16,20 +16,91 @@ export interface EnrichedEventPayload extends EventWithIdentity {
16
16
  context: EventContext;
17
17
  writeKey: string;
18
18
  }
19
+ /**
20
+ * Why `createAnalyticsClient` refused its options. In development builds the
21
+ * call throws instead; in release the SDK stays inert for the session and
22
+ * reports this through `onConfigError` and `getDebugInfo().configError`.
23
+ * `description` is the same text the iOS and Android SDKs give.
24
+ */
25
+ export type ConfigError = {
26
+ type: 'emptyWriteKey';
27
+ description: string;
28
+ } | {
29
+ type: 'invalidIngestionHost';
30
+ raw: string;
31
+ description: string;
32
+ };
19
33
  export interface InitOptions {
34
+ /** Required. Trimmed; empty or whitespace-only is a config error. */
20
35
  writeKey: string;
36
+ /**
37
+ * Required. An http(s) URL with a host. Trimmed, and trailing slashes are
38
+ * removed. Cleartext http logs a warning unless the host is loopback.
39
+ */
21
40
  ingestionHost: string;
41
+ /** Seconds between automatic flushes (default: 10). Clamped to >= 1. */
22
42
  flushIntervalSeconds?: number;
23
43
  debug?: boolean;
24
44
  /** Max events held in the in-memory queue (default: 2000). Clamped to >= 1. */
25
45
  maxQueueEvents?: number;
26
46
  /**
27
47
  * Max events stored on disk for crash-safety + extended offline periods
28
- * (default: 10000). Must be >= 0. When set to 0, disk persistence is
48
+ * (default: 10000). Negative values are clamped to 0. When set to 0, disk persistence is
29
49
  * disabled and the SDK runs as a pure in-memory pipeline (events are lost
30
50
  * on app kill — documented tradeoff).
31
51
  */
32
52
  maxDiskEvents?: number;
53
+ /**
54
+ * Emit Application Opened/Backgrounded/Installed/Updated events.
55
+ * Defaults to false (opt-in). Matches iOS/Android parity — existing
56
+ * customers upgrading the SDK do not begin emitting lifecycle events
57
+ * until they explicitly set this to true.
58
+ */
59
+ trackLifecycleEvents?: boolean;
60
+ /**
61
+ * Minutes of inactivity after which the next event starts a new session
62
+ * (default: 30). Clamped to >= 1. Session stamping itself is always on.
63
+ */
64
+ sessionTimeoutMinutes?: number;
65
+ /**
66
+ * Emit a `Session Started` track event each time a new session is minted.
67
+ * Defaults to false, so upgrading the SDK never changes an app's event
68
+ * volume.
69
+ */
70
+ fireSessionStarted?: boolean;
71
+ /**
72
+ * Called synchronously by `createAnalyticsClient` when the options are
73
+ * invalid in a release build, after the error is logged. The SDK is inert
74
+ * for the session; a later `createAnalyticsClient` with valid options, or
75
+ * `reset()`, recovers it. Development builds throw from
76
+ * `createAnalyticsClient` instead and never call this. Not called for
77
+ * 401/403/404 responses from the ingestion host.
78
+ */
79
+ onConfigError?: (error: ConfigError) => void;
80
+ }
81
+ /** The part of a `react-native-webview` ref the bridge uses to send replies. */
82
+ export interface WebViewRefLike {
83
+ current: {
84
+ injectJavaScript: (script: string) => void;
85
+ } | null;
86
+ }
87
+ /** The part of a `react-native-webview` message event the bridge reads. */
88
+ export interface WebViewMessageEventLike {
89
+ nativeEvent: {
90
+ data: string;
91
+ url?: string;
92
+ };
93
+ }
94
+ /**
95
+ * Props returned by `attachWebView`, for a `react-native-webview` `<WebView>`.
96
+ * `onMessage` returns true when it consumed a bridge message and false for any
97
+ * other message, so a host with its own handler chains it:
98
+ * `onMessage={(e) => { if (!bridge.onMessage(e)) myHandler(e); }}`.
99
+ */
100
+ export interface WebViewBridgeProps {
101
+ /** Empty when the attach was refused, so joining it with a host script is safe. */
102
+ injectedJavaScriptBeforeContentLoaded: string;
103
+ onMessage: (event: WebViewMessageEventLike) => boolean;
33
104
  }
34
105
  export interface AnalyticsInterface {
35
106
  track: (event: string, props?: Record<string, any>) => void;
@@ -38,6 +109,19 @@ export interface AnalyticsInterface {
38
109
  screen: (name: string, props?: Record<string, any>) => void;
39
110
  page: (name: string, props?: Record<string, any>) => void;
40
111
  alias: (newUserId: string) => void;
112
+ /**
113
+ * Forward a URL the host received from `Linking` (or platform-specific
114
+ * URL handlers) so it is attached to the next `Application Opened`
115
+ * event. The SDK does not read `Linking` itself, so only URLs passed
116
+ * here are recorded — sanitize before forwarding. One-shot — buffer is
117
+ * cleared on emit; last-write-wins if called multiple times before the
118
+ * next Opened. Safe to call right after createAnalyticsClient(): a URL
119
+ * forwarded while initialization is running still reaches the
120
+ * cold-launch Opened.
121
+ *
122
+ * No-op with an always-on warning when `trackLifecycleEvents` is disabled.
123
+ */
124
+ recordOpenedURL: (url: string, sourceApplication?: string) => void;
41
125
  setAdvertisingId: (advertisingId: string) => Promise<void>;
42
126
  clearAdvertisingId: () => Promise<void>;
43
127
  setTracing: (enabled: boolean) => void;
@@ -46,6 +130,23 @@ export interface AnalyticsInterface {
46
130
  enableDebugLogging: () => void;
47
131
  getDebugInfo: () => Promise<Record<string, any>>;
48
132
  getAnonymousId: () => Promise<string>;
133
+ /**
134
+ * The current session id, or null before the first event of the process
135
+ * has been enriched. Sessions are minted by events, not reads, so this never
136
+ * waits for initialization and never extends the session. The same value is
137
+ * stamped on every event at `context.providers.metarouter.sessionID`.
138
+ */
139
+ getSessionId: () => Promise<string | null>;
140
+ /**
141
+ * Bridges a `react-native-webview` WebView: pages on `allowedOrigins` get
142
+ * `window.metarouterBridge.track/page`, and their events are sent through
143
+ * this SDK with the app's identity, device context and session. Spread the
144
+ * returned props onto the `<WebView>` and pass its ref so the page receives
145
+ * acks. Origins must be exact `scheme://host[:port]`; invalid rules are
146
+ * refused with a warning and the returned props do nothing. Safe to call
147
+ * before initialization and on every render.
148
+ */
149
+ attachWebView: (webViewRef: WebViewRefLike | null | undefined, allowedOrigins: readonly string[]) => WebViewBridgeProps;
49
150
  }
50
151
  export interface EventContext {
51
152
  app: {
@@ -79,6 +180,12 @@ export interface EventContext {
79
180
  };
80
181
  locale: string;
81
182
  timezone: string;
183
+ /**
184
+ * Per-event provider values keyed by provider name — the mobile counterpart
185
+ * of the web SDK's `context.providers`. Set at enrichment, never cached with
186
+ * the rest of the context, because session values change per event.
187
+ */
188
+ providers?: Record<string, Record<string, unknown>>;
82
189
  [key: string]: any;
83
190
  }
84
191
  export type Lifecycle = 'idle' | 'initializing' | 'ready' | 'resetting' | 'disabled';
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRo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AAE,OAAO,CAAC,CAAC,CAAC;IACpD,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,cAAc,GACd,OAAO,GACP,WAAW,GACX,UAAU,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Snapshot of the host app's identity (name, version, build, bundle id).
3
+ * Read once at SDK init and reused across every event — both as the `app:`
4
+ * block on the EventContext and as version/build properties on lifecycle
5
+ * events. Mirrors the iOS `AppContext` so a single source of truth flows
6
+ * through the same places on both platforms.
7
+ */
8
+ export interface AppContext {
9
+ name: string;
10
+ version: string;
11
+ build: string;
12
+ namespace: string;
13
+ }
14
+ /**
15
+ * Reads the current app identity from `react-native-device-info`. Every field
16
+ * falls back to 'unknown' when the package isn't installed (e.g. unit tests);
17
+ * without its native module (Expo Go) device-info returns 'unknown' itself.
18
+ * Never the SDK's own version: that would report the SDK as the app's version
19
+ * and fire Application Updated on SDK upgrades instead of app updates.
20
+ */
21
+ export declare function loadAppContext(): AppContext;
22
+ //# sourceMappingURL=appContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appContext.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/appContext.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI,UAAU,CAO3C"}
@@ -0,0 +1,23 @@
1
+ let DeviceInfo = null;
2
+ try {
3
+ DeviceInfo = require('react-native-device-info');
4
+ }
5
+ catch {
6
+ DeviceInfo = null;
7
+ }
8
+ /**
9
+ * Reads the current app identity from `react-native-device-info`. Every field
10
+ * falls back to 'unknown' when the package isn't installed (e.g. unit tests);
11
+ * without its native module (Expo Go) device-info returns 'unknown' itself.
12
+ * Never the SDK's own version: that would report the SDK as the app's version
13
+ * and fire Application Updated on SDK upgrades instead of app updates.
14
+ */
15
+ export function loadAppContext() {
16
+ var _a, _b, _c, _d, _e, _f, _g, _h;
17
+ return {
18
+ name: (_b = (_a = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getApplicationName) === null || _a === void 0 ? void 0 : _a.call(DeviceInfo)) !== null && _b !== void 0 ? _b : 'unknown',
19
+ version: (_d = (_c = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getVersion) === null || _c === void 0 ? void 0 : _c.call(DeviceInfo)) !== null && _d !== void 0 ? _d : 'unknown',
20
+ build: (_f = (_e = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBuildNumber) === null || _e === void 0 ? void 0 : _e.call(DeviceInfo)) !== null && _f !== void 0 ? _f : 'unknown',
21
+ namespace: (_h = (_g = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBundleId) === null || _g === void 0 ? void 0 : _g.call(DeviceInfo)) !== null && _h !== void 0 ? _h : 'unknown',
22
+ };
23
+ }
@@ -1,4 +1,5 @@
1
1
  import { EventContext } from '../types';
2
+ import { AppContext } from './appContext';
2
3
  /**
3
4
  * Clears the cached context information, forcing a refresh on the next getContextInfo call.
4
5
  */
@@ -6,13 +7,16 @@ export declare function clearContextCache(): void;
6
7
  /**
7
8
  * Gathers and caches device, app, and environment context information for analytics events.
8
9
  *
9
- * - Collects details such as app name/version, device model/type, OS, screen size, locale, timezone, and network status.
10
- * - Uses `react-native-device-info` and the current environment to populate fields.
10
+ * - Collects details such as device model/type, OS, screen size, locale, timezone, and network status.
11
+ * - Uses `react-native-device-info` and the current environment to populate device/os fields.
12
+ * - Reuses the caller-provided AppContext for the `app:` block so version/build
13
+ * are sourced from the same snapshot used by lifecycle events.
11
14
  * - Caches the result for the lifetime of the app to avoid redundant async calls.
12
15
  * - Returns a context object suitable for event enrichment.
13
16
  *
17
+ * @param appContext - The host app identity snapshot (name, version, build, namespace).
14
18
  * @param advertisingId - Optional advertising identifier (IDFA on iOS, GAID on Android) for ad tracking and attribution.
15
19
  * @returns {Promise<EventContext>} A promise that resolves to the context information object.
16
20
  */
17
- export declare function getContextInfo(advertisingId?: string): Promise<EventContext>;
21
+ export declare function getContextInfo(appContext: AppContext, advertisingId?: string): Promise<EventContext>;
18
22
  //# sourceMappingURL=contextInfo.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contextInfo.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/contextInfo.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAYxC;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAGxC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAClC,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,YAAY,CAAC,CA+DvB"}
1
+ {"version":3,"file":"contextInfo.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/contextInfo.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAY1C;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAGxC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAClC,UAAU,EAAE,UAAU,EACtB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,YAAY,CAAC,CA+DvB"}
@@ -20,16 +20,19 @@ export function clearContextCache() {
20
20
  /**
21
21
  * Gathers and caches device, app, and environment context information for analytics events.
22
22
  *
23
- * - Collects details such as app name/version, device model/type, OS, screen size, locale, timezone, and network status.
24
- * - Uses `react-native-device-info` and the current environment to populate fields.
23
+ * - Collects details such as device model/type, OS, screen size, locale, timezone, and network status.
24
+ * - Uses `react-native-device-info` and the current environment to populate device/os fields.
25
+ * - Reuses the caller-provided AppContext for the `app:` block so version/build
26
+ * are sourced from the same snapshot used by lifecycle events.
25
27
  * - Caches the result for the lifetime of the app to avoid redundant async calls.
26
28
  * - Returns a context object suitable for event enrichment.
27
29
  *
30
+ * @param appContext - The host app identity snapshot (name, version, build, namespace).
28
31
  * @param advertisingId - Optional advertising identifier (IDFA on iOS, GAID on Android) for ad tracking and attribution.
29
32
  * @returns {Promise<EventContext>} A promise that resolves to the context information object.
30
33
  */
31
- export async function getContextInfo(advertisingId) {
32
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
34
+ export async function getContextInfo(appContext, advertisingId) {
35
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
33
36
  // Return cached context only if it exists AND the advertising ID hasn't changed
34
37
  if (cachedContext && cachedAdvertisingId === advertisingId)
35
38
  return cachedContext;
@@ -64,10 +67,10 @@ export async function getContextInfo(advertisingId) {
64
67
  version: (_q = (_p = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getSystemVersion) === null || _p === void 0 ? void 0 : _p.call(DeviceInfo)) !== null && _q !== void 0 ? _q : 'unknown',
65
68
  },
66
69
  app: {
67
- name: (_s = (_r = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getApplicationName) === null || _r === void 0 ? void 0 : _r.call(DeviceInfo)) !== null && _s !== void 0 ? _s : 'unknown',
68
- version: (_v = (_u = (_t = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getVersion) === null || _t === void 0 ? void 0 : _t.call(DeviceInfo)) !== null && _u !== void 0 ? _u : pkg.version) !== null && _v !== void 0 ? _v : 'unknown',
69
- build: (_x = (_w = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBuildNumber) === null || _w === void 0 ? void 0 : _w.call(DeviceInfo)) !== null && _x !== void 0 ? _x : 'unknown',
70
- namespace: (_z = (_y = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBundleId) === null || _y === void 0 ? void 0 : _y.call(DeviceInfo)) !== null && _z !== void 0 ? _z : 'unknown',
70
+ name: appContext.name,
71
+ version: appContext.version,
72
+ build: appContext.build,
73
+ namespace: appContext.namespace,
71
74
  },
72
75
  screen: {
73
76
  width: Math.round(width),
@@ -77,7 +80,7 @@ export async function getContextInfo(advertisingId) {
77
80
  ...(Platform.OS === 'android'
78
81
  ? {
79
82
  network: {
80
- wifi: (_1 = (await ((_0 = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.isWifiEnabled) === null || _0 === void 0 ? void 0 : _0.call(DeviceInfo)))) !== null && _1 !== void 0 ? _1 : false,
83
+ wifi: (_s = (await ((_r = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.isWifiEnabled) === null || _r === void 0 ? void 0 : _r.call(DeviceInfo)))) !== null && _s !== void 0 ? _s : false,
81
84
  },
82
85
  }
83
86
  : {}),
@@ -1,4 +1,6 @@
1
- import { EnrichedEventPayload, EventContext, EventWithIdentity } from "../types";
1
+ import { EnrichedEventPayload, EventContext, EventWithIdentity } from '../types';
2
+ import type { SessionInfo } from '../session/sessionManager';
3
+ import type { PageContext } from '../webview/bridgeEnvelope';
2
4
  /**
3
5
  * Enriches an analytics event with additional metadata required for ingestion.
4
6
  *
@@ -9,7 +11,9 @@ import { EnrichedEventPayload, EventContext, EventWithIdentity } from "../types"
9
11
  * @param event The base event with identity information.
10
12
  * @param writeKey The write key for the analytics project.
11
13
  * @param context The context information (device, app, environment, etc.).
14
+ * @param session The session this event belongs to; stamped at
15
+ * `context.providers.metarouter`.
12
16
  * @returns The enriched event payload.
13
17
  */
14
- export declare function enrichEvent(event: EventWithIdentity, writeKey: string, context: EventContext): EnrichedEventPayload;
18
+ export declare function enrichEvent(event: EventWithIdentity, writeKey: string, context: EventContext, session: SessionInfo, page?: PageContext): EnrichedEventPayload;
15
19
  //# sourceMappingURL=enrichEvent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"enrichEvent.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/enrichEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAYlB;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,YAAY,GACpB,oBAAoB,CAStB"}
1
+ {"version":3,"file":"enrichEvent.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/enrichEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAW7D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,WAAW,EACpB,IAAI,CAAC,EAAE,WAAW,GACjB,oBAAoB,CAwBtB"}