@metarouter/react-native-sdk 1.8.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 (54) hide show
  1. package/README.md +139 -6
  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 +21 -0
  8. package/lib/analytics/MetaRouterAnalyticsClient.d.ts.map +1 -1
  9. package/lib/analytics/MetaRouterAnalyticsClient.js +77 -10
  10. package/lib/analytics/init.d.ts.map +1 -1
  11. package/lib/analytics/init.js +14 -1
  12. package/lib/analytics/proxy/proxyClient.d.ts +2 -0
  13. package/lib/analytics/proxy/proxyClient.d.ts.map +1 -1
  14. package/lib/analytics/proxy/proxyClient.js +28 -1
  15. package/lib/analytics/session/sessionManager.d.ts +108 -0
  16. package/lib/analytics/session/sessionManager.d.ts.map +1 -0
  17. package/lib/analytics/session/sessionManager.js +193 -0
  18. package/lib/analytics/types.d.ts +58 -0
  19. package/lib/analytics/types.d.ts.map +1 -1
  20. package/lib/analytics/utils/appContext.d.ts +5 -3
  21. package/lib/analytics/utils/appContext.d.ts.map +1 -1
  22. package/lib/analytics/utils/appContext.js +9 -8
  23. package/lib/analytics/utils/enrichEvent.d.ts +6 -2
  24. package/lib/analytics/utils/enrichEvent.d.ts.map +1 -1
  25. package/lib/analytics/utils/enrichEvent.js +20 -3
  26. package/lib/analytics/utils/initOptions.d.ts.map +1 -1
  27. package/lib/analytics/utils/initOptions.js +7 -0
  28. package/lib/analytics/utils/monotonicClock.d.ts +15 -0
  29. package/lib/analytics/utils/monotonicClock.d.ts.map +1 -0
  30. package/lib/analytics/utils/monotonicClock.js +52 -0
  31. package/lib/analytics/utils/sessionStorage.d.ts +27 -0
  32. package/lib/analytics/utils/sessionStorage.d.ts.map +1 -0
  33. package/lib/analytics/utils/sessionStorage.js +85 -0
  34. package/lib/analytics/webview/bridgeDedupStore.d.ts +37 -0
  35. package/lib/analytics/webview/bridgeDedupStore.d.ts.map +1 -0
  36. package/lib/analytics/webview/bridgeDedupStore.js +63 -0
  37. package/lib/analytics/webview/bridgeEnvelope.d.ts +68 -0
  38. package/lib/analytics/webview/bridgeEnvelope.d.ts.map +1 -0
  39. package/lib/analytics/webview/bridgeEnvelope.js +140 -0
  40. package/lib/analytics/webview/bridgeMessageProcessor.d.ts +38 -0
  41. package/lib/analytics/webview/bridgeMessageProcessor.d.ts.map +1 -0
  42. package/lib/analytics/webview/bridgeMessageProcessor.js +67 -0
  43. package/lib/analytics/webview/bridgeWrapperScript.d.ts +53 -0
  44. package/lib/analytics/webview/bridgeWrapperScript.d.ts.map +1 -0
  45. package/lib/analytics/webview/bridgeWrapperScript.js +161 -0
  46. package/lib/analytics/webview/webViewBridge.d.ts +39 -0
  47. package/lib/analytics/webview/webViewBridge.d.ts.map +1 -0
  48. package/lib/analytics/webview/webViewBridge.js +211 -0
  49. package/lib/analytics/webview/webViewSupport.d.ts +16 -0
  50. package/lib/analytics/webview/webViewSupport.d.ts.map +1 -0
  51. package/lib/analytics/webview/webViewSupport.js +52 -0
  52. package/lib/index.d.ts +1 -1
  53. package/lib/index.d.ts.map +1 -1
  54. package/package.json +11 -3
@@ -1,3 +1,4 @@
1
+ import { inertProps } from '../webview/webViewBridge';
1
2
  const pendingCalls = [];
2
3
  const MAX_PENDING_CALLS = 20;
3
4
  let realClient = null;
@@ -9,6 +10,10 @@ let configDisabledError = null;
9
10
  // still-initializing session is cleared), so the proxy cannot route it to the
10
11
  // bound client alone.
11
12
  let resetHandler = null;
13
+ // Owned by init.ts, which holds the session-wide bridge processor. Like reset,
14
+ // attachWebView must work before a bind: its props are needed at the first
15
+ // render, and queueing it would leave the WebView without a wrapper.
16
+ let attachWebViewHandler = null;
12
17
  // The client whose init() is still running. recordOpenedURL only fills a
13
18
  // one-slot buffer that the cold-launch Application Opened reads during
14
19
  // init(), and the proxy binds only after init() resolves — so a cold-launch
@@ -70,6 +75,17 @@ let flushInFlight = null;
70
75
  */
71
76
  function handleMethodCall(methodName, ...args) {
72
77
  var _a;
78
+ // Bound or not: the props are stateless and the shared processor resolves
79
+ // the client per message.
80
+ if (methodName === 'attachWebView') {
81
+ if (attachWebViewHandler) {
82
+ return attachWebViewHandler(...args);
83
+ }
84
+ // Only reachable when init.ts was never loaded (a deep import). Queueing
85
+ // would hand the render undefined; inert props keep it rendering.
86
+ console.warn('[MetaRouter] attachWebView called before the SDK loaded — ignoring.');
87
+ return inertProps();
88
+ }
73
89
  // Real client bound
74
90
  if (realClient && methodName !== 'reset') {
75
91
  if (methodName === 'flush') {
@@ -89,7 +105,12 @@ function handleMethodCall(methodName, ...args) {
89
105
  }
90
106
  return (realClient ? realClient.reset() : Promise.resolve());
91
107
  }
92
- // No real client bound yet
108
+ // No real client bound yet. No queueing and no waiting for a bind, unlike
109
+ // getAnonymousId: sessions are minted by events, so before a bind "null — no
110
+ // session yet" is the true answer, refused sessions included.
111
+ if (methodName === 'getSessionId') {
112
+ return Promise.resolve(null);
113
+ }
93
114
  if (methodName === 'recordOpenedURL' && initializingClient) {
94
115
  initializingClient.recordOpenedURL(...args);
95
116
  return undefined;
@@ -176,6 +197,8 @@ export const proxyClient = {
176
197
  enableDebugLogging: () => handleMethodCall('enableDebugLogging'),
177
198
  getDebugInfo: () => handleMethodCall('getDebugInfo'),
178
199
  getAnonymousId: () => handleMethodCall('getAnonymousId'),
200
+ getSessionId: () => handleMethodCall('getSessionId'),
201
+ attachWebView: (webViewRef, allowedOrigins) => handleMethodCall('attachWebView', webViewRef, allowedOrigins),
179
202
  };
180
203
  /**
181
204
  * Sets (or clears, with `null`) the client whose init() is in flight, so
@@ -237,6 +260,10 @@ export function setRealClient(client, opts) {
237
260
  flushInFlight = null; // reset coalescer
238
261
  }
239
262
  }
263
+ /** Registers init.ts's WebView bridge, used by `attachWebView()` in every state. */
264
+ export function setAttachWebViewHandler(handler) {
265
+ attachWebViewHandler = handler;
266
+ }
240
267
  /** Registers init.ts's session reset, used by `reset()` in every state. */
241
268
  export function setResetHandler(handler) {
242
269
  resetHandler = handler;
@@ -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
+ }
@@ -57,6 +57,17 @@ export interface InitOptions {
57
57
  * until they explicitly set this to true.
58
58
  */
59
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;
60
71
  /**
61
72
  * Called synchronously by `createAnalyticsClient` when the options are
62
73
  * invalid in a release build, after the error is logged. The SDK is inert
@@ -67,6 +78,30 @@ export interface InitOptions {
67
78
  */
68
79
  onConfigError?: (error: ConfigError) => void;
69
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;
104
+ }
70
105
  export interface AnalyticsInterface {
71
106
  track: (event: string, props?: Record<string, any>) => void;
72
107
  identify: (userId: string, traits?: Record<string, any>) => void;
@@ -95,6 +130,23 @@ export interface AnalyticsInterface {
95
130
  enableDebugLogging: () => void;
96
131
  getDebugInfo: () => Promise<Record<string, any>>;
97
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;
98
150
  }
99
151
  export interface EventContext {
100
152
  app: {
@@ -128,6 +180,12 @@ export interface EventContext {
128
180
  };
129
181
  locale: string;
130
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>>;
131
189
  [key: string]: any;
132
190
  }
133
191
  export type Lifecycle = 'idle' | 'initializing' | 'ready' | 'resetting' | 'disabled';
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/analytics/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,OAAO,GACP,UAAU,GACV,OAAO,GACP,QAAQ,GACR,OAAO,GACP,MAAM,CAAC;AAEX,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB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;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,MAAM,EAAE;QACN,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,EAAE,EAAE;QACF,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE;QACR,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,cAAc,GACd,OAAO,GACP,WAAW,GACX,UAAU,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/analytics/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,OAAO,GACP,UAAU,GACV,OAAO,GACP,QAAQ,GACR,OAAO,GACP,MAAM,CAAC;AAEX,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,UAAU,CAAC,EAAE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AC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE;QACR,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,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"}
@@ -12,9 +12,11 @@ export interface AppContext {
12
12
  namespace: string;
13
13
  }
14
14
  /**
15
- * Reads the current app identity from `react-native-device-info`. Falls back
16
- * to package.json version + 'unknown' for everything else if the native
17
- * module is missing (e.g. unit tests, Expo Go without the dev client).
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.
18
20
  */
19
21
  export declare function loadAppContext(): AppContext;
20
22
  //# sourceMappingURL=appContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"appContext.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/appContext.ts"],"names":[],"mappings":"AAUA;;;;;;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;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,UAAU,CAO3C"}
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"}
@@ -1,4 +1,3 @@
1
- import pkg from '../../../package.json';
2
1
  let DeviceInfo = null;
3
2
  try {
4
3
  DeviceInfo = require('react-native-device-info');
@@ -7,16 +6,18 @@ catch {
7
6
  DeviceInfo = null;
8
7
  }
9
8
  /**
10
- * Reads the current app identity from `react-native-device-info`. Falls back
11
- * to package.json version + 'unknown' for everything else if the native
12
- * module is missing (e.g. unit tests, Expo Go without the dev client).
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.
13
14
  */
14
15
  export function loadAppContext() {
15
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
16
+ var _a, _b, _c, _d, _e, _f, _g, _h;
16
17
  return {
17
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',
18
- version: (_e = (_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 : pkg.version) !== null && _e !== void 0 ? _e : 'unknown',
19
- build: (_g = (_f = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBuildNumber) === null || _f === void 0 ? void 0 : _f.call(DeviceInfo)) !== null && _g !== void 0 ? _g : 'unknown',
20
- namespace: (_j = (_h = DeviceInfo === null || DeviceInfo === void 0 ? void 0 : DeviceInfo.getBundleId) === null || _h === void 0 ? void 0 : _h.call(DeviceInfo)) !== null && _j !== void 0 ? _j : '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',
21
22
  };
22
23
  }
@@ -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"}
@@ -1,4 +1,4 @@
1
- import uuid from "react-native-uuid";
1
+ import uuid from 'react-native-uuid';
2
2
  /**
3
3
  * Generate a messageId with a timestamp prefix (ms since epoch + UUID).
4
4
  * This makes it easy to debug when events were created.
@@ -17,14 +17,31 @@ function generateMessageId() {
17
17
  * @param event The base event with identity information.
18
18
  * @param writeKey The write key for the analytics project.
19
19
  * @param context The context information (device, app, environment, etc.).
20
+ * @param session The session this event belongs to; stamped at
21
+ * `context.providers.metarouter`.
20
22
  * @returns The enriched event payload.
21
23
  */
22
- export function enrichEvent(event, writeKey, context) {
24
+ export function enrichEvent(event, writeKey, context, session, page) {
23
25
  const enriched = {
24
26
  ...event,
25
27
  writeKey,
26
28
  messageId: generateMessageId(),
27
- context,
29
+ // A copy per event: `context` is the client's shared cached object. Key
30
+ // names and the epoch-ms string mirror the web SDK's MetaRouter session,
31
+ // so pipeline mappings read one shape from every platform — renaming any
32
+ // side forks them.
33
+ context: {
34
+ ...context,
35
+ providers: {
36
+ metarouter: {
37
+ sessionID: session.sessionId,
38
+ sessionCount: session.sessionCount,
39
+ },
40
+ },
41
+ // Bridge events carry the page they happened on; native events leave
42
+ // context.page absent, matching web SDK output.
43
+ ...(page && { page }),
44
+ },
28
45
  };
29
46
  return enriched;
30
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"initOptions.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/initOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAsBzD,MAAM,WAAW,oBAAoB;IACnC,oFAAoF;IACpF,OAAO,EAAE,WAAW,CAAC;IACrB,oEAAoE;IACpE,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;CACjC;AAYD,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIpD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,WAAW,EAChB,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GACnC,oBAAoB,CA2EtB;AAED,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAC7C,eAAO,MAAM,uBAAuB,QAAS,CAAC"}
1
+ {"version":3,"file":"initOptions.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/initOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAsBzD,MAAM,WAAW,oBAAoB;IACnC,oFAAoF;IACpF,OAAO,EAAE,WAAW,CAAC;IACrB,oEAAoE;IACpE,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;CACjC;AAYD,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIpD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,WAAW,EAChB,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,GACnC,oBAAoB,CAuFtB;AAED,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAC7C,eAAO,MAAM,uBAAuB,QAAS,CAAC"}
@@ -77,6 +77,10 @@ export function validateInitOptions(raw, opts = {}) {
77
77
  if (maxDiskEvents != null && maxDiskEvents < 0) {
78
78
  warn(`maxDiskEvents (${maxDiskEvents}) clamped to 0 — use 0 to disable disk persistence`);
79
79
  }
80
+ const sessionTimeoutMinutes = finiteOrUnset('sessionTimeoutMinutes', raw.sessionTimeoutMinutes);
81
+ if (sessionTimeoutMinutes != null && sessionTimeoutMinutes < 1) {
82
+ warn(`sessionTimeoutMinutes (${sessionTimeoutMinutes}) clamped to 1`);
83
+ }
80
84
  const clampedQueue = Math.max(1, maxQueueEvents !== null && maxQueueEvents !== void 0 ? maxQueueEvents : DEFAULT_MAX_QUEUE_EVENTS);
81
85
  const clampedDisk = Math.max(0, maxDiskEvents !== null && maxDiskEvents !== void 0 ? maxDiskEvents : DEFAULT_MAX_DISK_EVENTS);
82
86
  if (clampedDisk > 0 && clampedDisk < clampedQueue) {
@@ -92,6 +96,9 @@ export function validateInitOptions(raw, opts = {}) {
92
96
  : undefined,
93
97
  maxQueueEvents: clampedQueue,
94
98
  maxDiskEvents: clampedDisk,
99
+ sessionTimeoutMinutes: sessionTimeoutMinutes != null
100
+ ? Math.max(1, sessionTimeoutMinutes)
101
+ : undefined,
95
102
  },
96
103
  configError,
97
104
  };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Milliseconds on a monotonic clock that keeps counting through device sleep —
3
+ * `mach_continuous_time` on iOS, `SystemClock.elapsedRealtime` on Android, the
4
+ * same clocks the native SDKs measure session inactivity with. Read
5
+ * synchronously from the MetaRouterClock native module.
6
+ *
7
+ * Not `performance.now()`: React Native backs it with clocks that stop while
8
+ * the device sleeps, so an app backgrounded on a phone locked for hours would
9
+ * resume into the same session. Without the native module (e.g. Expo Go), or
10
+ * once a synchronous call fails, this falls back to wall-clock for the rest of
11
+ * the process with a one-time warning: sleep is then measured, but a clock
12
+ * change can end or stretch a session.
13
+ */
14
+ export declare function continuousMillis(): number;
15
+ //# sourceMappingURL=monotonicClock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monotonicClock.d.ts","sourceRoot":"","sources":["../../../src/analytics/utils/monotonicClock.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAiCzC"}