@layers/react-native 1.4.11 → 2.0.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.
@@ -0,0 +1,746 @@
1
+ import { t as ATTStatus } from "./att-BDPyE-Gs.mjs";
2
+ import { n as SKANManager } from "./skan-CAN-v1eU.mjs";
3
+ import { ConsentState, ConsentState as ConsentState$1, DeviceContext, DeviceContext as DeviceContext$1, Environment, Environment as Environment$1, EventProperties, EventProperties as EventProperties$1, LayersError, UserProperties, UserProperties as UserProperties$1 } from "@layers/core-wasm";
4
+
5
+ //#region src/standard-events.d.ts
6
+
7
+ /**
8
+ * Predefined standard event name constants.
9
+ *
10
+ * Usage:
11
+ * ```ts
12
+ * import { StandardEvents } from '@layers/react-native';
13
+ * layers.track(StandardEvents.PURCHASE, { amount: 9.99, currency: 'USD' });
14
+ * ```
15
+ */
16
+ declare const StandardEvents: {
17
+ readonly APP_OPEN: "app_open";
18
+ readonly LOGIN: "login";
19
+ readonly SIGN_UP: "sign_up";
20
+ readonly REGISTER: "register";
21
+ readonly PURCHASE: "purchase_success";
22
+ readonly ADD_TO_CART: "add_to_cart";
23
+ readonly ADD_TO_WISHLIST: "add_to_wishlist";
24
+ readonly INITIATE_CHECKOUT: "initiate_checkout";
25
+ readonly BEGIN_CHECKOUT: "begin_checkout";
26
+ readonly START_TRIAL: "start_trial";
27
+ readonly SUBSCRIBE: "subscribe";
28
+ readonly LEVEL_START: "level_start";
29
+ readonly LEVEL_COMPLETE: "level_complete";
30
+ readonly TUTORIAL_COMPLETE: "tutorial_complete";
31
+ readonly SEARCH: "search";
32
+ readonly VIEW_ITEM: "view_item";
33
+ readonly VIEW_CONTENT: "view_content";
34
+ readonly SHARE: "share";
35
+ readonly DEEP_LINK: "deep_link_opened";
36
+ readonly SCREEN_VIEW: "screen_view";
37
+ };
38
+ /** Union type of all standard event name strings. */
39
+ type StandardEventName = (typeof StandardEvents)[keyof typeof StandardEvents];
40
+ interface StandardEventPayload {
41
+ event: StandardEventName;
42
+ properties: EventProperties;
43
+ }
44
+ /** Build a login event. */
45
+ declare function loginEvent(method?: string): StandardEventPayload;
46
+ /** Build a sign-up event. */
47
+ declare function signUpEvent(method?: string): StandardEventPayload;
48
+ /** Build a register event. */
49
+ declare function registerEvent(method?: string): StandardEventPayload;
50
+ /** Build a purchase event. */
51
+ declare function purchaseEvent(amount: number, currency?: string, itemId?: string): StandardEventPayload;
52
+ /** Build an add-to-cart event. */
53
+ declare function addToCartEvent(itemId: string, price: number, quantity?: number): StandardEventPayload;
54
+ /** Build an add-to-wishlist event. */
55
+ declare function addToWishlistEvent(itemId: string, name?: string, price?: number): StandardEventPayload;
56
+ /** Build an initiate-checkout event. */
57
+ declare function initiateCheckoutEvent(value: number, currency?: string, itemCount?: number): StandardEventPayload;
58
+ /** Build a start-trial event. */
59
+ declare function startTrialEvent(plan?: string, durationDays?: number): StandardEventPayload;
60
+ /** Build a subscribe event. */
61
+ declare function subscribeEvent(plan: string, amount: number, currency?: string): StandardEventPayload;
62
+ /** Build a level-start event. */
63
+ declare function levelStartEvent(level: string): StandardEventPayload;
64
+ /** Build a level-complete event. */
65
+ declare function levelCompleteEvent(level: string, score?: number): StandardEventPayload;
66
+ /** Build a tutorial-complete event. */
67
+ declare function tutorialCompleteEvent(name?: string): StandardEventPayload;
68
+ /** Build a search event. */
69
+ declare function searchEvent(query: string, resultCount?: number): StandardEventPayload;
70
+ /** Build a view-item event. */
71
+ declare function viewItemEvent(itemId: string, name?: string, category?: string): StandardEventPayload;
72
+ /** Build a view-content event. */
73
+ declare function viewContentEvent(contentId: string, contentType?: string, name?: string): StandardEventPayload;
74
+ /** Build a share event. */
75
+ declare function shareEvent(contentType: string, method?: string, contentId?: string): StandardEventPayload;
76
+ /** Build a screen-view event. */
77
+ declare function screenViewEvent(name: string, screenClass?: string): StandardEventPayload;
78
+ //#endregion
79
+ //#region src/superwall.d.ts
80
+ /** Minimal subset of Superwall's PaywallInfo used by this integration. */
81
+ interface SuperwallPaywallInfo {
82
+ identifier: string;
83
+ name?: string;
84
+ url?: string;
85
+ products?: {
86
+ id: string;
87
+ }[];
88
+ experiment?: {
89
+ id: string;
90
+ variantId: string;
91
+ };
92
+ }
93
+ /** Minimal subset of Superwall's event info. */
94
+ interface SuperwallEventInfo {
95
+ event: {
96
+ rawName?: string;
97
+ type?: string;
98
+ };
99
+ params?: Record<string, unknown>;
100
+ }
101
+ /** Product info from a Superwall paywall purchase. */
102
+ interface SuperwallProduct {
103
+ productIdentifier?: string;
104
+ id?: string;
105
+ price?: number;
106
+ currencyCode?: string;
107
+ currency?: string;
108
+ }
109
+ /**
110
+ * Forward any Superwall event to Layers, prefixed with `superwall_`.
111
+ *
112
+ * Wire this up in your Superwall delegate / event handler:
113
+ * ```ts
114
+ * import Superwall from '@superwall/react-native-superwall';
115
+ * import { superwallOnEvent } from '@layers/react-native';
116
+ *
117
+ * Superwall.instance.setDelegate({
118
+ * handleSuperwallEvent(eventInfo) {
119
+ * superwallOnEvent(layers, eventInfo);
120
+ * }
121
+ * });
122
+ * ```
123
+ */
124
+ declare function superwallOnEvent(layers: LayersReactNative, eventInfo: SuperwallEventInfo): void;
125
+ /**
126
+ * Track that a paywall was presented to the user.
127
+ *
128
+ * ```ts
129
+ * superwallTrackPresentation(layers, paywallInfo);
130
+ * ```
131
+ */
132
+ declare function superwallTrackPresentation(layers: LayersReactNative, paywallInfo: SuperwallPaywallInfo): void;
133
+ /**
134
+ * Track that a paywall was dismissed.
135
+ *
136
+ * ```ts
137
+ * superwallTrackDismiss(layers, paywallInfo);
138
+ * ```
139
+ */
140
+ declare function superwallTrackDismiss(layers: LayersReactNative, paywallInfo: SuperwallPaywallInfo): void;
141
+ /**
142
+ * Track a purchase initiated from a Superwall paywall.
143
+ *
144
+ * ```ts
145
+ * superwallTrackPurchase(layers, paywallInfo, product);
146
+ * ```
147
+ */
148
+ declare function superwallTrackPurchase(layers: LayersReactNative, paywallInfo: SuperwallPaywallInfo, product?: SuperwallProduct): void;
149
+ /**
150
+ * Track that a paywall was skipped (e.g. holdout, no rule match).
151
+ *
152
+ * ```ts
153
+ * superwallTrackSkip(layers, paywallInfo, 'holdout');
154
+ * ```
155
+ */
156
+ declare function superwallTrackSkip(layers: LayersReactNative, paywallInfo: SuperwallPaywallInfo | null, reason: string): void;
157
+ /**
158
+ * Get Layers attribution data formatted as Superwall user attributes.
159
+ *
160
+ * Pass the returned object to `Superwall.instance.setUserAttributes()`:
161
+ * ```ts
162
+ * const attrs = superwallUserAttributes(layers);
163
+ * Superwall.instance.setUserAttributes(attrs);
164
+ * ```
165
+ */
166
+ declare function superwallUserAttributes(layers: LayersReactNative): Record<string, string>;
167
+ //#endregion
168
+ //#region src/commerce.d.ts
169
+ /** Minimal Layers SDK interface required by the commerce module. */
170
+ interface CommerceTracker {
171
+ track(event: string, properties?: EventProperties): void;
172
+ }
173
+ /** Purchase details for trackPurchase. */
174
+ interface PurchaseParams {
175
+ productId: string;
176
+ /** Unit price of the item. Revenue is computed as `price * quantity`. */
177
+ price: number;
178
+ currency: string;
179
+ transactionId?: string;
180
+ quantity?: number;
181
+ isRestored?: boolean;
182
+ store?: string;
183
+ properties?: EventProperties;
184
+ }
185
+ /** Subscription details for trackSubscription. */
186
+ interface SubscriptionParams {
187
+ productId: string;
188
+ /** Unit price of the subscription. */
189
+ price: number;
190
+ currency: string;
191
+ period?: string;
192
+ transactionId?: string;
193
+ isRenewal?: boolean;
194
+ isTrial?: boolean;
195
+ subscriptionGroupId?: string;
196
+ originalTransactionId?: string;
197
+ properties?: EventProperties;
198
+ }
199
+ /** Cart item for order and checkout tracking. */
200
+ interface CartItem {
201
+ productId: string;
202
+ name: string;
203
+ price: number;
204
+ quantity?: number;
205
+ category?: string;
206
+ }
207
+ /** Order details for trackOrder. */
208
+ interface OrderParams {
209
+ orderId: string;
210
+ items: CartItem[];
211
+ subtotal: number;
212
+ currency?: string;
213
+ tax?: number;
214
+ shipping?: number;
215
+ discount?: number;
216
+ couponCode?: string;
217
+ properties?: EventProperties;
218
+ }
219
+ /** Refund details for trackRefund. */
220
+ interface RefundParams {
221
+ transactionId: string;
222
+ amount: number;
223
+ currency: string;
224
+ reason?: string;
225
+ properties?: EventProperties;
226
+ }
227
+ /** Purchase failure details for trackPurchaseFailed. */
228
+ interface PurchaseFailedParams {
229
+ productId: string;
230
+ currency: string;
231
+ errorCode: string | number;
232
+ errorMessage?: string;
233
+ properties?: EventProperties;
234
+ }
235
+ /**
236
+ * Track a successful purchase.
237
+ *
238
+ * ```ts
239
+ * import { trackPurchase } from '@layers/react-native';
240
+ *
241
+ * trackPurchase(layers, {
242
+ * productId: 'premium_monthly',
243
+ * price: 9.99,
244
+ * currency: 'USD',
245
+ * transactionId: 'txn_abc123',
246
+ * });
247
+ * ```
248
+ */
249
+ declare function trackPurchase(layers: CommerceTracker, params: PurchaseParams): void;
250
+ /**
251
+ * Track a failed purchase attempt.
252
+ */
253
+ declare function trackPurchaseFailed(layers: CommerceTracker, params: PurchaseFailedParams): void;
254
+ /**
255
+ * Track a subscription purchase or renewal.
256
+ *
257
+ * ```ts
258
+ * import { trackSubscription } from '@layers/react-native';
259
+ *
260
+ * trackSubscription(layers, {
261
+ * productId: 'pro_annual',
262
+ * price: 49.99,
263
+ * currency: 'USD',
264
+ * period: 'P1Y',
265
+ * });
266
+ * ```
267
+ */
268
+ declare function trackSubscription(layers: CommerceTracker, params: SubscriptionParams): void;
269
+ /**
270
+ * Track a completed order with multiple line items.
271
+ */
272
+ declare function trackOrder(layers: CommerceTracker, params: OrderParams): void;
273
+ /**
274
+ * Track an item being added to the cart.
275
+ */
276
+ declare function trackAddToCart(layers: CommerceTracker, item: CartItem, properties?: EventProperties): void;
277
+ /**
278
+ * Track an item being removed from the cart.
279
+ */
280
+ declare function trackRemoveFromCart(layers: CommerceTracker, item: CartItem, properties?: EventProperties): void;
281
+ /**
282
+ * Track beginning the checkout flow.
283
+ */
284
+ declare function trackBeginCheckout(layers: CommerceTracker, items: CartItem[], currency?: string, properties?: EventProperties): void;
285
+ /**
286
+ * Track viewing a product detail page.
287
+ */
288
+ declare function trackViewProduct(layers: CommerceTracker, productId: string, name: string, price: number, currency?: string, category?: string, properties?: EventProperties): void;
289
+ /**
290
+ * Track a refund.
291
+ */
292
+ declare function trackRefund(layers: CommerceTracker, params: RefundParams): void;
293
+ //#endregion
294
+ //#region src/revenuecat.d.ts
295
+ /**
296
+ * Minimal interface for RevenueCat's CustomerInfo object.
297
+ * Avoids a hard dependency on `react-native-purchases`.
298
+ */
299
+ interface RevenueCatCustomerInfo {
300
+ readonly activeSubscriptions: string[];
301
+ readonly originalAppUserId: string;
302
+ }
303
+ /**
304
+ * Minimal interface for RevenueCat's PurchasesPackage object.
305
+ */
306
+ interface RevenueCatPackage {
307
+ readonly product: {
308
+ readonly identifier: string;
309
+ readonly price: number;
310
+ readonly currencyCode: string;
311
+ };
312
+ }
313
+ /**
314
+ * Options for configuring the RevenueCat integration.
315
+ */
316
+ interface RevenueCatConfig {
317
+ /** The Layers SDK instance to bridge events to. */
318
+ layers: LayersReactNative;
319
+ /**
320
+ * Callback invoked when a new subscription is detected.
321
+ * By default, new subscriptions are tracked as `subscription_start` events.
322
+ * Set to `null` to disable automatic subscription tracking.
323
+ */
324
+ onSubscriptionStart?: ((productId: string) => void) | null;
325
+ }
326
+ /**
327
+ * Connect Layers to your existing RevenueCat Purchases instance.
328
+ *
329
+ * Listens for customer info updates to detect new subscriptions and syncs
330
+ * subscriber status to Layers user properties.
331
+ *
332
+ * @example
333
+ * ```ts
334
+ * import Purchases from 'react-native-purchases';
335
+ * import { LayersReactNative, connectRevenueCat } from '@layers/react-native';
336
+ *
337
+ * const layers = new LayersReactNative();
338
+ * await layers.init({ appId: 'your-app-id', environment: 'production' });
339
+ *
340
+ * connectRevenueCat({
341
+ * layers,
342
+ * purchases: Purchases,
343
+ * });
344
+ * ```
345
+ *
346
+ * @param config - Configuration including the Layers instance.
347
+ * @param purchases - The RevenueCat Purchases instance (duck-typed to avoid hard dependency).
348
+ */
349
+ declare function connectRevenueCat(config: RevenueCatConfig, purchases: {
350
+ addCustomerInfoUpdateListener: (listener: (info: RevenueCatCustomerInfo) => void) => {
351
+ remove: () => void;
352
+ } | void;
353
+ getCustomerInfo: () => Promise<{
354
+ customerInfo: RevenueCatCustomerInfo;
355
+ }>;
356
+ }): void;
357
+ /**
358
+ * Track a RevenueCat package purchase manually.
359
+ *
360
+ * @example
361
+ * ```ts
362
+ * const offerings = await Purchases.getOfferings();
363
+ * const pkg = offerings.current?.availablePackages[0];
364
+ * if (pkg) trackRevenueCatPurchase(layers, pkg);
365
+ * ```
366
+ */
367
+ declare function trackRevenueCatPurchase(layers: LayersReactNative, rcPackage: RevenueCatPackage, store?: string): void;
368
+ /**
369
+ * Manually sync RevenueCat subscriber attributes to Layers user properties.
370
+ *
371
+ * This is called automatically when using `connectRevenueCat()`, but can also
372
+ * be called manually if needed.
373
+ */
374
+ declare function syncRevenueCatAttributes(layers: LayersReactNative, customerInfo: RevenueCatCustomerInfo): void;
375
+ /**
376
+ * Reset RevenueCat integration state. For testing only.
377
+ */
378
+ declare function resetRevenueCatForTesting(): void;
379
+ /**
380
+ * Whether the RevenueCat integration is currently connected.
381
+ */
382
+ declare function isRevenueCatConnected(): boolean;
383
+ //#endregion
384
+ //#region src/background-flush.d.ts
385
+ /**
386
+ * Task identifier for Layers background flush.
387
+ *
388
+ * Use this constant when registering the background task with
389
+ * `react-native-background-fetch`, `expo-task-manager`, or any
390
+ * other background task scheduler.
391
+ */
392
+ declare const BACKGROUND_FLUSH_TASK_NAME = "com.layers.sdk.background-flush";
393
+ /**
394
+ * Minimum recommended interval (in minutes) between background flushes.
395
+ * Both iOS and Android enforce a minimum of ~15 minutes for background
396
+ * fetch tasks.
397
+ */
398
+ declare const BACKGROUND_FLUSH_MIN_INTERVAL_MINUTES = 15;
399
+ /**
400
+ * Result type returned by the background flush handler.
401
+ * Compatible with both `react-native-background-fetch` and
402
+ * `expo-task-manager` result conventions.
403
+ */
404
+ interface BackgroundFlushResult {
405
+ /** Whether the flush completed successfully. */
406
+ success: boolean;
407
+ /** Number of events flushed, if available. */
408
+ eventsFlushed?: number;
409
+ }
410
+ /**
411
+ * Creates a background flush handler function.
412
+ *
413
+ * The returned async function, when called by a background task scheduler,
414
+ * will flush any queued events via the Layers SDK. It is safe to call even
415
+ * if the SDK is not initialized (it will silently no-op).
416
+ *
417
+ * @param getLayers - A getter that returns the current LayersReactNative
418
+ * instance, or `null` if the SDK is not yet initialized.
419
+ * @returns An async handler suitable for use with background task libraries.
420
+ *
421
+ * @example
422
+ * ```typescript
423
+ * const handler = createBackgroundFlushHandler(() => myLayersInstance);
424
+ * ```
425
+ */
426
+ declare function createBackgroundFlushHandler(getLayers: () => LayersReactNative | null): () => Promise<BackgroundFlushResult>;
427
+ /**
428
+ * Registers a background flush task with `expo-task-manager`.
429
+ *
430
+ * This must be called at module scope (outside of any component) as
431
+ * `expo-task-manager` requires tasks to be defined before the app mounts.
432
+ *
433
+ * @param taskManager - The `expo-task-manager` module (import * as TaskManager from 'expo-task-manager').
434
+ * @param getLayers - A getter that returns the current LayersReactNative
435
+ * instance, or `null` if the SDK is not yet initialized.
436
+ *
437
+ * @example
438
+ * ```typescript
439
+ * import * as TaskManager from 'expo-task-manager';
440
+ * import { registerExpoBackgroundFlush } from '@layers/expo';
441
+ *
442
+ * let layers: LayersReactNative | null = null;
443
+ * registerExpoBackgroundFlush(TaskManager, () => layers);
444
+ *
445
+ * // Later, in your app initialization:
446
+ * layers = new LayersReactNative({ appId: '...', environment: 'production' });
447
+ * await layers.init();
448
+ * ```
449
+ */
450
+ declare function registerExpoBackgroundFlush(taskManager: {
451
+ defineTask: (taskName: string, handler: () => Promise<void>) => void;
452
+ }, getLayers: () => LayersReactNative | null): void;
453
+ //#endregion
454
+ //#region src/index.d.ts
455
+ interface LayersRNConfig {
456
+ appId: string;
457
+ environment: Environment;
458
+ appUserId?: string;
459
+ enableDebug?: boolean;
460
+ baseUrl?: string;
461
+ flushIntervalMs?: number;
462
+ flushThreshold?: number;
463
+ maxQueueSize?: number;
464
+ /**
465
+ * Whether to automatically fire an `app_open` event during init().
466
+ * Set to `false` if you want to fire the event manually.
467
+ * @default true
468
+ */
469
+ autoTrackAppOpen?: boolean;
470
+ /**
471
+ * Whether to automatically track `deep_link_opened` events when a deep link
472
+ * is received. The tracked event includes the parsed URL components and all
473
+ * query parameters (UTM params, click IDs like fbclid/gclid/ttclid, etc.)
474
+ * as flat top-level properties.
475
+ *
476
+ * This listener runs in addition to any consumer-registered listener via
477
+ * `setupDeepLinkListener()` -- it does not replace it.
478
+ *
479
+ * @default true
480
+ */
481
+ autoTrackDeepLinks?: boolean;
482
+ }
483
+ type ErrorListener = (error: Error) => void;
484
+ /**
485
+ * Listener for SDK initialization timing metrics.
486
+ *
487
+ * @param mainThreadDurationMs Time spent in the synchronous portion of init
488
+ * (core creation, device info collection, before background work).
489
+ * @param totalDurationMs Total wall-clock time of the `init()` call,
490
+ * including all async work (remote config fetch, attribution signals, app_open event).
491
+ */
492
+ type InitListener = (mainThreadDurationMs: number, totalDurationMs: number) => void;
493
+ declare class LayersReactNative {
494
+ private core;
495
+ private appUserId;
496
+ private isOnline;
497
+ private readonly enableDebug;
498
+ private appStateSubscription;
499
+ private netInfoUnsubscribe;
500
+ private readonly config;
501
+ private userIdLocked;
502
+ private readonly errorListeners;
503
+ private _skanManager;
504
+ private _lastSkanConfigStr;
505
+ private deepLinkUnsubscribe;
506
+ private static readonly MAX_RECENT_EVENTS;
507
+ private _recentEvents;
508
+ private _isInitialized;
509
+ private _configPollTimer;
510
+ private static readonly CONFIG_POLL_INTERVAL_MS;
511
+ private _adServicesToken;
512
+ private _installReferrer;
513
+ private _hadPriorSdkState;
514
+ private _attributionDeeplinkId;
515
+ private _attributionGclid;
516
+ private static readonly ATTRIBUTION_DEEPLINK_ID_KEY;
517
+ private static readonly ATTRIBUTION_GCLID_KEY;
518
+ private _initListener;
519
+ constructor(config: LayersRNConfig);
520
+ init(): Promise<void>;
521
+ track(eventName: string, properties?: EventProperties): void;
522
+ screen(screenName: string, properties?: EventProperties): void;
523
+ setUserProperties(properties: UserProperties): Promise<void>;
524
+ setUserPropertiesOnce(properties: UserProperties): Promise<void>;
525
+ setConsent(consent: ConsentState): Promise<void>;
526
+ /**
527
+ * Request App Tracking Transparency authorization (iOS only).
528
+ * After the user responds, this method automatically:
529
+ * - Collects IDFA if authorized
530
+ * - Updates device info with IDFA and ATT status
531
+ * - Sets advertising consent based on ATT result
532
+ *
533
+ * Returns the ATT status string.
534
+ */
535
+ requestTrackingPermission(): Promise<ATTStatus>;
536
+ /**
537
+ * Set the app user ID. Uses set-user-once semantics:
538
+ * once set, subsequent calls are ignored until clearAppUserId() is called.
539
+ */
540
+ setAppUserId(appUserId: string): void;
541
+ clearAppUserId(): void;
542
+ /**
543
+ * Reset the SDK state: clears the user ID, unlocks set-user-once,
544
+ * clears user properties, and starts a new session.
545
+ *
546
+ * After reset(), the SDK behaves as if no user has been identified.
547
+ * A new anonymous session is started. Events tracked after reset()
548
+ * will not carry the previous user's identity.
549
+ */
550
+ reset(): void;
551
+ /**
552
+ * Associate all subsequent events with a group (company, team, organization).
553
+ * Pass `undefined` or empty string to clear the group association.
554
+ */
555
+ group(groupId: string | undefined, properties?: EventProperties): void;
556
+ getAppUserId(): string | undefined;
557
+ getSessionId(): string;
558
+ getConsentState(): ConsentState;
559
+ setDeviceInfo(deviceInfo: DeviceContext): void;
560
+ flush(): Promise<void>;
561
+ /**
562
+ * Flush all queued events synchronously (blocking).
563
+ *
564
+ * Drains all batches from the queue and sends them via HTTP, awaiting
565
+ * each batch before proceeding. Does not return until all batches have
566
+ * been sent or failed.
567
+ *
568
+ * This is useful for AppState background transitions where the app may
569
+ * be suspended shortly after the call returns.
570
+ */
571
+ flushBlocking(): Promise<void>;
572
+ /**
573
+ * Register an error listener. Errors from track/screen/flush
574
+ * that would otherwise be silently dropped are forwarded here.
575
+ */
576
+ on(event: 'error', listener: ErrorListener): this;
577
+ /**
578
+ * Remove a previously registered error listener.
579
+ */
580
+ off(event: 'error', listener: ErrorListener): this;
581
+ /**
582
+ * Set a listener to receive SDK initialization timing metrics.
583
+ * Must be called **before** `init()` to receive the callback.
584
+ * Pass `null` to clear the listener.
585
+ *
586
+ * @param listener A function receiving `(mainThreadDurationMs, totalDurationMs)`.
587
+ * `mainThreadDurationMs` is the time spent before background work begins.
588
+ * `totalDurationMs` is the total wall-clock time of the `init()` call.
589
+ */
590
+ setInitListener(listener: InitListener | null): void;
591
+ /**
592
+ * Returns the AdServices attribution token (iOS only), or null if not
593
+ * available. Collected automatically during init() on iOS 14.3+.
594
+ * Does NOT require ATT consent.
595
+ */
596
+ getAdServicesToken(): string | null;
597
+ /**
598
+ * Returns the Google Play install referrer data (Android only), or null
599
+ * if not available. Collected automatically during init() on Android.
600
+ */
601
+ getInstallReferrer(): InstallReferrerData | null;
602
+ /**
603
+ * Returns the auto-configured SKANManager instance, or null if SKAN was not
604
+ * configured by the server's remote config.
605
+ * On iOS, when remote config contains a `skan` section with `preset` or
606
+ * `customRules`, the SDK automatically creates and configures a SKANManager.
607
+ * Every `track()` call is automatically forwarded to SKAN rule evaluation.
608
+ */
609
+ getSkanManager(): SKANManager | null;
610
+ /** Whether the SDK has completed async initialization. */
611
+ get isInitialized(): boolean;
612
+ /** The configured environment ('development' | 'staging' | 'production'). */
613
+ get environment(): Environment;
614
+ /** The configured app ID. */
615
+ get appId(): string;
616
+ /** Number of events currently queued. */
617
+ getQueueDepth(): number;
618
+ /** Current device context from the core. */
619
+ getDeviceContext(): DeviceContext;
620
+ /** Whether the SDK believes the device is online. */
621
+ getNetworkStatus(): boolean;
622
+ /** SDK version string. */
623
+ getSdkVersion(): string;
624
+ /**
625
+ * Returns the most recent tracked events (newest first).
626
+ * Each entry is a formatted string like "12:34:56 event_name (3 props)".
627
+ */
628
+ getRecentEvents(): readonly string[];
629
+ private recordRecentEvent;
630
+ private emitError;
631
+ shutdown(): void;
632
+ /**
633
+ * Store attribution data that will be attached to all subsequent events.
634
+ *
635
+ * The values are persisted in AsyncStorage so they survive app restarts.
636
+ * Pass `null` to clear a value.
637
+ *
638
+ * When set, `deeplink_id` and/or `gclid` are included in every event's properties.
639
+ *
640
+ * @param deeplinkId Deep link identifier for server-side attribution matching.
641
+ * @param gclid Google Click Identifier from ad click URLs.
642
+ */
643
+ setAttributionData(deeplinkId?: string | null, gclid?: string | null): Promise<void>;
644
+ /**
645
+ * Merge attribution properties (`gclid`) into the given event properties,
646
+ * if any attribution data is set. `deeplink_id` flows through DeviceContext
647
+ * on the Rust core (set via `setAttributionData`), not through properties.
648
+ */
649
+ private mergeAttributionProperties;
650
+ /**
651
+ * Restore persisted attribution data from AsyncStorage.
652
+ * Called during initialization to survive app restarts.
653
+ */
654
+ private restoreAttributionData;
655
+ private _trackedDeepLinkUrls;
656
+ private setupDeepLinkAutoTracking;
657
+ private initializeDeviceInfo;
658
+ private setupAppStateListener;
659
+ private configureSkanFromRemoteConfig;
660
+ private startConfigPolling;
661
+ private stopConfigPolling;
662
+ private pollRemoteConfig;
663
+ private setupNetInfoListener;
664
+ }
665
+ declare function getOrSetInstallId(): Promise<string>;
666
+ /**
667
+ * Read the app's first install time from the native module.
668
+ * Returns milliseconds since epoch, or null if not available.
669
+ *
670
+ * - Android: reads PackageInfo.firstInstallTime via PackageManager
671
+ * - iOS: reads the Documents directory creation date as a proxy
672
+ */
673
+ declare function getFirstInstallTime(): Promise<number | null>;
674
+ /**
675
+ * Determine whether this is a genuine new install or an existing app that
676
+ * just added the Layers SDK.
677
+ *
678
+ * This is a pure function that takes pre-resolved inputs — the caller is
679
+ * responsible for reading and persisting the `FIRST_LAUNCH_TRACKED_KEY`
680
+ * flag in AsyncStorage. This mirrors the Android/Swift implementations
681
+ * where the caller manages persistence.
682
+ *
683
+ * Logic (mirrors Android's `shouldTreatAsNewInstall`):
684
+ * 1. If `isFirstLaunchByFlag` is `false` (flag already tracked), return `false`.
685
+ * 2. If the SDK had prior state (`install_id` already existed in
686
+ * AsyncStorage), trust the flag — this is a returning user whose
687
+ * first-launch flag was not yet written (e.g. upgrade from an older
688
+ * SDK version). Return `true`.
689
+ * 3. If the SDK had NO prior state AND the app was installed more than
690
+ * 24 hours ago, this is an existing app getting the SDK for the first
691
+ * time — suppress `is_first_launch`. Return `false`.
692
+ * 4. If the SDK had no prior state AND the app was installed within 24
693
+ * hours, this is a genuine new install — allow `is_first_launch`.
694
+ * Return `true`.
695
+ *
696
+ * @param isFirstLaunchByFlag Whether the first_launch flag has NOT been set yet (true = not yet tracked).
697
+ * @param hadPriorSdkState Whether `install_id` already existed before init.
698
+ * @param enableDebug Whether to log debug info.
699
+ */
700
+ declare function shouldTreatAsNewInstall(isFirstLaunchByFlag: boolean, hadPriorSdkState: boolean, enableDebug?: boolean, _getInstallTime?: () => Promise<number | null>): Promise<boolean>;
701
+ interface ClipboardAttribution {
702
+ clickUrl: string;
703
+ clickId: string;
704
+ }
705
+ declare function readClipboardAttribution(): Promise<ClipboardAttribution | null>;
706
+ interface GoogleAdvertisingInfo {
707
+ id: string;
708
+ isLimitAdTrackingEnabled: boolean;
709
+ }
710
+ /**
711
+ * Fetch the Google Advertising ID (GAID) on Android via NativeModules.
712
+ * Returns null on iOS or when the native module is not available.
713
+ */
714
+ declare function getGoogleAdvertisingId(): Promise<GoogleAdvertisingInfo | null>;
715
+ /**
716
+ * Request the AdServices attribution token on iOS 14.3+.
717
+ * Uses the LayersAdServices native module which calls AAAttribution.attributionToken().
718
+ * Does NOT require ATT consent.
719
+ * Returns null on Android or when the native module is not available.
720
+ */
721
+ declare function getAdServicesToken(): Promise<string | null>;
722
+ interface InstallReferrerData {
723
+ referrerUrl: string;
724
+ referrerClickTimestamp?: number;
725
+ installBeginTimestamp?: number;
726
+ }
727
+ /**
728
+ * Fetch the Google Play install referrer on Android via NativeModules.
729
+ * Requires the `com.android.installreferrer` library on the native side.
730
+ * Returns null on iOS or when the native module is not available.
731
+ */
732
+ declare function getInstallReferrer(): Promise<InstallReferrerData | null>;
733
+ interface DeepLinkData {
734
+ url: string;
735
+ scheme: string;
736
+ host: string;
737
+ path: string;
738
+ queryParams: Record<string, string>;
739
+ timestamp: number;
740
+ }
741
+ declare function setupDeepLinkListener(onDeepLink: (data: DeepLinkData) => void): () => void;
742
+ declare function parseDeepLink(url: string): DeepLinkData | null;
743
+ declare function useLayersExpoRouterTracking(layersInstance: LayersReactNative, usePathname: () => string, useGlobalSearchParams: () => Record<string, string | string[]>): void;
744
+ //#endregion
745
+ export { trackViewProduct as $, RevenueCatConfig as A, OrderParams as B, shouldTreatAsNewInstall as C, signUpEvent as Ct, BackgroundFlushResult as D, viewContentEvent as Dt, BACKGROUND_FLUSH_TASK_NAME as E, tutorialCompleteEvent as Et, resetRevenueCatForTesting as F, trackAddToCart as G, PurchaseParams as H, syncRevenueCatAttributes as I, trackPurchase as J, trackBeginCheckout as K, trackRevenueCatPurchase as L, RevenueCatPackage as M, connectRevenueCat as N, createBackgroundFlushHandler as O, viewItemEvent as Ot, isRevenueCatConnected as P, trackSubscription as Q, CartItem as R, setupDeepLinkListener as S, shareEvent as St, BACKGROUND_FLUSH_MIN_INTERVAL_MINUTES as T, subscribeEvent as Tt, RefundParams as U, PurchaseFailedParams as V, SubscriptionParams as W, trackRefund as X, trackPurchaseFailed as Y, trackRemoveFromCart as Z, getGoogleAdvertisingId as _, loginEvent as _t, Environment$1 as a, superwallTrackPresentation as at, parseDeepLink as b, screenViewEvent as bt, GoogleAdvertisingInfo as c, superwallUserAttributes as ct, LayersError as d, StandardEvents as dt, SuperwallEventInfo as et, LayersRNConfig as f, addToCartEvent as ft, getFirstInstallTime as g, levelStartEvent as gt, getAdServicesToken as h, levelCompleteEvent as ht, DeviceContext$1 as i, superwallTrackDismiss as it, RevenueCatCustomerInfo as j, registerExpoBackgroundFlush as k, InitListener as l, StandardEventName as lt, UserProperties$1 as m, initiateCheckoutEvent as mt, ConsentState$1 as n, SuperwallProduct as nt, ErrorListener as o, superwallTrackPurchase as ot, LayersReactNative as p, addToWishlistEvent as pt, trackOrder as q, DeepLinkData as r, superwallOnEvent as rt, EventProperties$1 as s, superwallTrackSkip as st, ClipboardAttribution as t, SuperwallPaywallInfo as tt, InstallReferrerData as u, StandardEventPayload as ut, getInstallReferrer as v, purchaseEvent as vt, useLayersExpoRouterTracking as w, startTrialEvent as wt, readClipboardAttribution as x, searchEvent as xt, getOrSetInstallId as y, registerEvent as yt, CommerceTracker as z };
746
+ //# sourceMappingURL=index-CgWfOUd2.d.mts.map