@layers/react-native 1.4.11 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/att-BFy6dcWE.d.ts.map +1 -1
- package/dist/debug-overlay.d.mts +19 -0
- package/dist/debug-overlay.d.mts.map +1 -0
- package/dist/debug-overlay.d.ts +19 -0
- package/dist/debug-overlay.d.ts.map +1 -0
- package/dist/debug-overlay.js +356 -0
- package/dist/debug-overlay.mjs +353 -0
- package/dist/debug-overlay.mjs.map +1 -0
- package/dist/index-CgWfOUd2.d.mts +746 -0
- package/dist/index-CgWfOUd2.d.mts.map +1 -0
- package/dist/index-DD43_S2s.d.ts +746 -0
- package/dist/index-DD43_S2s.d.ts.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +46 -2
- package/dist/index.mjs +2 -2
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/react.mjs +1 -1
- package/dist/src-B1dWMPEa.js +2059 -0
- package/dist/src-CT0RgNql.mjs +1742 -0
- package/dist/src-CT0RgNql.mjs.map +1 -0
- package/package.json +10 -3
- package/dist/index-Ct99z5MX.d.mts +0 -187
- package/dist/index-Ct99z5MX.d.mts.map +0 -1
- package/dist/index-DtN6DP29.d.ts +0 -187
- package/dist/index-DtN6DP29.d.ts.map +0 -1
- package/dist/src-DFnL34cK.mjs +0 -772
- package/dist/src-DFnL34cK.mjs.map +0 -1
- package/dist/src-DQCNfyUc.js +0 -825
|
@@ -0,0 +1,1742 @@
|
|
|
1
|
+
import { t as __require } from "./chunk-DmmLNhcN.mjs";
|
|
2
|
+
import { a as requestTrackingAuthorization, n as getAdvertisingId, r as getVendorId } from "./att-B6KTrEU7.mjs";
|
|
3
|
+
import { t as SKANManager } from "./skan-CBE6_mjp.mjs";
|
|
4
|
+
import { FetchHttpClient, LayersCore, LayersError as LayersError$1, MemoryPersistence } from "@layers/core-wasm";
|
|
5
|
+
|
|
6
|
+
//#region src/standard-events.ts
|
|
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
|
+
const StandardEvents = {
|
|
17
|
+
APP_OPEN: "app_open",
|
|
18
|
+
LOGIN: "login",
|
|
19
|
+
SIGN_UP: "sign_up",
|
|
20
|
+
REGISTER: "register",
|
|
21
|
+
PURCHASE: "purchase_success",
|
|
22
|
+
ADD_TO_CART: "add_to_cart",
|
|
23
|
+
ADD_TO_WISHLIST: "add_to_wishlist",
|
|
24
|
+
INITIATE_CHECKOUT: "initiate_checkout",
|
|
25
|
+
BEGIN_CHECKOUT: "begin_checkout",
|
|
26
|
+
START_TRIAL: "start_trial",
|
|
27
|
+
SUBSCRIBE: "subscribe",
|
|
28
|
+
LEVEL_START: "level_start",
|
|
29
|
+
LEVEL_COMPLETE: "level_complete",
|
|
30
|
+
TUTORIAL_COMPLETE: "tutorial_complete",
|
|
31
|
+
SEARCH: "search",
|
|
32
|
+
VIEW_ITEM: "view_item",
|
|
33
|
+
VIEW_CONTENT: "view_content",
|
|
34
|
+
SHARE: "share",
|
|
35
|
+
DEEP_LINK: "deep_link_opened",
|
|
36
|
+
SCREEN_VIEW: "screen_view"
|
|
37
|
+
};
|
|
38
|
+
/** Build a login event. */
|
|
39
|
+
function loginEvent(method) {
|
|
40
|
+
const properties = {};
|
|
41
|
+
if (method !== void 0) properties.method = method;
|
|
42
|
+
return {
|
|
43
|
+
event: StandardEvents.LOGIN,
|
|
44
|
+
properties
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Build a sign-up event. */
|
|
48
|
+
function signUpEvent(method) {
|
|
49
|
+
const properties = {};
|
|
50
|
+
if (method !== void 0) properties.method = method;
|
|
51
|
+
return {
|
|
52
|
+
event: StandardEvents.SIGN_UP,
|
|
53
|
+
properties
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Build a register event. */
|
|
57
|
+
function registerEvent(method) {
|
|
58
|
+
const properties = {};
|
|
59
|
+
if (method !== void 0) properties.method = method;
|
|
60
|
+
return {
|
|
61
|
+
event: StandardEvents.REGISTER,
|
|
62
|
+
properties
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Build a purchase event. */
|
|
66
|
+
function purchaseEvent(amount, currency = "USD", itemId) {
|
|
67
|
+
const properties = {
|
|
68
|
+
amount,
|
|
69
|
+
currency
|
|
70
|
+
};
|
|
71
|
+
if (itemId !== void 0) properties.item_id = itemId;
|
|
72
|
+
return {
|
|
73
|
+
event: StandardEvents.PURCHASE,
|
|
74
|
+
properties
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Build an add-to-cart event. */
|
|
78
|
+
function addToCartEvent(itemId, price, quantity = 1) {
|
|
79
|
+
return {
|
|
80
|
+
event: StandardEvents.ADD_TO_CART,
|
|
81
|
+
properties: {
|
|
82
|
+
item_id: itemId,
|
|
83
|
+
price,
|
|
84
|
+
quantity
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Build an add-to-wishlist event. */
|
|
89
|
+
function addToWishlistEvent(itemId, name, price) {
|
|
90
|
+
const properties = { item_id: itemId };
|
|
91
|
+
if (name !== void 0) properties.name = name;
|
|
92
|
+
if (price !== void 0) properties.price = price;
|
|
93
|
+
return {
|
|
94
|
+
event: StandardEvents.ADD_TO_WISHLIST,
|
|
95
|
+
properties
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** Build an initiate-checkout event. */
|
|
99
|
+
function initiateCheckoutEvent(value, currency = "USD", itemCount) {
|
|
100
|
+
const properties = {
|
|
101
|
+
value,
|
|
102
|
+
currency
|
|
103
|
+
};
|
|
104
|
+
if (itemCount !== void 0) properties.item_count = itemCount;
|
|
105
|
+
return {
|
|
106
|
+
event: StandardEvents.INITIATE_CHECKOUT,
|
|
107
|
+
properties
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** Build a start-trial event. */
|
|
111
|
+
function startTrialEvent(plan, durationDays) {
|
|
112
|
+
const properties = {};
|
|
113
|
+
if (plan !== void 0) properties.plan = plan;
|
|
114
|
+
if (durationDays !== void 0) properties.duration_days = durationDays;
|
|
115
|
+
return {
|
|
116
|
+
event: StandardEvents.START_TRIAL,
|
|
117
|
+
properties
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/** Build a subscribe event. */
|
|
121
|
+
function subscribeEvent(plan, amount, currency = "USD") {
|
|
122
|
+
return {
|
|
123
|
+
event: StandardEvents.SUBSCRIBE,
|
|
124
|
+
properties: {
|
|
125
|
+
plan,
|
|
126
|
+
amount,
|
|
127
|
+
currency
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** Build a level-start event. */
|
|
132
|
+
function levelStartEvent(level) {
|
|
133
|
+
return {
|
|
134
|
+
event: StandardEvents.LEVEL_START,
|
|
135
|
+
properties: { level }
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** Build a level-complete event. */
|
|
139
|
+
function levelCompleteEvent(level, score) {
|
|
140
|
+
const properties = { level };
|
|
141
|
+
if (score !== void 0) properties.score = score;
|
|
142
|
+
return {
|
|
143
|
+
event: StandardEvents.LEVEL_COMPLETE,
|
|
144
|
+
properties
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Build a tutorial-complete event. */
|
|
148
|
+
function tutorialCompleteEvent(name) {
|
|
149
|
+
const properties = {};
|
|
150
|
+
if (name !== void 0) properties.name = name;
|
|
151
|
+
return {
|
|
152
|
+
event: StandardEvents.TUTORIAL_COMPLETE,
|
|
153
|
+
properties
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/** Build a search event. */
|
|
157
|
+
function searchEvent(query, resultCount) {
|
|
158
|
+
const properties = { query };
|
|
159
|
+
if (resultCount !== void 0) properties.result_count = resultCount;
|
|
160
|
+
return {
|
|
161
|
+
event: StandardEvents.SEARCH,
|
|
162
|
+
properties
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Build a view-item event. */
|
|
166
|
+
function viewItemEvent(itemId, name, category) {
|
|
167
|
+
const properties = { item_id: itemId };
|
|
168
|
+
if (name !== void 0) properties.name = name;
|
|
169
|
+
if (category !== void 0) properties.category = category;
|
|
170
|
+
return {
|
|
171
|
+
event: StandardEvents.VIEW_ITEM,
|
|
172
|
+
properties
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/** Build a view-content event. */
|
|
176
|
+
function viewContentEvent(contentId, contentType, name) {
|
|
177
|
+
const properties = { content_id: contentId };
|
|
178
|
+
if (contentType !== void 0) properties.content_type = contentType;
|
|
179
|
+
if (name !== void 0) properties.name = name;
|
|
180
|
+
return {
|
|
181
|
+
event: StandardEvents.VIEW_CONTENT,
|
|
182
|
+
properties
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/** Build a share event. */
|
|
186
|
+
function shareEvent(contentType, method, contentId) {
|
|
187
|
+
const properties = { content_type: contentType };
|
|
188
|
+
if (method !== void 0) properties.method = method;
|
|
189
|
+
if (contentId !== void 0) properties.content_id = contentId;
|
|
190
|
+
return {
|
|
191
|
+
event: StandardEvents.SHARE,
|
|
192
|
+
properties
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/** Build a screen-view event. */
|
|
196
|
+
function screenViewEvent(name, screenClass) {
|
|
197
|
+
const properties = { screen_name: name };
|
|
198
|
+
if (screenClass !== void 0) properties.screen_class = screenClass;
|
|
199
|
+
return {
|
|
200
|
+
event: StandardEvents.SCREEN_VIEW,
|
|
201
|
+
properties
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/superwall.ts
|
|
207
|
+
/**
|
|
208
|
+
* Forward any Superwall event to Layers, prefixed with `superwall_`.
|
|
209
|
+
*
|
|
210
|
+
* Wire this up in your Superwall delegate / event handler:
|
|
211
|
+
* ```ts
|
|
212
|
+
* import Superwall from '@superwall/react-native-superwall';
|
|
213
|
+
* import { superwallOnEvent } from '@layers/react-native';
|
|
214
|
+
*
|
|
215
|
+
* Superwall.instance.setDelegate({
|
|
216
|
+
* handleSuperwallEvent(eventInfo) {
|
|
217
|
+
* superwallOnEvent(layers, eventInfo);
|
|
218
|
+
* }
|
|
219
|
+
* });
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
function superwallOnEvent(layers, eventInfo) {
|
|
223
|
+
try {
|
|
224
|
+
const eventName = eventInfo.event.rawName ?? eventInfo.event.type ?? "unknown";
|
|
225
|
+
const properties = { source: "superwall" };
|
|
226
|
+
if (eventInfo.params) Object.assign(properties, eventInfo.params);
|
|
227
|
+
layers.track(`superwall_${eventName}`, properties);
|
|
228
|
+
} catch {}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Track that a paywall was presented to the user.
|
|
232
|
+
*
|
|
233
|
+
* ```ts
|
|
234
|
+
* superwallTrackPresentation(layers, paywallInfo);
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
function superwallTrackPresentation(layers, paywallInfo) {
|
|
238
|
+
try {
|
|
239
|
+
if (!paywallInfo) return;
|
|
240
|
+
const properties = {
|
|
241
|
+
paywall_id: paywallInfo.identifier,
|
|
242
|
+
placement: paywallInfo.name ?? "unknown",
|
|
243
|
+
source: "superwall"
|
|
244
|
+
};
|
|
245
|
+
if (paywallInfo.url) properties.url = paywallInfo.url;
|
|
246
|
+
if (paywallInfo.experiment) properties.ab_test = {
|
|
247
|
+
id: paywallInfo.experiment.id,
|
|
248
|
+
variant: paywallInfo.experiment.variantId
|
|
249
|
+
};
|
|
250
|
+
layers.track("paywall_show", properties);
|
|
251
|
+
} catch {}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Track that a paywall was dismissed.
|
|
255
|
+
*
|
|
256
|
+
* ```ts
|
|
257
|
+
* superwallTrackDismiss(layers, paywallInfo);
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
function superwallTrackDismiss(layers, paywallInfo) {
|
|
261
|
+
try {
|
|
262
|
+
if (!paywallInfo) return;
|
|
263
|
+
layers.track("paywall_dismiss", {
|
|
264
|
+
paywall_id: paywallInfo.identifier,
|
|
265
|
+
source: "superwall"
|
|
266
|
+
});
|
|
267
|
+
} catch {}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Track a purchase initiated from a Superwall paywall.
|
|
271
|
+
*
|
|
272
|
+
* ```ts
|
|
273
|
+
* superwallTrackPurchase(layers, paywallInfo, product);
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
function superwallTrackPurchase(layers, paywallInfo, product) {
|
|
277
|
+
try {
|
|
278
|
+
const properties = {
|
|
279
|
+
paywall_id: paywallInfo?.identifier ?? "unknown",
|
|
280
|
+
source: "superwall"
|
|
281
|
+
};
|
|
282
|
+
if (product) {
|
|
283
|
+
const productId = product.productIdentifier ?? product.id;
|
|
284
|
+
if (productId) properties.product_id = productId;
|
|
285
|
+
if (product.price != null) properties.price = product.price;
|
|
286
|
+
const currency = product.currencyCode ?? product.currency;
|
|
287
|
+
if (currency) properties.currency = currency;
|
|
288
|
+
}
|
|
289
|
+
layers.track("paywall_purchase", properties);
|
|
290
|
+
} catch {}
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Track that a paywall was skipped (e.g. holdout, no rule match).
|
|
294
|
+
*
|
|
295
|
+
* ```ts
|
|
296
|
+
* superwallTrackSkip(layers, paywallInfo, 'holdout');
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
function superwallTrackSkip(layers, paywallInfo, reason) {
|
|
300
|
+
try {
|
|
301
|
+
layers.track("paywall_skip", {
|
|
302
|
+
paywall_id: paywallInfo?.identifier ?? "unknown",
|
|
303
|
+
reason,
|
|
304
|
+
source: "superwall"
|
|
305
|
+
});
|
|
306
|
+
} catch {}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get Layers attribution data formatted as Superwall user attributes.
|
|
310
|
+
*
|
|
311
|
+
* Pass the returned object to `Superwall.instance.setUserAttributes()`:
|
|
312
|
+
* ```ts
|
|
313
|
+
* const attrs = superwallUserAttributes(layers);
|
|
314
|
+
* Superwall.instance.setUserAttributes(attrs);
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
function superwallUserAttributes(layers) {
|
|
318
|
+
const attrs = {};
|
|
319
|
+
try {
|
|
320
|
+
const sessionId = layers.getSessionId();
|
|
321
|
+
if (sessionId) attrs.layers_session_id = sessionId;
|
|
322
|
+
const userId = layers.getAppUserId();
|
|
323
|
+
if (userId) attrs.layers_user_id = userId;
|
|
324
|
+
} catch {}
|
|
325
|
+
return attrs;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/commerce.ts
|
|
330
|
+
/**
|
|
331
|
+
* Track a successful purchase.
|
|
332
|
+
*
|
|
333
|
+
* ```ts
|
|
334
|
+
* import { trackPurchase } from '@layers/react-native';
|
|
335
|
+
*
|
|
336
|
+
* trackPurchase(layers, {
|
|
337
|
+
* productId: 'premium_monthly',
|
|
338
|
+
* price: 9.99,
|
|
339
|
+
* currency: 'USD',
|
|
340
|
+
* transactionId: 'txn_abc123',
|
|
341
|
+
* });
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
function trackPurchase(layers, params) {
|
|
345
|
+
const quantity = params.quantity ?? 1;
|
|
346
|
+
const props = {
|
|
347
|
+
product_id: params.productId,
|
|
348
|
+
price: params.price,
|
|
349
|
+
currency: params.currency,
|
|
350
|
+
quantity,
|
|
351
|
+
revenue: params.price * quantity,
|
|
352
|
+
...params.properties
|
|
353
|
+
};
|
|
354
|
+
if (params.transactionId !== void 0) props.transaction_id = params.transactionId;
|
|
355
|
+
if (params.isRestored !== void 0) props.is_restored = params.isRestored;
|
|
356
|
+
if (params.store !== void 0) props.store = params.store;
|
|
357
|
+
layers.track("purchase_success", props);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Track a failed purchase attempt.
|
|
361
|
+
*/
|
|
362
|
+
function trackPurchaseFailed(layers, params) {
|
|
363
|
+
const props = {
|
|
364
|
+
product_id: params.productId,
|
|
365
|
+
currency: params.currency,
|
|
366
|
+
error_code: params.errorCode,
|
|
367
|
+
...params.properties
|
|
368
|
+
};
|
|
369
|
+
if (params.errorMessage !== void 0) props.error_message = params.errorMessage;
|
|
370
|
+
layers.track("purchase_failed", props);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Track a subscription purchase or renewal.
|
|
374
|
+
*
|
|
375
|
+
* ```ts
|
|
376
|
+
* import { trackSubscription } from '@layers/react-native';
|
|
377
|
+
*
|
|
378
|
+
* trackSubscription(layers, {
|
|
379
|
+
* productId: 'pro_annual',
|
|
380
|
+
* price: 49.99,
|
|
381
|
+
* currency: 'USD',
|
|
382
|
+
* period: 'P1Y',
|
|
383
|
+
* });
|
|
384
|
+
* ```
|
|
385
|
+
*/
|
|
386
|
+
function trackSubscription(layers, params) {
|
|
387
|
+
const props = {
|
|
388
|
+
product_id: params.productId,
|
|
389
|
+
price: params.price,
|
|
390
|
+
currency: params.currency,
|
|
391
|
+
quantity: 1,
|
|
392
|
+
revenue: params.price,
|
|
393
|
+
...params.properties
|
|
394
|
+
};
|
|
395
|
+
if (params.transactionId !== void 0) props.transaction_id = params.transactionId;
|
|
396
|
+
if (params.period !== void 0) props.period = params.period;
|
|
397
|
+
if (params.isRenewal !== void 0) props.is_renewal = params.isRenewal;
|
|
398
|
+
if (params.isTrial !== void 0) props.is_trial = params.isTrial;
|
|
399
|
+
if (params.subscriptionGroupId !== void 0) props.subscription_group_id = params.subscriptionGroupId;
|
|
400
|
+
if (params.originalTransactionId !== void 0) props.original_transaction_id = params.originalTransactionId;
|
|
401
|
+
layers.track("subscribe", props);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Track a completed order with multiple line items.
|
|
405
|
+
*/
|
|
406
|
+
function trackOrder(layers, params) {
|
|
407
|
+
const currency = params.currency ?? "USD";
|
|
408
|
+
let total = params.subtotal;
|
|
409
|
+
if (params.tax !== void 0) total += params.tax;
|
|
410
|
+
if (params.shipping !== void 0) total += params.shipping;
|
|
411
|
+
if (params.discount !== void 0) total -= params.discount;
|
|
412
|
+
const props = {
|
|
413
|
+
order_id: params.orderId,
|
|
414
|
+
subtotal: params.subtotal,
|
|
415
|
+
total,
|
|
416
|
+
currency,
|
|
417
|
+
item_count: params.items.length,
|
|
418
|
+
revenue: total,
|
|
419
|
+
product_ids: params.items.map((i) => i.productId).join(","),
|
|
420
|
+
...params.properties
|
|
421
|
+
};
|
|
422
|
+
if (params.tax !== void 0) props.tax = params.tax;
|
|
423
|
+
if (params.shipping !== void 0) props.shipping = params.shipping;
|
|
424
|
+
if (params.discount !== void 0) props.discount = params.discount;
|
|
425
|
+
if (params.couponCode !== void 0) props.coupon_code = params.couponCode;
|
|
426
|
+
layers.track("purchase_success", props);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Track an item being added to the cart.
|
|
430
|
+
*/
|
|
431
|
+
function trackAddToCart(layers, item, properties) {
|
|
432
|
+
const quantity = item.quantity ?? 1;
|
|
433
|
+
const props = {
|
|
434
|
+
product_id: item.productId,
|
|
435
|
+
product_name: item.name,
|
|
436
|
+
price: item.price,
|
|
437
|
+
quantity,
|
|
438
|
+
value: item.price * quantity,
|
|
439
|
+
...properties
|
|
440
|
+
};
|
|
441
|
+
if (item.category !== void 0) props.category = item.category;
|
|
442
|
+
layers.track("add_to_cart", props);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Track an item being removed from the cart.
|
|
446
|
+
*/
|
|
447
|
+
function trackRemoveFromCart(layers, item, properties) {
|
|
448
|
+
const quantity = item.quantity ?? 1;
|
|
449
|
+
const props = {
|
|
450
|
+
product_id: item.productId,
|
|
451
|
+
product_name: item.name,
|
|
452
|
+
price: item.price,
|
|
453
|
+
quantity,
|
|
454
|
+
...properties
|
|
455
|
+
};
|
|
456
|
+
if (item.category !== void 0) props.category = item.category;
|
|
457
|
+
layers.track("remove_from_cart", props);
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Track beginning the checkout flow.
|
|
461
|
+
*/
|
|
462
|
+
function trackBeginCheckout(layers, items, currency = "USD", properties) {
|
|
463
|
+
const total = items.reduce((sum, item) => sum + item.price * (item.quantity ?? 1), 0);
|
|
464
|
+
const props = {
|
|
465
|
+
item_count: items.length,
|
|
466
|
+
value: total,
|
|
467
|
+
currency,
|
|
468
|
+
product_ids: items.map((i) => i.productId).join(","),
|
|
469
|
+
...properties
|
|
470
|
+
};
|
|
471
|
+
layers.track("begin_checkout", props);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Track viewing a product detail page.
|
|
475
|
+
*/
|
|
476
|
+
function trackViewProduct(layers, productId, name, price, currency = "USD", category, properties) {
|
|
477
|
+
const props = {
|
|
478
|
+
product_id: productId,
|
|
479
|
+
product_name: name,
|
|
480
|
+
price,
|
|
481
|
+
currency,
|
|
482
|
+
...properties
|
|
483
|
+
};
|
|
484
|
+
if (category !== void 0) props.category = category;
|
|
485
|
+
layers.track("view_item", props);
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Track a refund.
|
|
489
|
+
*/
|
|
490
|
+
function trackRefund(layers, params) {
|
|
491
|
+
const props = {
|
|
492
|
+
transaction_id: params.transactionId,
|
|
493
|
+
amount: params.amount,
|
|
494
|
+
currency: params.currency,
|
|
495
|
+
...params.properties
|
|
496
|
+
};
|
|
497
|
+
if (params.reason !== void 0) props.reason = params.reason;
|
|
498
|
+
layers.track("refund", props);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/revenuecat.ts
|
|
503
|
+
let _isConnected = false;
|
|
504
|
+
let _activeSubscriptions = /* @__PURE__ */ new Set();
|
|
505
|
+
let _isInitialLoadDone = false;
|
|
506
|
+
let _connectedLayers = null;
|
|
507
|
+
/**
|
|
508
|
+
* Connect Layers to your existing RevenueCat Purchases instance.
|
|
509
|
+
*
|
|
510
|
+
* Listens for customer info updates to detect new subscriptions and syncs
|
|
511
|
+
* subscriber status to Layers user properties.
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```ts
|
|
515
|
+
* import Purchases from 'react-native-purchases';
|
|
516
|
+
* import { LayersReactNative, connectRevenueCat } from '@layers/react-native';
|
|
517
|
+
*
|
|
518
|
+
* const layers = new LayersReactNative();
|
|
519
|
+
* await layers.init({ appId: 'your-app-id', environment: 'production' });
|
|
520
|
+
*
|
|
521
|
+
* connectRevenueCat({
|
|
522
|
+
* layers,
|
|
523
|
+
* purchases: Purchases,
|
|
524
|
+
* });
|
|
525
|
+
* ```
|
|
526
|
+
*
|
|
527
|
+
* @param config - Configuration including the Layers instance.
|
|
528
|
+
* @param purchases - The RevenueCat Purchases instance (duck-typed to avoid hard dependency).
|
|
529
|
+
*/
|
|
530
|
+
function connectRevenueCat(config, purchases) {
|
|
531
|
+
if (_isConnected) return;
|
|
532
|
+
try {
|
|
533
|
+
if (!purchases) return;
|
|
534
|
+
if (typeof purchases.addCustomerInfoUpdateListener !== "function") return;
|
|
535
|
+
if (typeof purchases.getCustomerInfo !== "function") return;
|
|
536
|
+
_connectedLayers = config.layers;
|
|
537
|
+
purchases.addCustomerInfoUpdateListener((info) => {
|
|
538
|
+
handleCustomerInfoUpdate(config, info, false);
|
|
539
|
+
});
|
|
540
|
+
purchases.getCustomerInfo().then(({ customerInfo }) => {
|
|
541
|
+
handleCustomerInfoUpdate(config, customerInfo, true);
|
|
542
|
+
}).catch(() => {});
|
|
543
|
+
_isConnected = true;
|
|
544
|
+
} catch {}
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Track a RevenueCat package purchase manually.
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```ts
|
|
551
|
+
* const offerings = await Purchases.getOfferings();
|
|
552
|
+
* const pkg = offerings.current?.availablePackages[0];
|
|
553
|
+
* if (pkg) trackRevenueCatPurchase(layers, pkg);
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
function trackRevenueCatPurchase(layers, rcPackage, store) {
|
|
557
|
+
try {
|
|
558
|
+
if (!rcPackage?.product) return;
|
|
559
|
+
let resolvedStore = store ?? "app_store";
|
|
560
|
+
if (!store) try {
|
|
561
|
+
const { Platform } = __require("react-native");
|
|
562
|
+
resolvedStore = Platform.OS === "ios" ? "app_store" : "play_store";
|
|
563
|
+
} catch {}
|
|
564
|
+
layers.track("purchase_success", {
|
|
565
|
+
product_id: rcPackage.product.identifier ?? "",
|
|
566
|
+
price: rcPackage.product.price ?? 0,
|
|
567
|
+
currency: rcPackage.product.currencyCode ?? "USD",
|
|
568
|
+
store: resolvedStore,
|
|
569
|
+
source: "revenuecat"
|
|
570
|
+
});
|
|
571
|
+
} catch {}
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Manually sync RevenueCat subscriber attributes to Layers user properties.
|
|
575
|
+
*
|
|
576
|
+
* This is called automatically when using `connectRevenueCat()`, but can also
|
|
577
|
+
* be called manually if needed.
|
|
578
|
+
*/
|
|
579
|
+
function syncRevenueCatAttributes(layers, customerInfo) {
|
|
580
|
+
try {
|
|
581
|
+
const userProps = { is_subscriber: Array.isArray(customerInfo.activeSubscriptions) && customerInfo.activeSubscriptions.length > 0 };
|
|
582
|
+
if (customerInfo.originalAppUserId) userProps.revenuecat_original_app_user_id = customerInfo.originalAppUserId;
|
|
583
|
+
layers.setUserProperties(userProps);
|
|
584
|
+
} catch {}
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Reset RevenueCat integration state. For testing only.
|
|
588
|
+
*/
|
|
589
|
+
function resetRevenueCatForTesting() {
|
|
590
|
+
_isConnected = false;
|
|
591
|
+
_activeSubscriptions = /* @__PURE__ */ new Set();
|
|
592
|
+
_isInitialLoadDone = false;
|
|
593
|
+
_connectedLayers = null;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Whether the RevenueCat integration is currently connected.
|
|
597
|
+
*/
|
|
598
|
+
function isRevenueCatConnected() {
|
|
599
|
+
return _isConnected;
|
|
600
|
+
}
|
|
601
|
+
function handleCustomerInfoUpdate(config, info, isInitialLoad) {
|
|
602
|
+
try {
|
|
603
|
+
const currentSubs = new Set(Array.isArray(info.activeSubscriptions) ? info.activeSubscriptions : []);
|
|
604
|
+
if (isInitialLoad && _isInitialLoadDone) return;
|
|
605
|
+
if (!isInitialLoad && _isInitialLoadDone && _connectedLayers) {
|
|
606
|
+
for (const subId of currentSubs) if (!_activeSubscriptions.has(subId)) {
|
|
607
|
+
if (config.onSubscriptionStart !== null) if (config.onSubscriptionStart) config.onSubscriptionStart(subId);
|
|
608
|
+
else _connectedLayers.track("subscription_start", {
|
|
609
|
+
product_id: subId,
|
|
610
|
+
source: "revenuecat"
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
_activeSubscriptions = currentSubs;
|
|
615
|
+
_isInitialLoadDone = true;
|
|
616
|
+
if (_connectedLayers) syncRevenueCatAttributes(_connectedLayers, info);
|
|
617
|
+
} catch {}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region src/background-flush.ts
|
|
622
|
+
/**
|
|
623
|
+
* Task identifier for Layers background flush.
|
|
624
|
+
*
|
|
625
|
+
* Use this constant when registering the background task with
|
|
626
|
+
* `react-native-background-fetch`, `expo-task-manager`, or any
|
|
627
|
+
* other background task scheduler.
|
|
628
|
+
*/
|
|
629
|
+
const BACKGROUND_FLUSH_TASK_NAME = "com.layers.sdk.background-flush";
|
|
630
|
+
/**
|
|
631
|
+
* Minimum recommended interval (in minutes) between background flushes.
|
|
632
|
+
* Both iOS and Android enforce a minimum of ~15 minutes for background
|
|
633
|
+
* fetch tasks.
|
|
634
|
+
*/
|
|
635
|
+
const BACKGROUND_FLUSH_MIN_INTERVAL_MINUTES = 15;
|
|
636
|
+
/**
|
|
637
|
+
* Creates a background flush handler function.
|
|
638
|
+
*
|
|
639
|
+
* The returned async function, when called by a background task scheduler,
|
|
640
|
+
* will flush any queued events via the Layers SDK. It is safe to call even
|
|
641
|
+
* if the SDK is not initialized (it will silently no-op).
|
|
642
|
+
*
|
|
643
|
+
* @param getLayers - A getter that returns the current LayersReactNative
|
|
644
|
+
* instance, or `null` if the SDK is not yet initialized.
|
|
645
|
+
* @returns An async handler suitable for use with background task libraries.
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* ```typescript
|
|
649
|
+
* const handler = createBackgroundFlushHandler(() => myLayersInstance);
|
|
650
|
+
* ```
|
|
651
|
+
*/
|
|
652
|
+
function createBackgroundFlushHandler(getLayers) {
|
|
653
|
+
return async () => {
|
|
654
|
+
const layers = getLayers();
|
|
655
|
+
if (!layers) return { success: false };
|
|
656
|
+
try {
|
|
657
|
+
await layers.flush();
|
|
658
|
+
return { success: true };
|
|
659
|
+
} catch {
|
|
660
|
+
return { success: false };
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Registers a background flush task with `expo-task-manager`.
|
|
666
|
+
*
|
|
667
|
+
* This must be called at module scope (outside of any component) as
|
|
668
|
+
* `expo-task-manager` requires tasks to be defined before the app mounts.
|
|
669
|
+
*
|
|
670
|
+
* @param taskManager - The `expo-task-manager` module (import * as TaskManager from 'expo-task-manager').
|
|
671
|
+
* @param getLayers - A getter that returns the current LayersReactNative
|
|
672
|
+
* instance, or `null` if the SDK is not yet initialized.
|
|
673
|
+
*
|
|
674
|
+
* @example
|
|
675
|
+
* ```typescript
|
|
676
|
+
* import * as TaskManager from 'expo-task-manager';
|
|
677
|
+
* import { registerExpoBackgroundFlush } from '@layers/expo';
|
|
678
|
+
*
|
|
679
|
+
* let layers: LayersReactNative | null = null;
|
|
680
|
+
* registerExpoBackgroundFlush(TaskManager, () => layers);
|
|
681
|
+
*
|
|
682
|
+
* // Later, in your app initialization:
|
|
683
|
+
* layers = new LayersReactNative({ appId: '...', environment: 'production' });
|
|
684
|
+
* await layers.init();
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
687
|
+
function registerExpoBackgroundFlush(taskManager, getLayers) {
|
|
688
|
+
const handler = createBackgroundFlushHandler(getLayers);
|
|
689
|
+
taskManager.defineTask(BACKGROUND_FLUSH_TASK_NAME, async () => {
|
|
690
|
+
await handler();
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
//#endregion
|
|
695
|
+
//#region src/index.ts
|
|
696
|
+
const SDK_VERSION = typeof __LAYERS_RN_VERSION__ !== "undefined" ? __LAYERS_RN_VERSION__ : "0.1.0";
|
|
697
|
+
var LayersReactNative = class LayersReactNative {
|
|
698
|
+
core;
|
|
699
|
+
appUserId;
|
|
700
|
+
isOnline = true;
|
|
701
|
+
enableDebug;
|
|
702
|
+
appStateSubscription = null;
|
|
703
|
+
netInfoUnsubscribe = null;
|
|
704
|
+
config;
|
|
705
|
+
userIdLocked = false;
|
|
706
|
+
errorListeners = /* @__PURE__ */ new Set();
|
|
707
|
+
_skanManager = null;
|
|
708
|
+
_lastSkanConfigStr = null;
|
|
709
|
+
deepLinkUnsubscribe = null;
|
|
710
|
+
static MAX_RECENT_EVENTS = 20;
|
|
711
|
+
_recentEvents = [];
|
|
712
|
+
_isInitialized = false;
|
|
713
|
+
_configPollTimer = null;
|
|
714
|
+
static CONFIG_POLL_INTERVAL_MS = 3e5;
|
|
715
|
+
_adServicesToken = null;
|
|
716
|
+
_installReferrer = null;
|
|
717
|
+
_hadPriorSdkState = false;
|
|
718
|
+
_attributionDeeplinkId = null;
|
|
719
|
+
_attributionGclid = null;
|
|
720
|
+
static ATTRIBUTION_DEEPLINK_ID_KEY = "@layers/deeplink_id";
|
|
721
|
+
static ATTRIBUTION_GCLID_KEY = "@layers/gclid";
|
|
722
|
+
_initListener = null;
|
|
723
|
+
constructor(config) {
|
|
724
|
+
this.enableDebug = config.enableDebug ?? false;
|
|
725
|
+
this.appUserId = config.appUserId;
|
|
726
|
+
this.config = config;
|
|
727
|
+
const httpClient = new FetchHttpClient();
|
|
728
|
+
this.core = LayersCore.init({
|
|
729
|
+
config: {
|
|
730
|
+
appId: config.appId,
|
|
731
|
+
environment: config.environment,
|
|
732
|
+
...config.baseUrl != null && { baseUrl: config.baseUrl },
|
|
733
|
+
...config.enableDebug != null && { enableDebug: config.enableDebug },
|
|
734
|
+
...config.flushIntervalMs != null && { flushIntervalMs: config.flushIntervalMs },
|
|
735
|
+
...config.flushThreshold != null && { flushThreshold: config.flushThreshold },
|
|
736
|
+
...config.maxQueueSize != null && { maxQueueSize: config.maxQueueSize },
|
|
737
|
+
sdkVersion: `react-native/${SDK_VERSION}`
|
|
738
|
+
},
|
|
739
|
+
httpClient,
|
|
740
|
+
persistence: new MemoryPersistence()
|
|
741
|
+
});
|
|
742
|
+
if (this.appUserId) {
|
|
743
|
+
this.core.identify(this.appUserId);
|
|
744
|
+
this.userIdLocked = true;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
async init() {
|
|
748
|
+
const initStartTime = Date.now();
|
|
749
|
+
try {
|
|
750
|
+
const persistence = await createAsyncStoragePersistence(this.config.appId);
|
|
751
|
+
const httpClient = new FetchHttpClient();
|
|
752
|
+
this.core.shutdown();
|
|
753
|
+
this.core = LayersCore.init({
|
|
754
|
+
config: {
|
|
755
|
+
appId: this.config.appId,
|
|
756
|
+
environment: this.config.environment,
|
|
757
|
+
...this.config.baseUrl != null && { baseUrl: this.config.baseUrl },
|
|
758
|
+
...this.config.enableDebug != null && { enableDebug: this.config.enableDebug },
|
|
759
|
+
...this.config.flushIntervalMs != null && { flushIntervalMs: this.config.flushIntervalMs },
|
|
760
|
+
...this.config.flushThreshold != null && { flushThreshold: this.config.flushThreshold },
|
|
761
|
+
...this.config.maxQueueSize != null && { maxQueueSize: this.config.maxQueueSize },
|
|
762
|
+
sdkVersion: `react-native/${SDK_VERSION}`
|
|
763
|
+
},
|
|
764
|
+
httpClient,
|
|
765
|
+
persistence
|
|
766
|
+
});
|
|
767
|
+
if (this.appUserId) this.core.identify(this.appUserId);
|
|
768
|
+
} catch {}
|
|
769
|
+
await this.initializeDeviceInfo();
|
|
770
|
+
this.setupAppStateListener();
|
|
771
|
+
this.setupNetInfoListener();
|
|
772
|
+
const mainThreadDurationMs = Date.now() - initStartTime;
|
|
773
|
+
await this.restoreAttributionData();
|
|
774
|
+
await this.core.fetchRemoteConfig().catch(() => {});
|
|
775
|
+
await this.configureSkanFromRemoteConfig();
|
|
776
|
+
this.startConfigPolling();
|
|
777
|
+
let clipboardData = null;
|
|
778
|
+
try {
|
|
779
|
+
const { Platform } = __require("react-native");
|
|
780
|
+
if (Platform.OS === "ios") {
|
|
781
|
+
let clipboardEnabled = false;
|
|
782
|
+
try {
|
|
783
|
+
const configJson = this.core.getRemoteConfigJson?.();
|
|
784
|
+
if (configJson) clipboardEnabled = JSON.parse(configJson)?.clipboard_attribution_enabled === true;
|
|
785
|
+
} catch {}
|
|
786
|
+
if (clipboardEnabled) clipboardData = await readClipboardAttribution();
|
|
787
|
+
}
|
|
788
|
+
} catch {}
|
|
789
|
+
if (this.config.autoTrackAppOpen !== false) {
|
|
790
|
+
const appOpenProps = {};
|
|
791
|
+
let isFirstLaunchByFlag = true;
|
|
792
|
+
try {
|
|
793
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
794
|
+
if (AsyncStorage) {
|
|
795
|
+
if (await AsyncStorage.getItem(FIRST_LAUNCH_TRACKED_KEY) === "true") isFirstLaunchByFlag = false;
|
|
796
|
+
}
|
|
797
|
+
} catch {}
|
|
798
|
+
const isFirstLaunch = await shouldTreatAsNewInstall(isFirstLaunchByFlag, this._hadPriorSdkState, this.enableDebug);
|
|
799
|
+
appOpenProps.is_first_launch = isFirstLaunch;
|
|
800
|
+
if (isFirstLaunch) try {
|
|
801
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
802
|
+
if (AsyncStorage) await AsyncStorage.setItem(FIRST_LAUNCH_TRACKED_KEY, "true");
|
|
803
|
+
} catch {}
|
|
804
|
+
if (clipboardData) {
|
|
805
|
+
appOpenProps.clipboard_attribution_url = clipboardData.clickUrl;
|
|
806
|
+
appOpenProps.clipboard_click_id = clipboardData.clickId;
|
|
807
|
+
}
|
|
808
|
+
if (this._adServicesToken) appOpenProps.adservices_token = this._adServicesToken;
|
|
809
|
+
if (this._installReferrer) {
|
|
810
|
+
appOpenProps.install_referrer_url = this._installReferrer.referrerUrl;
|
|
811
|
+
if (this._installReferrer.referrerClickTimestamp) appOpenProps.install_referrer_click_timestamp = this._installReferrer.referrerClickTimestamp;
|
|
812
|
+
if (this._installReferrer.installBeginTimestamp) appOpenProps.install_referrer_install_timestamp = this._installReferrer.installBeginTimestamp;
|
|
813
|
+
}
|
|
814
|
+
this.track("app_open", appOpenProps);
|
|
815
|
+
}
|
|
816
|
+
if (this.config.autoTrackDeepLinks !== false) this.setupDeepLinkAutoTracking();
|
|
817
|
+
this._isInitialized = true;
|
|
818
|
+
const totalDurationMs = Date.now() - initStartTime;
|
|
819
|
+
if (this.enableDebug) console.log(`[Layers] Init timing: mainThread=${String(mainThreadDurationMs)}ms, total=${String(totalDurationMs)}ms`);
|
|
820
|
+
if (this._initListener) try {
|
|
821
|
+
this._initListener(mainThreadDurationMs, totalDurationMs);
|
|
822
|
+
} catch (e) {
|
|
823
|
+
if (this.enableDebug) console.warn("[Layers] InitListener threw:", e);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
track(eventName, properties) {
|
|
827
|
+
if (this.enableDebug) console.log(`[Layers] track("${eventName}", ${Object.keys(properties ?? {}).length} properties)`);
|
|
828
|
+
try {
|
|
829
|
+
const merged = this.mergeAttributionProperties(properties);
|
|
830
|
+
const depthBefore = this.core.queueDepth();
|
|
831
|
+
this.core.track(eventName, merged, this.appUserId);
|
|
832
|
+
const depthAfter = this.core.queueDepth();
|
|
833
|
+
if (depthAfter <= depthBefore && this.enableDebug) console.warn(`[Layers] track("${eventName}") — event may not have been queued (depth before=${String(depthBefore)}, after=${String(depthAfter)})`);
|
|
834
|
+
this.recordRecentEvent(eventName, properties);
|
|
835
|
+
if (this._skanManager) this._skanManager.processEvent(eventName, merged ?? {}).catch(() => {});
|
|
836
|
+
} catch (e) {
|
|
837
|
+
this.emitError(e);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
screen(screenName, properties) {
|
|
841
|
+
if (this.enableDebug) console.log(`[Layers] screen("${screenName}", ${Object.keys(properties ?? {}).length} properties)`);
|
|
842
|
+
try {
|
|
843
|
+
const merged = this.mergeAttributionProperties(properties);
|
|
844
|
+
const depthBefore = this.core.queueDepth();
|
|
845
|
+
this.core.screen(screenName, merged, this.appUserId);
|
|
846
|
+
const depthAfter = this.core.queueDepth();
|
|
847
|
+
if (depthAfter <= depthBefore && this.enableDebug) console.warn(`[Layers] screen("${screenName}") — event may not have been queued (depth before=${String(depthBefore)}, after=${String(depthAfter)})`);
|
|
848
|
+
this.recordRecentEvent(`screen:${screenName}`, properties);
|
|
849
|
+
} catch (e) {
|
|
850
|
+
this.emitError(e);
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
async setUserProperties(properties) {
|
|
854
|
+
this.core.setUserProperties(properties);
|
|
855
|
+
}
|
|
856
|
+
async setUserPropertiesOnce(properties) {
|
|
857
|
+
this.core.setUserPropertiesOnce(properties);
|
|
858
|
+
}
|
|
859
|
+
async setConsent(consent) {
|
|
860
|
+
this.core.setConsent(consent);
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Request App Tracking Transparency authorization (iOS only).
|
|
864
|
+
* After the user responds, this method automatically:
|
|
865
|
+
* - Collects IDFA if authorized
|
|
866
|
+
* - Updates device info with IDFA and ATT status
|
|
867
|
+
* - Sets advertising consent based on ATT result
|
|
868
|
+
*
|
|
869
|
+
* Returns the ATT status string.
|
|
870
|
+
*/
|
|
871
|
+
async requestTrackingPermission() {
|
|
872
|
+
let status;
|
|
873
|
+
try {
|
|
874
|
+
const ExpoTT = await import("./TrackingTransparency-DunpgkgS.mjs").catch(() => null);
|
|
875
|
+
if (ExpoTT) {
|
|
876
|
+
const { status: expoStatus } = await ExpoTT.requestTrackingPermissionsAsync();
|
|
877
|
+
status = {
|
|
878
|
+
granted: "authorized",
|
|
879
|
+
denied: "denied",
|
|
880
|
+
restricted: "restricted",
|
|
881
|
+
undetermined: "not_determined"
|
|
882
|
+
}[expoStatus] ?? "not_determined";
|
|
883
|
+
} else status = await requestTrackingAuthorization();
|
|
884
|
+
} catch {
|
|
885
|
+
status = await requestTrackingAuthorization();
|
|
886
|
+
}
|
|
887
|
+
const updates = {
|
|
888
|
+
...this.core.getDeviceContext(),
|
|
889
|
+
attStatus: status
|
|
890
|
+
};
|
|
891
|
+
if (status === "authorized") try {
|
|
892
|
+
const idfa = await getAdvertisingId();
|
|
893
|
+
if (idfa) updates.idfa = idfa;
|
|
894
|
+
} catch {}
|
|
895
|
+
this.core.setDeviceContext(updates);
|
|
896
|
+
const advertisingAllowed = status === "authorized";
|
|
897
|
+
this.core.setConsent({ advertising: advertisingAllowed });
|
|
898
|
+
if (this.enableDebug) console.log(`[Layers] ATT status: ${status}, advertising consent: ${String(advertisingAllowed)}`);
|
|
899
|
+
return status;
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Set the app user ID. Uses set-user-once semantics:
|
|
903
|
+
* once set, subsequent calls are ignored until clearAppUserId() is called.
|
|
904
|
+
*/
|
|
905
|
+
setAppUserId(appUserId) {
|
|
906
|
+
if (this.enableDebug) console.log(`[Layers] setAppUserId("${appUserId}")`);
|
|
907
|
+
if (this.userIdLocked && this.appUserId) {
|
|
908
|
+
if (this.enableDebug) console.warn("[Layers] appUserId already set. Call clearAppUserId() first to change it.");
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
this.appUserId = appUserId;
|
|
912
|
+
this.userIdLocked = true;
|
|
913
|
+
this.core.identify(appUserId);
|
|
914
|
+
}
|
|
915
|
+
clearAppUserId() {
|
|
916
|
+
this.appUserId = void 0;
|
|
917
|
+
this.userIdLocked = false;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Reset the SDK state: clears the user ID, unlocks set-user-once,
|
|
921
|
+
* clears user properties, and starts a new session.
|
|
922
|
+
*
|
|
923
|
+
* After reset(), the SDK behaves as if no user has been identified.
|
|
924
|
+
* A new anonymous session is started. Events tracked after reset()
|
|
925
|
+
* will not carry the previous user's identity.
|
|
926
|
+
*/
|
|
927
|
+
reset() {
|
|
928
|
+
if (this.enableDebug) console.log("[Layers] reset()");
|
|
929
|
+
this.appUserId = void 0;
|
|
930
|
+
this.userIdLocked = false;
|
|
931
|
+
try {
|
|
932
|
+
this.core.setUserProperties({});
|
|
933
|
+
} catch (e) {
|
|
934
|
+
this.emitError(e);
|
|
935
|
+
}
|
|
936
|
+
try {
|
|
937
|
+
this.core.startNewSession();
|
|
938
|
+
} catch (e) {
|
|
939
|
+
this.emitError(e);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* Associate all subsequent events with a group (company, team, organization).
|
|
944
|
+
* Pass `undefined` or empty string to clear the group association.
|
|
945
|
+
*/
|
|
946
|
+
group(groupId, properties) {
|
|
947
|
+
if (this.enableDebug) console.log(`[Layers] group(${groupId ? `"${groupId}"` : "undefined"}, ${Object.keys(properties ?? {}).length} properties)`);
|
|
948
|
+
try {
|
|
949
|
+
this.core.group(groupId ?? "", properties);
|
|
950
|
+
} catch (e) {
|
|
951
|
+
this.emitError(e);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
getAppUserId() {
|
|
955
|
+
return this.appUserId;
|
|
956
|
+
}
|
|
957
|
+
getSessionId() {
|
|
958
|
+
return this.core.getSessionId();
|
|
959
|
+
}
|
|
960
|
+
getConsentState() {
|
|
961
|
+
return this.core.getConsentState();
|
|
962
|
+
}
|
|
963
|
+
setDeviceInfo(deviceInfo) {
|
|
964
|
+
this.core.setDeviceContext(deviceInfo);
|
|
965
|
+
}
|
|
966
|
+
async flush() {
|
|
967
|
+
try {
|
|
968
|
+
await this.core.flushAsync();
|
|
969
|
+
} catch (e) {
|
|
970
|
+
this.emitError(e);
|
|
971
|
+
this.core.flush();
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Flush all queued events synchronously (blocking).
|
|
976
|
+
*
|
|
977
|
+
* Drains all batches from the queue and sends them via HTTP, awaiting
|
|
978
|
+
* each batch before proceeding. Does not return until all batches have
|
|
979
|
+
* been sent or failed.
|
|
980
|
+
*
|
|
981
|
+
* This is useful for AppState background transitions where the app may
|
|
982
|
+
* be suspended shortly after the call returns.
|
|
983
|
+
*/
|
|
984
|
+
async flushBlocking() {
|
|
985
|
+
try {
|
|
986
|
+
let depth = this.core.queueDepth();
|
|
987
|
+
while (depth > 0) {
|
|
988
|
+
await this.core.flushAsync();
|
|
989
|
+
const newDepth = this.core.queueDepth();
|
|
990
|
+
if (newDepth >= depth) break;
|
|
991
|
+
depth = newDepth;
|
|
992
|
+
}
|
|
993
|
+
} catch (e) {
|
|
994
|
+
this.emitError(e);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Register an error listener. Errors from track/screen/flush
|
|
999
|
+
* that would otherwise be silently dropped are forwarded here.
|
|
1000
|
+
*/
|
|
1001
|
+
on(event, listener) {
|
|
1002
|
+
if (event === "error") this.errorListeners.add(listener);
|
|
1003
|
+
return this;
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Remove a previously registered error listener.
|
|
1007
|
+
*/
|
|
1008
|
+
off(event, listener) {
|
|
1009
|
+
if (event === "error") this.errorListeners.delete(listener);
|
|
1010
|
+
return this;
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Set a listener to receive SDK initialization timing metrics.
|
|
1014
|
+
* Must be called **before** `init()` to receive the callback.
|
|
1015
|
+
* Pass `null` to clear the listener.
|
|
1016
|
+
*
|
|
1017
|
+
* @param listener A function receiving `(mainThreadDurationMs, totalDurationMs)`.
|
|
1018
|
+
* `mainThreadDurationMs` is the time spent before background work begins.
|
|
1019
|
+
* `totalDurationMs` is the total wall-clock time of the `init()` call.
|
|
1020
|
+
*/
|
|
1021
|
+
setInitListener(listener) {
|
|
1022
|
+
this._initListener = listener;
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Returns the AdServices attribution token (iOS only), or null if not
|
|
1026
|
+
* available. Collected automatically during init() on iOS 14.3+.
|
|
1027
|
+
* Does NOT require ATT consent.
|
|
1028
|
+
*/
|
|
1029
|
+
getAdServicesToken() {
|
|
1030
|
+
return this._adServicesToken;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Returns the Google Play install referrer data (Android only), or null
|
|
1034
|
+
* if not available. Collected automatically during init() on Android.
|
|
1035
|
+
*/
|
|
1036
|
+
getInstallReferrer() {
|
|
1037
|
+
return this._installReferrer;
|
|
1038
|
+
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Returns the auto-configured SKANManager instance, or null if SKAN was not
|
|
1041
|
+
* configured by the server's remote config.
|
|
1042
|
+
* On iOS, when remote config contains a `skan` section with `preset` or
|
|
1043
|
+
* `customRules`, the SDK automatically creates and configures a SKANManager.
|
|
1044
|
+
* Every `track()` call is automatically forwarded to SKAN rule evaluation.
|
|
1045
|
+
*/
|
|
1046
|
+
getSkanManager() {
|
|
1047
|
+
return this._skanManager;
|
|
1048
|
+
}
|
|
1049
|
+
/** Whether the SDK has completed async initialization. */
|
|
1050
|
+
get isInitialized() {
|
|
1051
|
+
return this._isInitialized;
|
|
1052
|
+
}
|
|
1053
|
+
/** The configured environment ('development' | 'staging' | 'production'). */
|
|
1054
|
+
get environment() {
|
|
1055
|
+
return this.config.environment;
|
|
1056
|
+
}
|
|
1057
|
+
/** The configured app ID. */
|
|
1058
|
+
get appId() {
|
|
1059
|
+
return this.config.appId;
|
|
1060
|
+
}
|
|
1061
|
+
/** Number of events currently queued. */
|
|
1062
|
+
getQueueDepth() {
|
|
1063
|
+
return this.core.queueDepth();
|
|
1064
|
+
}
|
|
1065
|
+
/** Current device context from the core. */
|
|
1066
|
+
getDeviceContext() {
|
|
1067
|
+
return this.core.getDeviceContext();
|
|
1068
|
+
}
|
|
1069
|
+
/** Whether the SDK believes the device is online. */
|
|
1070
|
+
getNetworkStatus() {
|
|
1071
|
+
return this.isOnline;
|
|
1072
|
+
}
|
|
1073
|
+
/** SDK version string. */
|
|
1074
|
+
getSdkVersion() {
|
|
1075
|
+
return SDK_VERSION;
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Returns the most recent tracked events (newest first).
|
|
1079
|
+
* Each entry is a formatted string like "12:34:56 event_name (3 props)".
|
|
1080
|
+
*/
|
|
1081
|
+
getRecentEvents() {
|
|
1082
|
+
return this._recentEvents;
|
|
1083
|
+
}
|
|
1084
|
+
recordRecentEvent(eventName, properties) {
|
|
1085
|
+
const now = /* @__PURE__ */ new Date();
|
|
1086
|
+
const time = `${String(now.getHours()).padStart(2, "0")}:${String(now.getMinutes()).padStart(2, "0")}:${String(now.getSeconds()).padStart(2, "0")}`;
|
|
1087
|
+
const propCount = Object.keys(properties ?? {}).length;
|
|
1088
|
+
const entry = `${time} ${eventName}${propCount > 0 ? ` (${String(propCount)} props)` : ""}`;
|
|
1089
|
+
this._recentEvents.unshift(entry);
|
|
1090
|
+
if (this._recentEvents.length > LayersReactNative.MAX_RECENT_EVENTS) this._recentEvents.pop();
|
|
1091
|
+
}
|
|
1092
|
+
emitError(error) {
|
|
1093
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
1094
|
+
for (const listener of this.errorListeners) try {
|
|
1095
|
+
listener(err);
|
|
1096
|
+
} catch {}
|
|
1097
|
+
if (this.enableDebug && this.errorListeners.size === 0) console.warn("[Layers]", err.message);
|
|
1098
|
+
}
|
|
1099
|
+
shutdown() {
|
|
1100
|
+
this.stopConfigPolling();
|
|
1101
|
+
if (this.appStateSubscription) {
|
|
1102
|
+
this.appStateSubscription.remove();
|
|
1103
|
+
this.appStateSubscription = null;
|
|
1104
|
+
}
|
|
1105
|
+
if (this.netInfoUnsubscribe) {
|
|
1106
|
+
this.netInfoUnsubscribe();
|
|
1107
|
+
this.netInfoUnsubscribe = null;
|
|
1108
|
+
}
|
|
1109
|
+
if (this.deepLinkUnsubscribe) {
|
|
1110
|
+
this.deepLinkUnsubscribe();
|
|
1111
|
+
this.deepLinkUnsubscribe = null;
|
|
1112
|
+
}
|
|
1113
|
+
this._attributionDeeplinkId = null;
|
|
1114
|
+
this._attributionGclid = null;
|
|
1115
|
+
this._initListener = null;
|
|
1116
|
+
this.core.shutdown();
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Store attribution data that will be attached to all subsequent events.
|
|
1120
|
+
*
|
|
1121
|
+
* The values are persisted in AsyncStorage so they survive app restarts.
|
|
1122
|
+
* Pass `null` to clear a value.
|
|
1123
|
+
*
|
|
1124
|
+
* When set, `deeplink_id` and/or `gclid` are included in every event's properties.
|
|
1125
|
+
*
|
|
1126
|
+
* @param deeplinkId Deep link identifier for server-side attribution matching.
|
|
1127
|
+
* @param gclid Google Click Identifier from ad click URLs.
|
|
1128
|
+
*/
|
|
1129
|
+
async setAttributionData(deeplinkId = null, gclid = null) {
|
|
1130
|
+
this._attributionDeeplinkId = deeplinkId;
|
|
1131
|
+
this._attributionGclid = gclid;
|
|
1132
|
+
try {
|
|
1133
|
+
const ctx = { ...this.core.getDeviceContext() };
|
|
1134
|
+
if (deeplinkId) ctx.deeplinkId = deeplinkId;
|
|
1135
|
+
else delete ctx.deeplinkId;
|
|
1136
|
+
this.core.setDeviceContext(ctx);
|
|
1137
|
+
} catch {}
|
|
1138
|
+
try {
|
|
1139
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
1140
|
+
if (AsyncStorage) {
|
|
1141
|
+
if (deeplinkId != null) await AsyncStorage.setItem(LayersReactNative.ATTRIBUTION_DEEPLINK_ID_KEY, deeplinkId);
|
|
1142
|
+
else await AsyncStorage.removeItem(LayersReactNative.ATTRIBUTION_DEEPLINK_ID_KEY);
|
|
1143
|
+
if (gclid != null) await AsyncStorage.setItem(LayersReactNative.ATTRIBUTION_GCLID_KEY, gclid);
|
|
1144
|
+
else await AsyncStorage.removeItem(LayersReactNative.ATTRIBUTION_GCLID_KEY);
|
|
1145
|
+
}
|
|
1146
|
+
} catch {}
|
|
1147
|
+
if (this.enableDebug) console.log(`[Layers] setAttributionData(deeplinkId=${String(deeplinkId)}, gclid=${String(gclid)})`);
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* Merge attribution properties (`gclid`) into the given event properties,
|
|
1151
|
+
* if any attribution data is set. `deeplink_id` flows through DeviceContext
|
|
1152
|
+
* on the Rust core (set via `setAttributionData`), not through properties.
|
|
1153
|
+
*/
|
|
1154
|
+
mergeAttributionProperties(properties) {
|
|
1155
|
+
const gc = this._attributionGclid;
|
|
1156
|
+
if (gc == null) return properties;
|
|
1157
|
+
const merged = { ...properties ?? {} };
|
|
1158
|
+
if (gc != null) merged.gclid = gc;
|
|
1159
|
+
return merged;
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Restore persisted attribution data from AsyncStorage.
|
|
1163
|
+
* Called during initialization to survive app restarts.
|
|
1164
|
+
*/
|
|
1165
|
+
async restoreAttributionData() {
|
|
1166
|
+
try {
|
|
1167
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
1168
|
+
if (!AsyncStorage) return;
|
|
1169
|
+
const [deeplinkId, gclid] = await Promise.all([AsyncStorage.getItem(LayersReactNative.ATTRIBUTION_DEEPLINK_ID_KEY), AsyncStorage.getItem(LayersReactNative.ATTRIBUTION_GCLID_KEY)]);
|
|
1170
|
+
this._attributionDeeplinkId = deeplinkId;
|
|
1171
|
+
this._attributionGclid = gclid;
|
|
1172
|
+
if (deeplinkId != null) try {
|
|
1173
|
+
const currentContext = this.core.getDeviceContext();
|
|
1174
|
+
this.core.setDeviceContext({
|
|
1175
|
+
...currentContext,
|
|
1176
|
+
deeplinkId
|
|
1177
|
+
});
|
|
1178
|
+
} catch {}
|
|
1179
|
+
if (this.enableDebug && (deeplinkId != null || gclid != null)) console.log(`[Layers] Restored attribution data: deeplinkId=${String(deeplinkId)}, gclid=${String(gclid)}`);
|
|
1180
|
+
} catch {}
|
|
1181
|
+
}
|
|
1182
|
+
_trackedDeepLinkUrls = /* @__PURE__ */ new Set();
|
|
1183
|
+
setupDeepLinkAutoTracking() {
|
|
1184
|
+
this.deepLinkUnsubscribe = setupDeepLinkListener((data) => {
|
|
1185
|
+
if (this._trackedDeepLinkUrls.has(data.url)) return;
|
|
1186
|
+
this._trackedDeepLinkUrls.add(data.url);
|
|
1187
|
+
setTimeout(() => this._trackedDeepLinkUrls.delete(data.url), 2e3);
|
|
1188
|
+
try {
|
|
1189
|
+
const properties = {
|
|
1190
|
+
...data.queryParams,
|
|
1191
|
+
url: data.url,
|
|
1192
|
+
scheme: data.scheme,
|
|
1193
|
+
host: data.host,
|
|
1194
|
+
path: data.path
|
|
1195
|
+
};
|
|
1196
|
+
for (const key of [
|
|
1197
|
+
"fbclid",
|
|
1198
|
+
"gclid",
|
|
1199
|
+
"ttclid",
|
|
1200
|
+
"msclkid",
|
|
1201
|
+
"utm_source",
|
|
1202
|
+
"utm_medium",
|
|
1203
|
+
"utm_campaign",
|
|
1204
|
+
"utm_term",
|
|
1205
|
+
"utm_content",
|
|
1206
|
+
"dclid",
|
|
1207
|
+
"li_fat_id",
|
|
1208
|
+
"twclid",
|
|
1209
|
+
"scclid",
|
|
1210
|
+
"irclickid",
|
|
1211
|
+
"af_sub1",
|
|
1212
|
+
"af_sub2",
|
|
1213
|
+
"af_sub3",
|
|
1214
|
+
"af_sub4",
|
|
1215
|
+
"af_sub5"
|
|
1216
|
+
]) if (data.queryParams[key]) properties[key] = data.queryParams[key];
|
|
1217
|
+
const fbclid = data.queryParams.fbclid;
|
|
1218
|
+
const gclid = data.queryParams.gclid;
|
|
1219
|
+
const ttclid = data.queryParams.ttclid;
|
|
1220
|
+
const msclkid = data.queryParams.msclkid;
|
|
1221
|
+
if (fbclid || gclid || ttclid || msclkid) {
|
|
1222
|
+
if (gclid) this.setAttributionData(null, gclid);
|
|
1223
|
+
}
|
|
1224
|
+
this.track("deep_link_opened", properties);
|
|
1225
|
+
if (this.enableDebug) console.log(`[Layers] auto-tracked deep_link_opened: ${data.url}`);
|
|
1226
|
+
} catch (e) {
|
|
1227
|
+
this.emitError(e);
|
|
1228
|
+
}
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
async initializeDeviceInfo() {
|
|
1232
|
+
try {
|
|
1233
|
+
const { Platform, Dimensions, NativeModules } = __require("react-native");
|
|
1234
|
+
const window = Dimensions.get("window");
|
|
1235
|
+
const platform = Platform.OS === "ios" ? "ios" : Platform.OS === "android" ? "android" : "react-native";
|
|
1236
|
+
const osVersion = typeof Platform.Version === "string" ? Platform.Version : String(Platform.Version);
|
|
1237
|
+
let deviceModel;
|
|
1238
|
+
if (Platform.OS === "android") {
|
|
1239
|
+
const brand = Platform.constants?.Brand ?? "";
|
|
1240
|
+
const model = Platform.constants?.Model ?? "";
|
|
1241
|
+
deviceModel = brand && model ? `${brand} ${model}` : model || brand || "Android";
|
|
1242
|
+
} else if (Platform.OS === "ios") try {
|
|
1243
|
+
deviceModel = await NativeModules.LayersDeviceInfo?.getModelIdentifier() || "iPhone";
|
|
1244
|
+
} catch {
|
|
1245
|
+
deviceModel = "iPhone";
|
|
1246
|
+
}
|
|
1247
|
+
else deviceModel = "unknown";
|
|
1248
|
+
let appVersion;
|
|
1249
|
+
try {
|
|
1250
|
+
appVersion = await getAppVersion(Platform, NativeModules);
|
|
1251
|
+
} catch {}
|
|
1252
|
+
const context = {
|
|
1253
|
+
platform,
|
|
1254
|
+
osVersion,
|
|
1255
|
+
deviceModel,
|
|
1256
|
+
locale: getLocale(),
|
|
1257
|
+
screenSize: `${Math.round(window.width)}x${Math.round(window.height)}`,
|
|
1258
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1259
|
+
...appVersion != null && { appVersion }
|
|
1260
|
+
};
|
|
1261
|
+
if (Platform.OS === "ios") try {
|
|
1262
|
+
const idfv = await getVendorId();
|
|
1263
|
+
if (idfv) context.idfv = idfv;
|
|
1264
|
+
} catch {}
|
|
1265
|
+
if (Platform.OS === "android") try {
|
|
1266
|
+
const gaid = await getGoogleAdvertisingId();
|
|
1267
|
+
if (gaid) context.idfa = gaid.id;
|
|
1268
|
+
if (gaid && gaid.isLimitAdTrackingEnabled != null) context.attStatus = gaid.isLimitAdTrackingEnabled ? "denied" : "authorized";
|
|
1269
|
+
} catch {}
|
|
1270
|
+
try {
|
|
1271
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
1272
|
+
if (AsyncStorage) this._hadPriorSdkState = await AsyncStorage.getItem(INSTALL_ID_KEY) != null;
|
|
1273
|
+
} catch {}
|
|
1274
|
+
try {
|
|
1275
|
+
const installId = await getOrSetInstallId();
|
|
1276
|
+
if (installId) context.installId = installId;
|
|
1277
|
+
} catch {}
|
|
1278
|
+
this.core.setDeviceContext(context);
|
|
1279
|
+
} catch {
|
|
1280
|
+
const context = {
|
|
1281
|
+
platform: "react-native",
|
|
1282
|
+
osVersion: "unknown",
|
|
1283
|
+
deviceModel: "unknown",
|
|
1284
|
+
locale: "en-US"
|
|
1285
|
+
};
|
|
1286
|
+
try {
|
|
1287
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
1288
|
+
if (AsyncStorage) this._hadPriorSdkState = await AsyncStorage.getItem(INSTALL_ID_KEY) != null;
|
|
1289
|
+
} catch {}
|
|
1290
|
+
try {
|
|
1291
|
+
const installId = await getOrSetInstallId();
|
|
1292
|
+
if (installId) context.installId = installId;
|
|
1293
|
+
} catch {}
|
|
1294
|
+
this.core.setDeviceContext(context);
|
|
1295
|
+
}
|
|
1296
|
+
try {
|
|
1297
|
+
const { Platform } = __require("react-native");
|
|
1298
|
+
if (Platform.OS === "ios") try {
|
|
1299
|
+
const token = await getAdServicesToken();
|
|
1300
|
+
if (token) this._adServicesToken = token;
|
|
1301
|
+
} catch {}
|
|
1302
|
+
if (Platform.OS === "android") try {
|
|
1303
|
+
const referrer = await getInstallReferrer();
|
|
1304
|
+
if (referrer) this._installReferrer = referrer;
|
|
1305
|
+
} catch {}
|
|
1306
|
+
} catch {}
|
|
1307
|
+
}
|
|
1308
|
+
setupAppStateListener() {
|
|
1309
|
+
try {
|
|
1310
|
+
const { AppState } = __require("react-native");
|
|
1311
|
+
this.appStateSubscription = AppState.addEventListener("change", (nextAppState) => {
|
|
1312
|
+
if (nextAppState === "background" || nextAppState === "inactive") this.core.flush();
|
|
1313
|
+
if (nextAppState === "active" && this.isOnline) this.core.flushAsync().catch(() => {});
|
|
1314
|
+
});
|
|
1315
|
+
} catch {}
|
|
1316
|
+
}
|
|
1317
|
+
async configureSkanFromRemoteConfig() {
|
|
1318
|
+
try {
|
|
1319
|
+
const { Platform } = __require("react-native");
|
|
1320
|
+
if (Platform.OS !== "ios") return;
|
|
1321
|
+
} catch {}
|
|
1322
|
+
try {
|
|
1323
|
+
const configJson = this.core.getRemoteConfigJson?.();
|
|
1324
|
+
if (!configJson) return;
|
|
1325
|
+
const skanConfig = JSON.parse(configJson)?.skan;
|
|
1326
|
+
if (!skanConfig || skanConfig.enabled === false) {
|
|
1327
|
+
this._skanManager = null;
|
|
1328
|
+
this._lastSkanConfigStr = null;
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1331
|
+
const skanConfigStr = JSON.stringify(skanConfig);
|
|
1332
|
+
if (this._skanManager && this._lastSkanConfigStr === skanConfigStr) return;
|
|
1333
|
+
const manager = new SKANManager();
|
|
1334
|
+
if (skanConfig.preset) manager.setPreset(skanConfig.preset);
|
|
1335
|
+
else if (skanConfig.customRules && Array.isArray(skanConfig.customRules)) manager.setCustomRules(skanConfig.customRules);
|
|
1336
|
+
else return;
|
|
1337
|
+
await manager.initialize();
|
|
1338
|
+
this._skanManager = manager;
|
|
1339
|
+
this._lastSkanConfigStr = skanConfigStr;
|
|
1340
|
+
if (this.enableDebug) {
|
|
1341
|
+
const metrics = manager.getMetrics();
|
|
1342
|
+
console.log(`[Layers] SKAN auto-configured from remote config: preset=${metrics.currentPreset}, rules=${String(metrics.ruleCount)}`);
|
|
1343
|
+
}
|
|
1344
|
+
} catch {}
|
|
1345
|
+
}
|
|
1346
|
+
startConfigPolling() {
|
|
1347
|
+
this.stopConfigPolling();
|
|
1348
|
+
this._configPollTimer = setInterval(() => {
|
|
1349
|
+
this.pollRemoteConfig();
|
|
1350
|
+
}, LayersReactNative.CONFIG_POLL_INTERVAL_MS);
|
|
1351
|
+
}
|
|
1352
|
+
stopConfigPolling() {
|
|
1353
|
+
if (this._configPollTimer) {
|
|
1354
|
+
clearInterval(this._configPollTimer);
|
|
1355
|
+
this._configPollTimer = null;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
async pollRemoteConfig() {
|
|
1359
|
+
try {
|
|
1360
|
+
await this.core.fetchRemoteConfig();
|
|
1361
|
+
await this.configureSkanFromRemoteConfig();
|
|
1362
|
+
if (this.enableDebug) console.log("[Layers] Remote config updated (poll)");
|
|
1363
|
+
} catch {}
|
|
1364
|
+
}
|
|
1365
|
+
setupNetInfoListener() {
|
|
1366
|
+
try {
|
|
1367
|
+
this.netInfoUnsubscribe = __require("@react-native-community/netinfo").addEventListener((state) => {
|
|
1368
|
+
const wasOffline = !this.isOnline;
|
|
1369
|
+
this.isOnline = state.isConnected !== false;
|
|
1370
|
+
if (wasOffline && this.isOnline) this.core.flushAsync().catch(() => {});
|
|
1371
|
+
});
|
|
1372
|
+
} catch {}
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
async function createAsyncStoragePersistence(appId) {
|
|
1376
|
+
const prefix = `layers_sdk_${appId}_`;
|
|
1377
|
+
const memoryStore = /* @__PURE__ */ new Map();
|
|
1378
|
+
try {
|
|
1379
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
1380
|
+
if (AsyncStorage) {
|
|
1381
|
+
const layersKeys = (await AsyncStorage.getAllKeys()).filter((k) => k.startsWith(prefix));
|
|
1382
|
+
if (layersKeys.length > 0) {
|
|
1383
|
+
const pairs = await AsyncStorage.multiGet(layersKeys);
|
|
1384
|
+
for (const [key, value] of pairs) if (value) {
|
|
1385
|
+
const shortKey = key.slice(prefix.length);
|
|
1386
|
+
memoryStore.set(shortKey, base64Decode(value));
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
} catch {}
|
|
1391
|
+
return {
|
|
1392
|
+
write(key, data) {
|
|
1393
|
+
memoryStore.set(key, new Uint8Array(data));
|
|
1394
|
+
writeToAsyncStorage(prefix + key, data);
|
|
1395
|
+
},
|
|
1396
|
+
read(key) {
|
|
1397
|
+
return memoryStore.get(key) ?? null;
|
|
1398
|
+
},
|
|
1399
|
+
delete(key) {
|
|
1400
|
+
memoryStore.delete(key);
|
|
1401
|
+
deleteFromAsyncStorage(prefix + key);
|
|
1402
|
+
},
|
|
1403
|
+
listKeys(keyPrefix) {
|
|
1404
|
+
const keys = [];
|
|
1405
|
+
for (const k of memoryStore.keys()) if (k.startsWith(keyPrefix)) keys.push(k);
|
|
1406
|
+
keys.sort();
|
|
1407
|
+
return keys;
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
const B64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
1412
|
+
const B64_LOOKUP = new Uint8Array(128);
|
|
1413
|
+
for (let _i = 0; _i < 64; _i += 1) B64_LOOKUP[B64_CHARS.charCodeAt(_i)] = _i;
|
|
1414
|
+
function base64Decode(str) {
|
|
1415
|
+
const lookup = B64_LOOKUP;
|
|
1416
|
+
let len = str.length;
|
|
1417
|
+
if (str[len - 1] === "=") len -= 1;
|
|
1418
|
+
if (str[len - 1] === "=") len -= 1;
|
|
1419
|
+
const bytes = new Uint8Array(Math.floor(len * 3 / 4));
|
|
1420
|
+
let p = 0;
|
|
1421
|
+
for (let i = 0; i < len; i += 4) {
|
|
1422
|
+
const b0 = lookup[str.charCodeAt(i)];
|
|
1423
|
+
const b1 = lookup[str.charCodeAt(i + 1)];
|
|
1424
|
+
const b2 = i + 2 < len ? lookup[str.charCodeAt(i + 2)] : 0;
|
|
1425
|
+
const b3 = i + 3 < len ? lookup[str.charCodeAt(i + 3)] : 0;
|
|
1426
|
+
bytes[p] = b0 << 2 | b1 >> 4;
|
|
1427
|
+
p += 1;
|
|
1428
|
+
if (i + 2 < len) {
|
|
1429
|
+
bytes[p] = (b1 & 15) << 4 | b2 >> 2;
|
|
1430
|
+
p += 1;
|
|
1431
|
+
}
|
|
1432
|
+
if (i + 3 < len) {
|
|
1433
|
+
bytes[p] = (b2 & 3) << 6 | b3;
|
|
1434
|
+
p += 1;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
return bytes;
|
|
1438
|
+
}
|
|
1439
|
+
function base64Encode(bytes) {
|
|
1440
|
+
let result = "";
|
|
1441
|
+
const len = bytes.length;
|
|
1442
|
+
for (let i = 0; i < len; i += 3) {
|
|
1443
|
+
const b0 = bytes[i];
|
|
1444
|
+
const b1 = i + 1 < len ? bytes[i + 1] : 0;
|
|
1445
|
+
const b2 = i + 2 < len ? bytes[i + 2] : 0;
|
|
1446
|
+
result += B64_CHARS[b0 >> 2];
|
|
1447
|
+
result += B64_CHARS[(b0 & 3) << 4 | b1 >> 4];
|
|
1448
|
+
result += i + 1 < len ? B64_CHARS[(b1 & 15) << 2 | b2 >> 6] : "=";
|
|
1449
|
+
result += i + 2 < len ? B64_CHARS[b2 & 63] : "=";
|
|
1450
|
+
}
|
|
1451
|
+
return result;
|
|
1452
|
+
}
|
|
1453
|
+
async function writeToAsyncStorage(key, data) {
|
|
1454
|
+
try {
|
|
1455
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
1456
|
+
if (!AsyncStorage) return;
|
|
1457
|
+
const encoded = base64Encode(data);
|
|
1458
|
+
await AsyncStorage.setItem(key, encoded);
|
|
1459
|
+
} catch {}
|
|
1460
|
+
}
|
|
1461
|
+
async function deleteFromAsyncStorage(key) {
|
|
1462
|
+
try {
|
|
1463
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
1464
|
+
if (!AsyncStorage) return;
|
|
1465
|
+
await AsyncStorage.removeItem(key);
|
|
1466
|
+
} catch {}
|
|
1467
|
+
}
|
|
1468
|
+
let _asyncStorage = void 0;
|
|
1469
|
+
let _asyncStoragePromise = null;
|
|
1470
|
+
async function loadAsyncStorage() {
|
|
1471
|
+
if (_asyncStorage) return _asyncStorage;
|
|
1472
|
+
if (!_asyncStoragePromise) _asyncStoragePromise = import("@react-native-async-storage/async-storage").then((mod) => {
|
|
1473
|
+
const storage = mod.default ?? mod;
|
|
1474
|
+
if (storage) _asyncStorage = storage;
|
|
1475
|
+
return storage;
|
|
1476
|
+
}).catch(() => null);
|
|
1477
|
+
return _asyncStoragePromise;
|
|
1478
|
+
}
|
|
1479
|
+
function getLocale() {
|
|
1480
|
+
try {
|
|
1481
|
+
const { Platform, NativeModules } = __require("react-native");
|
|
1482
|
+
if (Platform.OS === "ios") return NativeModules.SettingsManager?.settings?.AppleLocale ?? NativeModules.SettingsManager?.settings?.AppleLanguages?.[0] ?? "en-US";
|
|
1483
|
+
if (Platform.OS === "android") return NativeModules.I18nManager?.localeIdentifier ?? "en-US";
|
|
1484
|
+
} catch {}
|
|
1485
|
+
return "en-US";
|
|
1486
|
+
}
|
|
1487
|
+
const INSTALL_ID_KEY = "layers_install_id";
|
|
1488
|
+
const FIRST_LAUNCH_TRACKED_KEY = "@layers/first_launch_tracked";
|
|
1489
|
+
/**
|
|
1490
|
+
* Maximum age of an app installation (in milliseconds) for which the SDK
|
|
1491
|
+
* will consider the first launch as a genuine new install. If the app was
|
|
1492
|
+
* installed more than 24 hours ago AND no prior Layers SDK state exists,
|
|
1493
|
+
* the SDK treats this as an existing app that just added the SDK — not a
|
|
1494
|
+
* new install — and suppresses `is_first_launch = true`.
|
|
1495
|
+
*/
|
|
1496
|
+
const INSTALL_EVENT_MAX_DIFF_MS = 1440 * 60 * 1e3;
|
|
1497
|
+
async function getOrSetInstallId() {
|
|
1498
|
+
try {
|
|
1499
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
1500
|
+
if (!AsyncStorage) return generateUUID();
|
|
1501
|
+
const existing = await AsyncStorage.getItem(INSTALL_ID_KEY);
|
|
1502
|
+
if (existing) return existing;
|
|
1503
|
+
const newId = generateUUID();
|
|
1504
|
+
await AsyncStorage.setItem(INSTALL_ID_KEY, newId);
|
|
1505
|
+
return newId;
|
|
1506
|
+
} catch {
|
|
1507
|
+
return generateUUID();
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
function generateUUID() {
|
|
1511
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) return crypto.randomUUID();
|
|
1512
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
1513
|
+
const r = Math.random() * 16 | 0;
|
|
1514
|
+
return (c === "x" ? r : r & 3 | 8).toString(16);
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Read the app's first install time from the native module.
|
|
1519
|
+
* Returns milliseconds since epoch, or null if not available.
|
|
1520
|
+
*
|
|
1521
|
+
* - Android: reads PackageInfo.firstInstallTime via PackageManager
|
|
1522
|
+
* - iOS: reads the Documents directory creation date as a proxy
|
|
1523
|
+
*/
|
|
1524
|
+
async function getFirstInstallTime() {
|
|
1525
|
+
try {
|
|
1526
|
+
const { NativeModules } = __require("react-native");
|
|
1527
|
+
const mod = NativeModules.LayersDeviceInfo;
|
|
1528
|
+
if (!mod?.getFirstInstallTime) return null;
|
|
1529
|
+
const time = await mod.getFirstInstallTime();
|
|
1530
|
+
return time != null && Number.isFinite(time) ? time : null;
|
|
1531
|
+
} catch {
|
|
1532
|
+
return null;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
/**
|
|
1536
|
+
* Determine whether this is a genuine new install or an existing app that
|
|
1537
|
+
* just added the Layers SDK.
|
|
1538
|
+
*
|
|
1539
|
+
* This is a pure function that takes pre-resolved inputs — the caller is
|
|
1540
|
+
* responsible for reading and persisting the `FIRST_LAUNCH_TRACKED_KEY`
|
|
1541
|
+
* flag in AsyncStorage. This mirrors the Android/Swift implementations
|
|
1542
|
+
* where the caller manages persistence.
|
|
1543
|
+
*
|
|
1544
|
+
* Logic (mirrors Android's `shouldTreatAsNewInstall`):
|
|
1545
|
+
* 1. If `isFirstLaunchByFlag` is `false` (flag already tracked), return `false`.
|
|
1546
|
+
* 2. If the SDK had prior state (`install_id` already existed in
|
|
1547
|
+
* AsyncStorage), trust the flag — this is a returning user whose
|
|
1548
|
+
* first-launch flag was not yet written (e.g. upgrade from an older
|
|
1549
|
+
* SDK version). Return `true`.
|
|
1550
|
+
* 3. If the SDK had NO prior state AND the app was installed more than
|
|
1551
|
+
* 24 hours ago, this is an existing app getting the SDK for the first
|
|
1552
|
+
* time — suppress `is_first_launch`. Return `false`.
|
|
1553
|
+
* 4. If the SDK had no prior state AND the app was installed within 24
|
|
1554
|
+
* hours, this is a genuine new install — allow `is_first_launch`.
|
|
1555
|
+
* Return `true`.
|
|
1556
|
+
*
|
|
1557
|
+
* @param isFirstLaunchByFlag Whether the first_launch flag has NOT been set yet (true = not yet tracked).
|
|
1558
|
+
* @param hadPriorSdkState Whether `install_id` already existed before init.
|
|
1559
|
+
* @param enableDebug Whether to log debug info.
|
|
1560
|
+
*/
|
|
1561
|
+
async function shouldTreatAsNewInstall(isFirstLaunchByFlag, hadPriorSdkState, enableDebug = false, _getInstallTime = getFirstInstallTime) {
|
|
1562
|
+
if (!isFirstLaunchByFlag) return false;
|
|
1563
|
+
if (hadPriorSdkState) return true;
|
|
1564
|
+
try {
|
|
1565
|
+
const firstInstallTime = await _getInstallTime();
|
|
1566
|
+
if (firstInstallTime != null) {
|
|
1567
|
+
const elapsed = Date.now() - firstInstallTime;
|
|
1568
|
+
const isRecentInstall = elapsed <= INSTALL_EVENT_MAX_DIFF_MS;
|
|
1569
|
+
if (!isRecentInstall && enableDebug) console.log(`[Layers] Install event gated: app installed ${Math.round(elapsed / 1e3)}s ago (threshold=${INSTALL_EVENT_MAX_DIFF_MS / 1e3}s), no prior SDK state — suppressing is_first_launch`);
|
|
1570
|
+
return isRecentInstall;
|
|
1571
|
+
}
|
|
1572
|
+
} catch {}
|
|
1573
|
+
return true;
|
|
1574
|
+
}
|
|
1575
|
+
const CLIPBOARD_CHECKED_KEY = "@layers/clipboard_checked";
|
|
1576
|
+
async function readClipboardAttribution() {
|
|
1577
|
+
try {
|
|
1578
|
+
const { Platform } = __require("react-native");
|
|
1579
|
+
if (Platform.OS !== "ios") return null;
|
|
1580
|
+
} catch {
|
|
1581
|
+
return null;
|
|
1582
|
+
}
|
|
1583
|
+
try {
|
|
1584
|
+
const AS = await loadAsyncStorage();
|
|
1585
|
+
if (AS) {
|
|
1586
|
+
if (await AS.getItem(CLIPBOARD_CHECKED_KEY) === "true") return null;
|
|
1587
|
+
}
|
|
1588
|
+
} catch {}
|
|
1589
|
+
let text = null;
|
|
1590
|
+
try {
|
|
1591
|
+
const Clipboard = await import("@react-native-clipboard/clipboard").then((m) => m.default).catch(() => null);
|
|
1592
|
+
if (Clipboard) text = await Clipboard.getString();
|
|
1593
|
+
else {
|
|
1594
|
+
const { Clipboard: RNClipboard } = __require("react-native");
|
|
1595
|
+
if (RNClipboard) text = await RNClipboard.getString();
|
|
1596
|
+
}
|
|
1597
|
+
} catch {}
|
|
1598
|
+
try {
|
|
1599
|
+
const AS = await loadAsyncStorage();
|
|
1600
|
+
if (AS) await AS.setItem(CLIPBOARD_CHECKED_KEY, "true");
|
|
1601
|
+
} catch {}
|
|
1602
|
+
if (!text) return null;
|
|
1603
|
+
const match = text.match(/https?:\/\/(in\.layers\.com|link\.layers\.com)\/c\/([^?\s]+)/);
|
|
1604
|
+
if (!match) return null;
|
|
1605
|
+
return {
|
|
1606
|
+
clickUrl: text,
|
|
1607
|
+
clickId: match[2]
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Attempt to read the host app version from platform-specific APIs.
|
|
1612
|
+
* On Android, reads from PackageInfo via Platform.constants or a native module.
|
|
1613
|
+
* On iOS, reads from the LayersDeviceInfo native module which can access the Info.plist.
|
|
1614
|
+
*/
|
|
1615
|
+
async function getAppVersion(Platform, NativeModules) {
|
|
1616
|
+
try {
|
|
1617
|
+
if (Platform.OS === "android") {
|
|
1618
|
+
const mod = NativeModules.LayersDeviceInfo;
|
|
1619
|
+
if (mod?.getAppVersion) {
|
|
1620
|
+
const version = await mod.getAppVersion();
|
|
1621
|
+
if (version) return version;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
if (Platform.OS === "ios") {
|
|
1625
|
+
const mod = NativeModules.LayersDeviceInfo;
|
|
1626
|
+
if (mod?.getAppVersion) {
|
|
1627
|
+
const version = await mod.getAppVersion();
|
|
1628
|
+
if (version) return version;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
} catch {}
|
|
1632
|
+
}
|
|
1633
|
+
/**
|
|
1634
|
+
* Fetch the Google Advertising ID (GAID) on Android via NativeModules.
|
|
1635
|
+
* Returns null on iOS or when the native module is not available.
|
|
1636
|
+
*/
|
|
1637
|
+
async function getGoogleAdvertisingId() {
|
|
1638
|
+
try {
|
|
1639
|
+
const { NativeModules, Platform } = __require("react-native");
|
|
1640
|
+
if (Platform.OS !== "android") return null;
|
|
1641
|
+
const mod = NativeModules.LayersAdvertisingId;
|
|
1642
|
+
if (!mod?.getAdvertisingInfo) return null;
|
|
1643
|
+
const info = await mod.getAdvertisingInfo();
|
|
1644
|
+
if (!info || !info.id || info.id === "00000000-0000-0000-0000-000000000000") return null;
|
|
1645
|
+
return info;
|
|
1646
|
+
} catch {
|
|
1647
|
+
return null;
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Request the AdServices attribution token on iOS 14.3+.
|
|
1652
|
+
* Uses the LayersAdServices native module which calls AAAttribution.attributionToken().
|
|
1653
|
+
* Does NOT require ATT consent.
|
|
1654
|
+
* Returns null on Android or when the native module is not available.
|
|
1655
|
+
*/
|
|
1656
|
+
async function getAdServicesToken() {
|
|
1657
|
+
try {
|
|
1658
|
+
const { NativeModules, Platform } = __require("react-native");
|
|
1659
|
+
if (Platform.OS !== "ios") return null;
|
|
1660
|
+
const mod = NativeModules.LayersAdServices;
|
|
1661
|
+
if (!mod?.getAttributionToken) return null;
|
|
1662
|
+
return await mod.getAttributionToken();
|
|
1663
|
+
} catch {
|
|
1664
|
+
return null;
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* Fetch the Google Play install referrer on Android via NativeModules.
|
|
1669
|
+
* Requires the `com.android.installreferrer` library on the native side.
|
|
1670
|
+
* Returns null on iOS or when the native module is not available.
|
|
1671
|
+
*/
|
|
1672
|
+
async function getInstallReferrer() {
|
|
1673
|
+
try {
|
|
1674
|
+
const { NativeModules, Platform } = __require("react-native");
|
|
1675
|
+
if (Platform.OS !== "android") return null;
|
|
1676
|
+
const mod = NativeModules.LayersInstallReferrer;
|
|
1677
|
+
if (!mod?.getInstallReferrer) return null;
|
|
1678
|
+
const data = await mod.getInstallReferrer();
|
|
1679
|
+
if (!data || !data.referrerUrl) return null;
|
|
1680
|
+
return data;
|
|
1681
|
+
} catch {
|
|
1682
|
+
return null;
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
function setupDeepLinkListener(onDeepLink) {
|
|
1686
|
+
try {
|
|
1687
|
+
const { Linking } = __require("react-native");
|
|
1688
|
+
const handler = (event) => {
|
|
1689
|
+
const parsed = parseDeepLink(event.url);
|
|
1690
|
+
if (parsed) onDeepLink(parsed);
|
|
1691
|
+
};
|
|
1692
|
+
const subscription = Linking.addEventListener("url", handler);
|
|
1693
|
+
Linking.getInitialURL().then((url) => {
|
|
1694
|
+
if (url) {
|
|
1695
|
+
const parsed = parseDeepLink(url);
|
|
1696
|
+
if (parsed) onDeepLink(parsed);
|
|
1697
|
+
}
|
|
1698
|
+
});
|
|
1699
|
+
return () => {
|
|
1700
|
+
if (subscription?.remove) subscription.remove();
|
|
1701
|
+
};
|
|
1702
|
+
} catch {
|
|
1703
|
+
return () => {};
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
function parseDeepLink(url) {
|
|
1707
|
+
try {
|
|
1708
|
+
const parsed = new URL(url);
|
|
1709
|
+
const params = {};
|
|
1710
|
+
parsed.searchParams.forEach((value, key) => {
|
|
1711
|
+
params[key] = value;
|
|
1712
|
+
});
|
|
1713
|
+
return {
|
|
1714
|
+
url,
|
|
1715
|
+
scheme: parsed.protocol.replace(":", ""),
|
|
1716
|
+
host: parsed.hostname,
|
|
1717
|
+
path: parsed.pathname,
|
|
1718
|
+
queryParams: params,
|
|
1719
|
+
timestamp: Date.now()
|
|
1720
|
+
};
|
|
1721
|
+
} catch {
|
|
1722
|
+
return null;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
function useLayersExpoRouterTracking(layersInstance, usePathname, useGlobalSearchParams) {
|
|
1726
|
+
const { useEffect } = __require("react");
|
|
1727
|
+
const pathname = usePathname();
|
|
1728
|
+
const params = useGlobalSearchParams();
|
|
1729
|
+
useEffect(() => {
|
|
1730
|
+
if (pathname) {
|
|
1731
|
+
const properties = {};
|
|
1732
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
1733
|
+
properties[key] = Array.isArray(value) ? value.join(",") : value;
|
|
1734
|
+
});
|
|
1735
|
+
layersInstance.screen(pathname, properties);
|
|
1736
|
+
}
|
|
1737
|
+
}, [pathname, JSON.stringify(params)]);
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
//#endregion
|
|
1741
|
+
export { viewContentEvent as $, trackViewProduct as A, initiateCheckoutEvent as B, trackBeginCheckout as C, trackRefund as D, trackPurchaseFailed as E, superwallTrackSkip as F, registerEvent as G, levelStartEvent as H, superwallUserAttributes as I, shareEvent as J, screenViewEvent as K, StandardEvents as L, superwallTrackDismiss as M, superwallTrackPresentation as N, trackRemoveFromCart as O, superwallTrackPurchase as P, tutorialCompleteEvent as Q, addToCartEvent as R, trackAddToCart as S, trackPurchase as T, loginEvent as U, levelCompleteEvent as V, purchaseEvent as W, startTrialEvent as X, signUpEvent as Y, subscribeEvent as Z, connectRevenueCat as _, getGoogleAdvertisingId as a, syncRevenueCatAttributes as b, parseDeepLink as c, shouldTreatAsNewInstall as d, viewItemEvent as et, useLayersExpoRouterTracking as f, registerExpoBackgroundFlush as g, createBackgroundFlushHandler as h, getFirstInstallTime as i, superwallOnEvent as j, trackSubscription as k, readClipboardAttribution as l, BACKGROUND_FLUSH_TASK_NAME as m, LayersReactNative as n, getInstallReferrer as o, BACKGROUND_FLUSH_MIN_INTERVAL_MINUTES as p, searchEvent as q, getAdServicesToken as r, getOrSetInstallId as s, LayersError$1 as t, setupDeepLinkListener as u, isRevenueCatConnected as v, trackOrder as w, trackRevenueCatPurchase as x, resetRevenueCatForTesting as y, addToWishlistEvent as z };
|
|
1742
|
+
//# sourceMappingURL=src-CT0RgNql.mjs.map
|