@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
@@ -1,5 +1,7 @@
1
1
  import { InitOptions, Lifecycle } from './types';
2
2
  import { type NetworkReachability, type NetworkStatus } from './utils/networkMonitor';
3
+ import { SessionManager } from './session/sessionManager';
4
+ import type { BridgeEnvelope } from './webview/bridgeEnvelope';
3
5
  /**
4
6
  * Analytics client for MetaRouter.
5
7
  * - Handles event queueing, batching, and delivery with retries.
@@ -15,12 +17,11 @@ export declare class MetaRouterAnalyticsClient {
15
17
  private ingestionHost;
16
18
  private writeKey;
17
19
  private context;
20
+ private appContext;
18
21
  private appState;
19
22
  private appStateSubscription;
20
23
  private identityManager;
21
24
  private static readonly AUTO_FLUSH_THRESHOLD;
22
- private static readonly DEFAULT_MAX_QUEUE_EVENTS;
23
- private static readonly DEFAULT_MAX_DISK_EVENTS;
24
25
  private static readonly MAX_QUEUE_BYTES;
25
26
  private maxDiskEvents;
26
27
  private dispatcher;
@@ -29,12 +30,19 @@ export declare class MetaRouterAnalyticsClient {
29
30
  private networkMonitor;
30
31
  private networkStatus;
31
32
  private unsubscribeNetwork;
33
+ private lifecycleEmitter;
34
+ private trackLifecycleEvents;
35
+ private pendingDeepLink;
36
+ private coldLaunchOpenDeferred;
37
+ private wasBackgrounded;
38
+ private sessionManager;
32
39
  /**
33
40
  * Initializes the analytics client with the provided options.
34
41
  * @param options - The initialization options.
35
42
  */
36
43
  constructor(options: InitOptions, deps?: {
37
44
  networkMonitor?: NetworkReachability;
45
+ sessionManager?: SessionManager;
38
46
  });
39
47
  /**
40
48
  * Initializes the analytics client.
@@ -60,11 +68,26 @@ export declare class MetaRouterAnalyticsClient {
60
68
  * @returns The current timestamp in ISO format.
61
69
  */
62
70
  private now;
71
+ /**
72
+ * Adds identity, writeKey, context and messageId to a raw event. Shared by
73
+ * enqueue() and the lifecycle emitter so both paths produce identical
74
+ * payloads.
75
+ */
76
+ private buildEnrichedEvent;
63
77
  /**
64
78
  * Enqueues an event for processing.
65
79
  * @param event - The event to enqueue.
66
80
  */
67
81
  private enqueue;
82
+ /**
83
+ * Bridge sink: a validated, deduplicated WebView envelope enters the normal
84
+ * event path. Identity, device context, session, messageId and timestamp
85
+ * all come from the existing enrichment — the envelope contributes only the
86
+ * event and the page it happened on. Returns false when the client cannot
87
+ * accept it, so the page gets `not_ready` rather than a false ack.
88
+ */
89
+ enqueueBridgeEvent(envelope: BridgeEnvelope): boolean;
90
+ private enqueueEnriched;
68
91
  private scheduleFlushIn;
69
92
  private stopFlushLoop;
70
93
  private clearNextTimer;
@@ -72,11 +95,49 @@ export declare class MetaRouterAnalyticsClient {
72
95
  * Sets up the app state listener.
73
96
  */
74
97
  private setupAppStateListener;
98
+ /**
99
+ * Runs the cold-launch lifecycle sequence: detect install vs update vs
100
+ * neither, persist the current version/build, capture any cold-launch
101
+ * deep link, and (when the process is foregrounded) emit Application
102
+ * Opened with from_background=false.
103
+ *
104
+ * No-ops when trackLifecycleEvents is false.
105
+ *
106
+ * @param hadIdentityBeforeInit - Whether identity existed in storage before
107
+ * IdentityManager.init() ran on this launch (see init()).
108
+ */
109
+ private runColdLaunchLifecycle;
110
+ /**
111
+ * True if any identity field is present in storage. Used to distinguish a
112
+ * fresh install from an existing user upgrading from a pre-lifecycle SDK
113
+ * build. Best-effort: failures are treated as "no identity state".
114
+ */
115
+ private hasIdentityState;
116
+ private consumePendingDeepLink;
75
117
  /**
76
118
  * Handles the app state change event.
77
119
  * @param nextState - The new app state.
78
120
  */
79
121
  private handleAppStateChange;
122
+ /**
123
+ * Forward a URL the host received (e.g. from `Linking.getInitialURL`,
124
+ * `Linking.addEventListener('url', ...)`, a UIScene URL handler, or an
125
+ * Android Intent) so it is attached to the next `Application Opened`
126
+ * event as `url` (and `referring_application` if `sourceApplication`
127
+ * is provided). One-shot — the buffer is cleared on the next Opened
128
+ * emit. Last-write-wins if called multiple times before the next Opened.
129
+ *
130
+ * The SDK never reads `Linking` itself: deep links routinely carry auth
131
+ * tokens and OTPs, and an automatic capture would race the host's own
132
+ * sanitized forward for the same one-slot buffer. Only what the host
133
+ * passes here reaches the event (parity with iOS recordOpenedURL and
134
+ * Android recordOpenedUrl).
135
+ *
136
+ * No-op with an always-on warning when `trackLifecycleEvents` is
137
+ * disabled — silent no-ops are bad DX, hosts wiring this up should know
138
+ * they have the feature flag off.
139
+ */
140
+ recordOpenedURL(url: string, sourceApplication?: string): void;
80
141
  /**
81
142
  * Tracks an event.
82
143
  * @param event - The event to track.
@@ -155,10 +216,18 @@ export declare class MetaRouterAnalyticsClient {
155
216
  * never initialized or a reset() races with this call.
156
217
  */
157
218
  getAnonymousId(): Promise<string>;
219
+ /**
220
+ * The current session id, or null before the first event of the process
221
+ * has been enriched. A peek, not a touch: a diagnostic read is not activity
222
+ * and must not extend the inactivity window.
223
+ */
224
+ getSessionId(): Promise<string | null>;
158
225
  /**
159
226
  * Get current state for debugging
160
227
  */
161
228
  getDebugInfo(): Promise<{
229
+ sessionId?: string | undefined;
230
+ sessionCount?: number | undefined;
162
231
  lifecycle: Lifecycle;
163
232
  queueLength: number;
164
233
  ingestionHost: string;
@@ -1 +1 @@
1
- {"version":3,"file":"MetaRouterAnalyticsClient.d.ts","sourceRoot":"","sources":["../../src/analytics/MetaRouterAnalyticsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAe7E,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EACnB,MAAM,wBAAwB,CAAC;AAGhC;;;;;;GAMG;AACH,qBAAa,yBAAyB;IACpC,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,oBAAoB,CAAM;IAClC,OAAO,CAAC,aAAa,CAAS;IAC9B,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AC,aAAa,EAAE,MAAM;IAwB5C;;;;;;OAMG;IACG,kBAAkB;IAexB;;;;;;OAMG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO;IAK3B;;;OAGG;IACH,gBAAgB,IAAI,OAAO;IAI3B;;OAEG;IACH,kBAAkB;IAKlB;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAavC;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAI5C;;OAEG;IACG,YAAY;;;;;;;;;;;;;;;;;;;;;IA+BlB;;;OAGG;IACG,KAAK;IAIX;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAyCpC"}
@@ -3,12 +3,17 @@ import { log, setDebugLogging, warn, error } from './utils/logger';
3
3
  import { IdentityManager } from './IdentityManager';
4
4
  import { enrichEvent } from './utils/enrichEvent';
5
5
  import { getContextInfo, clearContextCache } from './utils/contextInfo';
6
- import { getIdentityField, setIdentityField, removeIdentityField, ADVERTISING_ID_KEY, } from './utils/identityStorage';
6
+ import { loadAppContext } from './utils/appContext';
7
+ import { getIdentityField, setIdentityField, removeIdentityField, ADVERTISING_ID_KEY, ANONYMOUS_ID_KEY, USER_ID_KEY, GROUP_ID_KEY, } from './utils/identityStorage';
8
+ import { getLifecycleVersion, getLifecycleBuild, setLifecycleVersionBuild, } from './utils/lifecycleStorage';
9
+ import { LifecycleEmitter, UNKNOWN_PREVIOUS, } from './lifecycle/lifecycleEvents';
7
10
  import CircuitBreaker from './utils/circuitBreaker';
8
11
  import Dispatcher from './dispatcher';
9
12
  import { PersistentEventQueue } from './persistence/PersistentEventQueue';
10
13
  import { NetworkMonitor, } from './utils/networkMonitor';
11
14
  import { DebouncedNetworkMonitor } from './utils/debouncedNetworkMonitor';
15
+ import { DEFAULT_SESSION_TIMEOUT_MINUTES, SESSION_STARTED_EVENT, SessionManager, } from './session/sessionManager';
16
+ import { DEFAULT_MAX_DISK_EVENTS, validateInitOptions, } from './utils/initOptions';
12
17
  /**
13
18
  * Analytics client for MetaRouter.
14
19
  * - Handles event queueing, batching, and delivery with retries.
@@ -22,24 +27,66 @@ export class MetaRouterAnalyticsClient {
22
27
  * @param options - The initialization options.
23
28
  */
24
29
  constructor(options, deps) {
25
- var _a, _b, _c, _d;
30
+ var _a, _b, _c, _d, _e, _f;
26
31
  this.lifecycle = 'idle';
27
32
  this.initPromise = null;
28
33
  this.queue = [];
29
34
  this.flushIntervalSeconds = 10;
30
35
  this.appState = AppState.currentState;
31
36
  this.appStateSubscription = null;
32
- this.maxDiskEvents = MetaRouterAnalyticsClient.DEFAULT_MAX_DISK_EVENTS;
37
+ this.maxDiskEvents = DEFAULT_MAX_DISK_EVENTS;
33
38
  this.tracingEnabled = false;
34
39
  this.networkStatus = 'connected';
35
40
  this.unsubscribeNetwork = null;
41
+ // Only constructed when trackLifecycleEvents is true, so every emit site
42
+ // is a null-safe call and a disabled client never builds lifecycle payloads.
43
+ this.lifecycleEmitter = null;
44
+ // Opt-in by default. Existing customers upgrading the SDK do not begin
45
+ // emitting lifecycle events without explicitly setting this to true.
46
+ this.trackLifecycleEvents = false;
47
+ // Buffers a URL forwarded through recordOpenedURL() so the next
48
+ // Application Opened can carry it. One-shot — cleared on emit.
49
+ this.pendingDeepLink = null;
50
+ // Suppressed cold-launch Application Opened (process woke in background).
51
+ // The next background→active transition emits an Opened with from_background:false.
52
+ this.coldLaunchOpenDeferred = false;
53
+ // Set when the app leaves the foreground for background, cleared on the
54
+ // next return to active. The resume Opened keys on this rather than on the
55
+ // last reported state: a return can pass through `inactive` (a FaceID or
56
+ // passcode prompt on resume), and comparing only the previous state would
57
+ // mistake it for a Control Center blip and drop the Opened.
58
+ this.wasBackgrounded = false;
36
59
  /**
37
60
  * Handles the app state change event.
38
61
  * @param nextState - The new app state.
39
62
  */
40
63
  this.handleAppStateChange = async (nextState) => {
41
- if (this.appState === 'active' && nextState.match(/inactive|background/)) {
64
+ var _a, _b, _c;
65
+ const previousState = this.appState;
66
+ this.appState = nextState;
67
+ const leavingForeground = previousState === 'active' &&
68
+ (nextState === 'inactive' || nextState === 'background');
69
+ // Accepts inactive as well as active as the previous state: on iOS, RN
70
+ // always reports active → inactive → background (RCTAppState emits
71
+ // `inactive` on WillResignActive first), so requiring active → background
72
+ // would mean Backgrounded never fires on iOS. Android has no `inactive`
73
+ // and goes straight to background. Other previous states (`unknown` or
74
+ // `extension` while a headless or push-woken process settles) never
75
+ // reached the foreground, so they must not emit a Backgrounded without
76
+ // an Opened before it.
77
+ const enteringBackground = nextState === 'background' &&
78
+ (previousState === 'active' || previousState === 'inactive');
79
+ if (leavingForeground || enteringBackground) {
42
80
  log('App moved to background');
81
+ // Enqueued synchronously before the flush below so the event is part
82
+ // of the same drain. On iOS the inactive step already flushed, so the
83
+ // background step flushes again just to carry this one event out.
84
+ if (enteringBackground) {
85
+ this.wasBackgrounded = true;
86
+ if (this.lifecycle === 'ready') {
87
+ (_a = this.lifecycleEmitter) === null || _a === void 0 ? void 0 : _a.emitBackgrounded();
88
+ }
89
+ }
43
90
  this.stopFlushLoop();
44
91
  this.clearNextTimer();
45
92
  try {
@@ -51,53 +98,67 @@ export class MetaRouterAnalyticsClient {
51
98
  warn('Failed to persist queue while moving to background:', err);
52
99
  }
53
100
  }
101
+ // Cleared on any arrival in the foreground, ready or not: a
102
+ // background → active cycle completed while init() is in flight is
103
+ // covered by the cold-launch Opened, and must not leave the flag set
104
+ // for the next active → inactive → active blip to report as a resume.
105
+ const returningFromBackground = nextState === 'active' && this.wasBackgrounded;
106
+ if (nextState === 'active') {
107
+ this.wasBackgrounded = false;
108
+ }
54
109
  if (nextState === 'active' && this.lifecycle === 'ready') {
55
110
  log('App moved to foreground');
111
+ // Application Opened semantics:
112
+ // - return after a background entry (directly or via inactive): emit
113
+ // with from_background=true
114
+ // - active→inactive→active (Control Center, FaceID, system alert):
115
+ // suppressed
116
+ // - first foreground after a background-launched cold start: emit
117
+ // with from_background=false (deferred cold-launch Opened)
118
+ if (this.coldLaunchOpenDeferred) {
119
+ (_b = this.lifecycleEmitter) === null || _b === void 0 ? void 0 : _b.emitOpened(false, this.consumePendingDeepLink());
120
+ this.coldLaunchOpenDeferred = false;
121
+ }
122
+ else if (returningFromBackground) {
123
+ (_c = this.lifecycleEmitter) === null || _c === void 0 ? void 0 : _c.emitOpened(true, this.consumePendingDeepLink());
124
+ }
56
125
  this.startFlushLoop();
57
126
  this.flush();
58
127
  }
59
- this.appState = nextState;
60
128
  };
61
- const { writeKey, ingestionHost, flushIntervalSeconds } = options;
62
- if (!writeKey || typeof writeKey !== 'string' || writeKey.trim() === '') {
63
- throw new Error('MetaRouterAnalyticsClient initialization failed: `writeKey` is required and must be a non-empty string.');
64
- }
65
- try {
66
- // Validate it's a proper absolute URL
67
- // and ensure it does not end with a trailing slash
68
- // e.g., "https://example.com" or "https://example.com/api" are valid,
69
- // but "https://example.com/" or "https://example.com/api/" are not.
70
- // eslint-disable-next-line no-new
71
- new URL(ingestionHost);
72
- if (ingestionHost.endsWith('/')) {
73
- throw new Error();
74
- }
75
- }
76
- catch {
77
- throw new Error('MetaRouterAnalyticsClient initialization failed: `ingestionHost` must be a valid URL and not end in a slash.');
78
- }
79
- this.ingestionHost = ingestionHost;
80
- this.writeKey = writeKey;
81
- this.flushIntervalSeconds = flushIntervalSeconds !== null && flushIntervalSeconds !== void 0 ? flushIntervalSeconds : 10;
82
- // Validate + normalize persistence caps.
83
- const rawMaxDisk = (_a = options.maxDiskEvents) !== null && _a !== void 0 ? _a : MetaRouterAnalyticsClient.DEFAULT_MAX_DISK_EVENTS;
84
- if (rawMaxDisk < 0) {
85
- throw new Error('MetaRouterAnalyticsClient initialization failed: `maxDiskEvents` must be >= 0 (use 0 to disable disk persistence).');
86
- }
87
- this.maxDiskEvents = rawMaxDisk;
88
- const rawMaxQueue = (_b = options.maxQueueEvents) !== null && _b !== void 0 ? _b : MetaRouterAnalyticsClient.DEFAULT_MAX_QUEUE_EVENTS;
89
- const maxQueueEvents = Math.max(1, rawMaxQueue);
90
- if (this.maxDiskEvents > 0 && this.maxDiskEvents < maxQueueEvents) {
91
- warn(`maxDiskEvents (${this.maxDiskEvents}) is less than maxQueueEvents (${maxQueueEvents}) — memory can hold more events than disk can preserve; events may be dropped during background flush`);
129
+ // Same rules as the createAnalyticsClient gate, without logging: the
130
+ // gate already logged this call's warnings, and logging here would print
131
+ // every cleartext/clamp warning twice. Constructed directly (bypassing the
132
+ // gate), invalid options throw on every build type, like Android's direct
133
+ // client entry point — this path has no inert session to fall back to.
134
+ const { options: normalized, configError } = validateInitOptions(options, {
135
+ logWarnings: false,
136
+ });
137
+ if (configError) {
138
+ throw new Error(`Invalid InitOptions: ${configError.description}`);
92
139
  }
93
- setDebugLogging((_c = options.debug) !== null && _c !== void 0 ? _c : false);
140
+ this.ingestionHost = normalized.ingestionHost;
141
+ this.writeKey = normalized.writeKey;
142
+ this.flushIntervalSeconds = Math.max(1, (_a = normalized.flushIntervalSeconds) !== null && _a !== void 0 ? _a : 10);
143
+ this.maxDiskEvents = normalized.maxDiskEvents;
144
+ const maxQueueEvents = normalized.maxQueueEvents;
145
+ setDebugLogging((_b = options.debug) !== null && _b !== void 0 ? _b : false);
146
+ this.trackLifecycleEvents = (_c = options.trackLifecycleEvents) !== null && _c !== void 0 ? _c : false;
94
147
  this.identityManager = new IdentityManager();
148
+ this.sessionManager =
149
+ (_d = deps === null || deps === void 0 ? void 0 : deps.sessionManager) !== null && _d !== void 0 ? _d : new SessionManager((_e = normalized.sessionTimeoutMinutes) !== null && _e !== void 0 ? _e : DEFAULT_SESSION_TIMEOUT_MINUTES);
150
+ // Installed here, before init() can let any event through: a handler
151
+ // installed after the install's first mint would drop its Session
152
+ // Started, which never recurs for that session.
153
+ if (options.fireSessionStarted) {
154
+ this.sessionManager.setOnSessionStart(() => this.track(SESSION_STARTED_EVENT));
155
+ }
95
156
  // Default: wrap the raw native monitor with the asymmetric debounce
96
157
  // (immediate offline, 2s stable-online). If a caller injects their own
97
158
  // monitor (e.g. in tests), use it as-is so they control the debounce
98
159
  // behavior explicitly.
99
160
  this.networkMonitor =
100
- (_d = deps === null || deps === void 0 ? void 0 : deps.networkMonitor) !== null && _d !== void 0 ? _d : new DebouncedNetworkMonitor(new NetworkMonitor());
161
+ (_f = deps === null || deps === void 0 ? void 0 : deps.networkMonitor) !== null && _f !== void 0 ? _f : new DebouncedNetworkMonitor(new NetworkMonitor());
101
162
  this.dispatcher = new Dispatcher({
102
163
  maxEventCount: maxQueueEvents,
103
164
  maxQueueBytes: MetaRouterAnalyticsClient.MAX_QUEUE_BYTES,
@@ -168,7 +229,20 @@ export class MetaRouterAnalyticsClient {
168
229
  this.lifecycle = 'initializing';
169
230
  this.initPromise = (async () => {
170
231
  try {
171
- await this.identityManager.init();
232
+ // Must be read before identityManager.init(): init() generates and
233
+ // persists an anonymousId on first launch, so checking afterwards
234
+ // would make every fresh install look like an upgrade from a
235
+ // pre-lifecycle build and emit Updated(unknown) instead of Installed.
236
+ const hadIdentityBeforeInit = this.trackLifecycleEvents
237
+ ? await this.hasIdentityState()
238
+ : false;
239
+ // The session load must settle before `ready`: the first enriched
240
+ // event decides between resuming the persisted session and minting a
241
+ // new one. Independent of identity, so the reads overlap.
242
+ await Promise.all([
243
+ this.identityManager.init(),
244
+ this.sessionManager.loadPersisted(),
245
+ ]);
172
246
  // Cheap existence check — memory queue starts empty. Any on-disk
173
247
  // events are drained directly to the network below (if online) via
174
248
  // drainDiskToNetwork, avoiding a memory spike from rehydrating a
@@ -178,8 +252,22 @@ export class MetaRouterAnalyticsClient {
178
252
  this.setupAppStateListener();
179
253
  // Load persisted advertising ID if available
180
254
  const persistedAdvertisingId = await getIdentityField(ADVERTISING_ID_KEY);
181
- this.context = await getContextInfo(persistedAdvertisingId || undefined);
255
+ this.appContext = loadAppContext();
256
+ this.context = await getContextInfo(this.appContext, persistedAdvertisingId || undefined);
257
+ if (this.trackLifecycleEvents) {
258
+ this.lifecycleEmitter = new LifecycleEmitter(this.dispatcher, (event, properties) => this.buildEnrichedEvent({
259
+ type: 'track',
260
+ event,
261
+ properties,
262
+ timestamp: this.now(),
263
+ }), this.appContext);
264
+ }
182
265
  this.lifecycle = 'ready';
266
+ // Lifecycle: detect install/update + capture deep link, then emit
267
+ // the cold-launch sequence. Runs after `ready` so the events carry
268
+ // the final identity/context, and before the network/disk drain
269
+ // block below so they join the first flush batch.
270
+ await this.runColdLaunchLifecycle(hadIdentityBeforeInit);
183
271
  // Set initial network state and subscribe to changes
184
272
  this.networkStatus = this.networkMonitor.currentStatus;
185
273
  this.unsubscribeNetwork = this.networkMonitor.onStatusChange((status) => {
@@ -251,6 +339,18 @@ export class MetaRouterAnalyticsClient {
251
339
  now() {
252
340
  return new Date().toISOString();
253
341
  }
342
+ /**
343
+ * Adds identity, writeKey, context and messageId to a raw event. Shared by
344
+ * enqueue() and the lifecycle emitter so both paths produce identical
345
+ * payloads.
346
+ */
347
+ buildEnrichedEvent(event, page) {
348
+ const eventWithIdentity = this.identityManager.addIdentityInfo(event);
349
+ // Every enriched event is session activity, and this is the funnel all
350
+ // event sources share (public calls, lifecycle events, the WebView
351
+ // bridge), so touching here is what makes the session stamp universal.
352
+ return enrichEvent(eventWithIdentity, this.writeKey, this.context, this.sessionManager.touch(), page);
353
+ }
254
354
  /**
255
355
  * Enqueues an event for processing.
256
356
  * @param event - The event to enqueue.
@@ -260,14 +360,41 @@ export class MetaRouterAnalyticsClient {
260
360
  warn('Analytics client is not ready to operate');
261
361
  return;
262
362
  }
263
- const eventWithIdentity = this.identityManager.addIdentityInfo(event);
264
- const enrichedEvent = enrichEvent(eventWithIdentity, this.writeKey, this.context);
265
- this.dispatcher.enqueue(enrichedEvent);
363
+ this.enqueueEnriched(this.buildEnrichedEvent(event));
364
+ }
365
+ /**
366
+ * Bridge sink: a validated, deduplicated WebView envelope enters the normal
367
+ * event path. Identity, device context, session, messageId and timestamp
368
+ * all come from the existing enrichment — the envelope contributes only the
369
+ * event and the page it happened on. Returns false when the client cannot
370
+ * accept it, so the page gets `not_ready` rather than a false ack.
371
+ */
372
+ enqueueBridgeEvent(envelope) {
373
+ if (!this.isReady())
374
+ return false;
375
+ this.enqueueEnriched(this.buildEnrichedEvent({
376
+ type: envelope.type,
377
+ event: envelope.name,
378
+ properties: envelope.properties,
379
+ timestamp: this.now(),
380
+ }, envelope.page));
381
+ return true;
382
+ }
383
+ enqueueEnriched(enriched) {
384
+ this.dispatcher.enqueue(enriched);
266
385
  // Check if we should flush to disk based on thresholds
267
- if (this.persistentQueue.shouldFlushToDisk()) {
268
- void this.persistentQueue.flushToDisk().catch((err) => {
269
- warn('Failed to flush queue to disk after threshold:', err);
270
- });
386
+ // Nothing here may throw out of this method: the event is already queued,
387
+ // and a bridge caller that saw a throw would NAK it and let the page
388
+ // re-send it as a duplicate.
389
+ try {
390
+ if (this.persistentQueue.shouldFlushToDisk()) {
391
+ void this.persistentQueue.flushToDisk().catch((err) => {
392
+ warn('Failed to flush queue to disk after threshold:', err);
393
+ });
394
+ }
395
+ }
396
+ catch (err) {
397
+ warn('Failed to flush queue to disk after threshold:', err);
271
398
  }
272
399
  }
273
400
  scheduleFlushIn(ms, opts) {
@@ -287,6 +414,119 @@ export class MetaRouterAnalyticsClient {
287
414
  setupAppStateListener() {
288
415
  this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange);
289
416
  }
417
+ /**
418
+ * Runs the cold-launch lifecycle sequence: detect install vs update vs
419
+ * neither, persist the current version/build, capture any cold-launch
420
+ * deep link, and (when the process is foregrounded) emit Application
421
+ * Opened with from_background=false.
422
+ *
423
+ * No-ops when trackLifecycleEvents is false.
424
+ *
425
+ * @param hadIdentityBeforeInit - Whether identity existed in storage before
426
+ * IdentityManager.init() ran on this launch (see init()).
427
+ */
428
+ async runColdLaunchLifecycle(hadIdentityBeforeInit) {
429
+ const emitter = this.lifecycleEmitter;
430
+ if (!emitter) {
431
+ return;
432
+ }
433
+ const { version, build } = this.appContext;
434
+ try {
435
+ const [storedVersion, storedBuild] = await Promise.all([
436
+ getLifecycleVersion(),
437
+ getLifecycleBuild(),
438
+ ]);
439
+ if (storedVersion == null && storedBuild == null) {
440
+ if (hadIdentityBeforeInit) {
441
+ emitter.emitUpdated({
442
+ version: UNKNOWN_PREVIOUS,
443
+ build: UNKNOWN_PREVIOUS,
444
+ });
445
+ }
446
+ else {
447
+ emitter.emitInstalled();
448
+ }
449
+ }
450
+ else if (storedVersion !== version || storedBuild !== build) {
451
+ emitter.emitUpdated({
452
+ version: storedVersion !== null && storedVersion !== void 0 ? storedVersion : UNKNOWN_PREVIOUS,
453
+ build: storedBuild !== null && storedBuild !== void 0 ? storedBuild : UNKNOWN_PREVIOUS,
454
+ });
455
+ }
456
+ await setLifecycleVersionBuild(version, build);
457
+ }
458
+ catch (err) {
459
+ warn('Lifecycle install/update detection failed:', err);
460
+ }
461
+ // Cold-launch Opened only fires when the process is in foreground.
462
+ // Background-launched processes (push, headless JS) defer to the next
463
+ // background→active transition.
464
+ if (AppState.currentState === 'active') {
465
+ emitter.emitOpened(false, this.consumePendingDeepLink());
466
+ }
467
+ else {
468
+ this.coldLaunchOpenDeferred = true;
469
+ }
470
+ }
471
+ /**
472
+ * True if any identity field is present in storage. Used to distinguish a
473
+ * fresh install from an existing user upgrading from a pre-lifecycle SDK
474
+ * build. Best-effort: failures are treated as "no identity state".
475
+ */
476
+ async hasIdentityState() {
477
+ try {
478
+ const [anon, user, group] = await Promise.all([
479
+ getIdentityField(ANONYMOUS_ID_KEY),
480
+ getIdentityField(USER_ID_KEY),
481
+ getIdentityField(GROUP_ID_KEY),
482
+ ]);
483
+ return !!(anon || user || group);
484
+ }
485
+ catch {
486
+ return false;
487
+ }
488
+ }
489
+ consumePendingDeepLink() {
490
+ if (!this.pendingDeepLink)
491
+ return undefined;
492
+ const dl = this.pendingDeepLink;
493
+ this.pendingDeepLink = null;
494
+ return dl;
495
+ }
496
+ /**
497
+ * Forward a URL the host received (e.g. from `Linking.getInitialURL`,
498
+ * `Linking.addEventListener('url', ...)`, a UIScene URL handler, or an
499
+ * Android Intent) so it is attached to the next `Application Opened`
500
+ * event as `url` (and `referring_application` if `sourceApplication`
501
+ * is provided). One-shot — the buffer is cleared on the next Opened
502
+ * emit. Last-write-wins if called multiple times before the next Opened.
503
+ *
504
+ * The SDK never reads `Linking` itself: deep links routinely carry auth
505
+ * tokens and OTPs, and an automatic capture would race the host's own
506
+ * sanitized forward for the same one-slot buffer. Only what the host
507
+ * passes here reaches the event (parity with iOS recordOpenedURL and
508
+ * Android recordOpenedUrl).
509
+ *
510
+ * No-op with an always-on warning when `trackLifecycleEvents` is
511
+ * disabled — silent no-ops are bad DX, hosts wiring this up should know
512
+ * they have the feature flag off.
513
+ */
514
+ recordOpenedURL(url, sourceApplication) {
515
+ // Gated on the option, not the emitter: the emitter is null until init()
516
+ // builds it and again after reset(), and in those windows the
517
+ // "disabled" warning would be wrong.
518
+ if (!this.trackLifecycleEvents) {
519
+ warn('recordOpenedURL called but trackLifecycleEvents is disabled — buffered URL ignored. Set trackLifecycleEvents: true in InitOptions to enable.');
520
+ return;
521
+ }
522
+ if (!url || typeof url !== 'string') {
523
+ warn('recordOpenedURL called with invalid url — ignored');
524
+ return;
525
+ }
526
+ this.pendingDeepLink = sourceApplication
527
+ ? { url, referringApplication: sourceApplication }
528
+ : { url };
529
+ }
290
530
  /**
291
531
  * Tracks an event.
292
532
  * @param event - The event to track.
@@ -372,7 +612,7 @@ export class MetaRouterAnalyticsClient {
372
612
  log('Setting advertising ID');
373
613
  await setIdentityField(ADVERTISING_ID_KEY, advertisingId);
374
614
  clearContextCache();
375
- this.context = await getContextInfo(advertisingId);
615
+ this.context = await getContextInfo(this.appContext, advertisingId);
376
616
  log('Advertising ID updated, persisted, and context refreshed');
377
617
  }
378
618
  /**
@@ -390,7 +630,7 @@ export class MetaRouterAnalyticsClient {
390
630
  log('Clearing advertising ID');
391
631
  await removeIdentityField(ADVERTISING_ID_KEY);
392
632
  clearContextCache();
393
- this.context = await getContextInfo();
633
+ this.context = await getContextInfo(this.appContext);
394
634
  log('Advertising ID cleared from storage and context');
395
635
  }
396
636
  /**
@@ -433,11 +673,21 @@ export class MetaRouterAnalyticsClient {
433
673
  }
434
674
  return id;
435
675
  }
676
+ /**
677
+ * The current session id, or null before the first event of the process
678
+ * has been enriched. A peek, not a touch: a diagnostic read is not activity
679
+ * and must not extend the inactivity window.
680
+ */
681
+ async getSessionId() {
682
+ var _a, _b;
683
+ return (_b = (_a = this.sessionManager.peek()) === null || _a === void 0 ? void 0 : _a.sessionId) !== null && _b !== void 0 ? _b : null;
684
+ }
436
685
  /**
437
686
  * Get current state for debugging
438
687
  */
439
688
  async getDebugInfo() {
440
689
  const d = this.dispatcher.getDebugInfo();
690
+ const session = this.sessionManager.peek();
441
691
  return {
442
692
  lifecycle: this.lifecycle,
443
693
  queueLength: d.queueLength,
@@ -456,6 +706,13 @@ export class MetaRouterAnalyticsClient {
456
706
  tracingEnabled: this.tracingEnabled,
457
707
  hasDiskData: this.persistentQueue.hasDiskData,
458
708
  networkStatus: this.networkStatus,
709
+ // Unmasked on purpose: a session id is an epoch-ms timestamp, not an
710
+ // identifier tied to a person, and the point of surfacing it here is
711
+ // matching it against event payloads.
712
+ ...(session && {
713
+ sessionId: session.sessionId,
714
+ sessionCount: session.sessionCount,
715
+ }),
459
716
  };
460
717
  }
461
718
  /**
@@ -481,6 +738,13 @@ export class MetaRouterAnalyticsClient {
481
738
  this.dispatcher.stop();
482
739
  (_c = (_b = this.appStateSubscription) === null || _b === void 0 ? void 0 : _b.remove) === null || _c === void 0 ? void 0 : _c.call(_b);
483
740
  this.appStateSubscription = null;
741
+ this.pendingDeepLink = null;
742
+ this.coldLaunchOpenDeferred = false;
743
+ this.wasBackgrounded = false;
744
+ this.lifecycleEmitter = null;
745
+ // The session survives reset() through storage: the next
746
+ // createAnalyticsClient builds a new client that resumes from it.
747
+ this.sessionManager.persistActivity();
484
748
  this.dispatcher.reset();
485
749
  await this.persistentQueue.deleteSnapshot();
486
750
  // Clear identity (must remove persisted IDs)
@@ -496,8 +760,6 @@ export class MetaRouterAnalyticsClient {
496
760
  }
497
761
  }
498
762
  MetaRouterAnalyticsClient.AUTO_FLUSH_THRESHOLD = 20;
499
- MetaRouterAnalyticsClient.DEFAULT_MAX_QUEUE_EVENTS = 2000;
500
- MetaRouterAnalyticsClient.DEFAULT_MAX_DISK_EVENTS = 10000;
501
763
  // Byte cap is intentionally internal (parity with iOS/Android). Not a
502
764
  // public option. 5MB — revisit only if a customer actually needs to tune.
503
765
  MetaRouterAnalyticsClient.MAX_QUEUE_BYTES = 5 * 1024 * 1024;
@@ -1,3 +1,10 @@
1
1
  import type { InitOptions, AnalyticsInterface } from './types';
2
+ /**
3
+ * Whether this is a development build. Injectable so tests can exercise the
4
+ * release path; production reads React Native's `__DEV__`.
5
+ */
6
+ export declare const buildConfig: {
7
+ isDevelopmentBuild: () => boolean;
8
+ };
2
9
  export declare function createAnalyticsClient(options: InitOptions): AnalyticsInterface;
3
10
  //# sourceMappingURL=init.d.ts.map