@layers/react-native 3.2.5 → 3.2.7
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/LICENSE +21 -0
- package/README.md +58 -12
- package/dist/att-BFy6dcWE.d.ts.map +1 -1
- package/dist/debug-overlay.d.mts +1 -1
- package/dist/debug-overlay.d.ts +1 -1
- package/dist/{index-D6lBf0N_.d.ts → index-BNM5Q_2v.d.ts} +132 -3
- package/dist/{index-D6lBf0N_.d.ts.map → index-BNM5Q_2v.d.ts.map} +1 -1
- package/dist/{index-NfkxionM.d.mts → index-BaCWtOOT.d.mts} +132 -3
- package/dist/{index-NfkxionM.d.mts.map → index-BaCWtOOT.d.mts.map} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/react.d.mts +2 -2
- package/dist/react.d.mts.map +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +3 -4
- package/dist/react.mjs +3 -4
- package/dist/react.mjs.map +1 -1
- package/dist/{skan-CYTZtEAI.mjs → skan-B0F6AX7g.mjs} +3 -3
- package/dist/skan-B0F6AX7g.mjs.map +1 -0
- package/dist/{skan-D0DUw-6o.js → skan-BRhw9sPC.js} +2 -2
- package/dist/skan-BljOFaeU.d.mts.map +1 -1
- package/dist/skan-DnKHcXAj.d.ts.map +1 -1
- package/dist/skan.js +1 -1
- package/dist/skan.mjs +1 -1
- package/dist/{src-CiemkTIn.mjs → src-A7xqoTvD.mjs} +355 -29
- package/dist/src-A7xqoTvD.mjs.map +1 -0
- package/dist/{src-DvRveiFz.js → src-DkJclY0S.js} +354 -28
- package/package.json +3 -2
- package/dist/skan-CYTZtEAI.mjs.map +0 -1
- package/dist/src-CiemkTIn.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __require } from "./chunk-COTuXS2J.mjs";
|
|
2
2
|
import { a as requestTrackingAuthorization, n as getAdvertisingId, r as getVendorId } from "./att-CnlG_CuV.mjs";
|
|
3
|
-
import { r as setSkanCore, t as SKANManager } from "./skan-
|
|
3
|
+
import { r as setSkanCore, t as SKANManager } from "./skan-B0F6AX7g.mjs";
|
|
4
4
|
import { FetchHttpClient, LayersCore, LayersError as LayersError$1, LayersEvent, MemoryPersistence, addToCartEvent as buildAddToCartEvent, beginCheckoutEvent as buildBeginCheckoutEvent, initWasm, purchaseEvent as buildPurchaseEvent, refundEvent as buildRefundEvent, startTrialEvent as buildStartTrialEvent, subscribeEvent as buildSubscribeEvent, viewItemEvent as buildViewItemEvent } from "@layers/core-wasm";
|
|
5
5
|
|
|
6
6
|
//#region src/standard-events.ts
|
|
@@ -909,7 +909,34 @@ var SurveysModule = class {
|
|
|
909
909
|
|
|
910
910
|
//#endregion
|
|
911
911
|
//#region src/index.ts
|
|
912
|
-
|
|
912
|
+
/**
|
|
913
|
+
* The surface `AppRegistry.js` registers at module scope in EVERY copy of
|
|
914
|
+
* react-native, duplicate or not, so it proves nothing on its own.
|
|
915
|
+
*/
|
|
916
|
+
const LOGBOX_SURFACE_KEY = "LogBox";
|
|
917
|
+
/**
|
|
918
|
+
* Is this the copy of react-native the host app actually runs?
|
|
919
|
+
*
|
|
920
|
+
* `AppRegistry.registerComponent` is called by the app's entry file, so the
|
|
921
|
+
* live copy carries the app's own surface key alongside LogBox. A copy that
|
|
922
|
+
* only the SDK imported was never handed an application and carries LogBox
|
|
923
|
+
* alone.
|
|
924
|
+
*
|
|
925
|
+
* Returns `null` when the question cannot be answered (no AppRegistry, a
|
|
926
|
+
* shape we don't recognise). Callers must stay silent on `null` — inventing a
|
|
927
|
+
* diagnosis from missing evidence is worse than the silence this replaces.
|
|
928
|
+
*/
|
|
929
|
+
function hostAppIsRegisteredOn(rn) {
|
|
930
|
+
try {
|
|
931
|
+
const keys = rn?.AppRegistry?.getAppKeys?.();
|
|
932
|
+
if (!Array.isArray(keys)) return null;
|
|
933
|
+
return keys.some((key) => typeof key === "string" && key !== LOGBOX_SURFACE_KEY);
|
|
934
|
+
} catch {
|
|
935
|
+
return null;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
const DUPLICATE_REACT_NATIVE_MESSAGE = "[Layers] The SDK resolved a SECOND copy of react-native, not the one your app runs. React Native delivers native lifecycle events to a single copy, so this listener can never fire: $app_background and $app_foreground will not be emitted and the background crash-safety snapshot will not run, which loses every event queued since the last flush on any launch that ends in a kill. Fix the duplicate in your bundler — in a Metro monorepo set `resolver.disableHierarchicalLookup = true` and list every workspace node_modules in `resolver.nodeModulesPaths` — or hand the SDK your app's module: `new LayersReactNative({ ..., appState: AppState })` with AppState imported from 'react-native'.";
|
|
939
|
+
const SDK_VERSION = "3.2.7";
|
|
913
940
|
var LayersReactNative = class LayersReactNative {
|
|
914
941
|
core;
|
|
915
942
|
eagerPersistence;
|
|
@@ -917,6 +944,7 @@ var LayersReactNative = class LayersReactNative {
|
|
|
917
944
|
isOnline = true;
|
|
918
945
|
enableDebug;
|
|
919
946
|
appStateSubscription = null;
|
|
947
|
+
_lifecycleCheckTimer = null;
|
|
920
948
|
netInfoUnsubscribe = null;
|
|
921
949
|
config;
|
|
922
950
|
userIdLocked = false;
|
|
@@ -927,6 +955,9 @@ var LayersReactNative = class LayersReactNative {
|
|
|
927
955
|
static MAX_RECENT_EVENTS = 20;
|
|
928
956
|
_recentEvents = [];
|
|
929
957
|
_isInitialized = false;
|
|
958
|
+
_initPromise = null;
|
|
959
|
+
_initGeneration = 0;
|
|
960
|
+
_runtimeGeneration = 0;
|
|
930
961
|
_configPollTimer = null;
|
|
931
962
|
static CONFIG_POLL_INTERVAL_MS = 3e5;
|
|
932
963
|
_adServicesToken = null;
|
|
@@ -968,16 +999,136 @@ var LayersReactNative = class LayersReactNative {
|
|
|
968
999
|
persistence: this.eagerPersistence
|
|
969
1000
|
});
|
|
970
1001
|
setSkanCore(this.core);
|
|
1002
|
+
this.applyEagerDeviceContext();
|
|
971
1003
|
if (this.appUserId) {
|
|
972
1004
|
this.core.identify(this.appUserId);
|
|
973
1005
|
this.userIdLocked = true;
|
|
974
1006
|
}
|
|
975
1007
|
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Best-effort device context available at construction time — no `await`,
|
|
1010
|
+
* so it can run in the constructor before any pre-init event is tracked.
|
|
1011
|
+
* Only the synchronously readable fields; the rest arrive with
|
|
1012
|
+
* initializeDeviceInfo().
|
|
1013
|
+
*/
|
|
1014
|
+
applyEagerDeviceContext() {
|
|
1015
|
+
const context = {
|
|
1016
|
+
platform: "react-native",
|
|
1017
|
+
osVersion: "unknown",
|
|
1018
|
+
deviceModel: "unknown",
|
|
1019
|
+
locale: "en-US"
|
|
1020
|
+
};
|
|
1021
|
+
try {
|
|
1022
|
+
const { Platform, Dimensions } = __require("react-native");
|
|
1023
|
+
context.platform = Platform.OS === "ios" ? "ios" : Platform.OS === "android" ? "android" : "react-native";
|
|
1024
|
+
context.osVersion = typeof Platform.Version === "string" ? Platform.Version : String(Platform.Version);
|
|
1025
|
+
context.locale = getLocale();
|
|
1026
|
+
if (Platform.OS === "android") {
|
|
1027
|
+
const brand = Platform.constants?.Brand ?? "";
|
|
1028
|
+
const model = Platform.constants?.Model ?? "";
|
|
1029
|
+
const deviceModel = brand && model ? `${brand} ${model}` : model || brand;
|
|
1030
|
+
if (deviceModel) context.deviceModel = deviceModel;
|
|
1031
|
+
}
|
|
1032
|
+
try {
|
|
1033
|
+
const window = Dimensions.get("window");
|
|
1034
|
+
context.screenSize = `${Math.round(window.width)}x${Math.round(window.height)}`;
|
|
1035
|
+
} catch {}
|
|
1036
|
+
try {
|
|
1037
|
+
context.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1038
|
+
} catch {}
|
|
1039
|
+
} catch {}
|
|
1040
|
+
try {
|
|
1041
|
+
this.core.setDeviceContext(context);
|
|
1042
|
+
} catch {}
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* The platform this instance runs on: 'ios' | 'android' | 'react-native'.
|
|
1046
|
+
* Reads the device context the constructor stamped (applyEagerDeviceContext)
|
|
1047
|
+
* and falls back to a direct `Platform.OS` read, so it answers correctly
|
|
1048
|
+
* before init() has completed.
|
|
1049
|
+
*/
|
|
1050
|
+
currentPlatform() {
|
|
1051
|
+
try {
|
|
1052
|
+
const platform = this.core.getDeviceContext().platform;
|
|
1053
|
+
if (platform) return platform;
|
|
1054
|
+
} catch {}
|
|
1055
|
+
try {
|
|
1056
|
+
const { Platform } = __require("react-native");
|
|
1057
|
+
return String(Platform.OS);
|
|
1058
|
+
} catch {
|
|
1059
|
+
return "react-native";
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Initialize the SDK. Idempotent: concurrent calls await the same in-flight
|
|
1064
|
+
* run, and a completed init() returns immediately. shutdown() releases the
|
|
1065
|
+
* latch, so shutdown() → init() re-initializes.
|
|
1066
|
+
*/
|
|
976
1067
|
async init() {
|
|
1068
|
+
if (this._initPromise) return this._initPromise;
|
|
1069
|
+
const promise = this.runInit(this._initGeneration);
|
|
1070
|
+
this._initPromise = promise;
|
|
1071
|
+
try {
|
|
1072
|
+
await promise;
|
|
1073
|
+
} catch (e) {
|
|
1074
|
+
if (this._initPromise === promise) this._initPromise = null;
|
|
1075
|
+
throw e;
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* True when a shutdown() landed after this init() run started. The caller
|
|
1080
|
+
* must return immediately.
|
|
1081
|
+
*
|
|
1082
|
+
* Without this gate init() ran to completion on an abandoned instance: it
|
|
1083
|
+
* built a second live core (the AsyncStorage rebuild below), installed the
|
|
1084
|
+
* AppState/NetInfo/deep-link listeners and the 300s config-poll timer on it,
|
|
1085
|
+
* and tracked a duplicate `app_open` — one orphaned SDK, with its own
|
|
1086
|
+
* timers, per remount. React 18 StrictMode mounts → unmounts → remounts
|
|
1087
|
+
* every effect, so the Expo `LayersProvider` (which calls shutdown() in
|
|
1088
|
+
* cleanup while init() is still awaiting) hit this on every dev launch.
|
|
1089
|
+
*
|
|
1090
|
+
* **This check has no side effects, deliberately.** It used to tear the
|
|
1091
|
+
* runtime down on any generation mismatch, which is wrong the moment two
|
|
1092
|
+
* runs overlap: init A → shutdown → init B completes → A finally reaches a
|
|
1093
|
+
* checkpoint and demolishes *B's* listeners, core and timer, leaving an SDK
|
|
1094
|
+
* that reported `isInitialized === true` and delivered nothing. Cleanup
|
|
1095
|
+
* belongs to shutdown() (which owns everything installed at the moment it
|
|
1096
|
+
* runs) and to {@link abandonRun} (which proves ownership by generation
|
|
1097
|
+
* first).
|
|
1098
|
+
*/
|
|
1099
|
+
isRunAbandoned(generation) {
|
|
1100
|
+
return generation !== this._initGeneration;
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* Abandon this run and release only the resources it installed itself.
|
|
1104
|
+
*
|
|
1105
|
+
* Every install site below is *synchronously* adjacent to its preceding
|
|
1106
|
+
* checkpoint — no `await` sits between "still current?" and the assignment —
|
|
1107
|
+
* so a shutdown() can never slip in between the two, and anything this run
|
|
1108
|
+
* did install was already torn down by that shutdown(). The ownership check
|
|
1109
|
+
* is what keeps that true if a future edit ever puts an await in between:
|
|
1110
|
+
* the run cleans up only while it is still the runtime's owner.
|
|
1111
|
+
*/
|
|
1112
|
+
abandonRun(generation) {
|
|
1113
|
+
if (this._runtimeGeneration !== generation) return;
|
|
1114
|
+
this.teardownRuntime();
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Checkpoint used at every await boundary in runInit(): report whether this
|
|
1118
|
+
* run has been abandoned and, if so, release only what it still owns.
|
|
1119
|
+
*/
|
|
1120
|
+
initAborted(generation) {
|
|
1121
|
+
if (!this.isRunAbandoned(generation)) return false;
|
|
1122
|
+
this.abandonRun(generation);
|
|
1123
|
+
return true;
|
|
1124
|
+
}
|
|
1125
|
+
async runInit(generation) {
|
|
977
1126
|
const initStartTime = Date.now();
|
|
978
1127
|
if (typeof WebAssembly !== "undefined") await initWasm();
|
|
1128
|
+
if (this.initAborted(generation)) return;
|
|
979
1129
|
try {
|
|
980
1130
|
const persistence = await createAsyncStoragePersistence(this.config.appId);
|
|
1131
|
+
if (this.initAborted(generation)) return;
|
|
981
1132
|
const httpClient = new FetchHttpClient();
|
|
982
1133
|
const migrationState = this.core.exportMigrationState();
|
|
983
1134
|
this.core.shutdown();
|
|
@@ -1009,16 +1160,20 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1009
1160
|
persistence
|
|
1010
1161
|
});
|
|
1011
1162
|
this.core.applyMigrationState(migrationState);
|
|
1163
|
+
this._runtimeGeneration = generation;
|
|
1012
1164
|
setSkanCore(this.core);
|
|
1013
1165
|
if (this.appUserId) this.core.identify(this.appUserId);
|
|
1014
1166
|
} catch {}
|
|
1015
1167
|
await this.restoreAttributionData();
|
|
1016
1168
|
await this.initializeDeviceInfo();
|
|
1169
|
+
if (this.initAborted(generation)) return;
|
|
1170
|
+
this._runtimeGeneration = generation;
|
|
1017
1171
|
this.setupAppStateListener();
|
|
1018
1172
|
this.setupNetInfoListener();
|
|
1019
1173
|
const mainThreadDurationMs = Date.now() - initStartTime;
|
|
1020
1174
|
await this.core.fetchRemoteConfig().catch(() => {});
|
|
1021
1175
|
await this.configureSkanFromRemoteConfig();
|
|
1176
|
+
if (this.initAborted(generation)) return;
|
|
1022
1177
|
this.startConfigPolling();
|
|
1023
1178
|
let clipboardData = null;
|
|
1024
1179
|
try {
|
|
@@ -1032,13 +1187,28 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1032
1187
|
if (clipboardEnabled) clipboardData = await readClipboardAttribution();
|
|
1033
1188
|
}
|
|
1034
1189
|
} catch {}
|
|
1190
|
+
if (this.initAborted(generation)) return;
|
|
1035
1191
|
if (this.config.autoTrackAppOpen !== false) {
|
|
1036
1192
|
const appOpenProps = {};
|
|
1037
1193
|
let isFirstLaunchByFlag = true;
|
|
1038
1194
|
try {
|
|
1039
1195
|
const AsyncStorage = await loadAsyncStorage();
|
|
1040
1196
|
if (AsyncStorage) {
|
|
1041
|
-
|
|
1197
|
+
const scopedKey = firstLaunchTrackedKey(this.config.appId);
|
|
1198
|
+
let flag = await AsyncStorage.getItem(scopedKey);
|
|
1199
|
+
let adoptLegacy = false;
|
|
1200
|
+
if (flag === null) {
|
|
1201
|
+
const legacy = await AsyncStorage.getItem(FIRST_LAUNCH_TRACKED_KEY_LEGACY);
|
|
1202
|
+
if (legacy === "true") {
|
|
1203
|
+
flag = legacy;
|
|
1204
|
+
adoptLegacy = true;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
if (flag === "true") isFirstLaunchByFlag = false;
|
|
1208
|
+
if (adoptLegacy) try {
|
|
1209
|
+
await AsyncStorage.setItem(scopedKey, "true");
|
|
1210
|
+
await AsyncStorage.removeItem(FIRST_LAUNCH_TRACKED_KEY_LEGACY);
|
|
1211
|
+
} catch {}
|
|
1042
1212
|
}
|
|
1043
1213
|
} catch {}
|
|
1044
1214
|
const isFirstLaunch = await shouldTreatAsNewInstall(isFirstLaunchByFlag, this._hadPriorSdkState, this.enableDebug);
|
|
@@ -1047,10 +1217,6 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1047
1217
|
if (isFirstLaunch && !hasAttribution) try {
|
|
1048
1218
|
await this.resolveClickFromFingerprint();
|
|
1049
1219
|
} catch {}
|
|
1050
|
-
if (isFirstLaunch) try {
|
|
1051
|
-
const AsyncStorage = await loadAsyncStorage();
|
|
1052
|
-
if (AsyncStorage) await AsyncStorage.setItem(FIRST_LAUNCH_TRACKED_KEY, "true");
|
|
1053
|
-
} catch {}
|
|
1054
1220
|
if (clipboardData) {
|
|
1055
1221
|
appOpenProps.clipboard_attribution_url = clipboardData.clickUrl;
|
|
1056
1222
|
appOpenProps.clipboard_click_id = clipboardData.clickId;
|
|
@@ -1064,8 +1230,13 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1064
1230
|
if (this._installReferrerParams) {
|
|
1065
1231
|
for (const [key, value] of Object.entries(this._installReferrerParams)) if (appOpenProps[key] === void 0) appOpenProps[key] = value;
|
|
1066
1232
|
}
|
|
1233
|
+
if (this.initAborted(generation)) return;
|
|
1067
1234
|
if (isFirstLaunch) this.track("app_install", appOpenProps);
|
|
1068
1235
|
this.track("app_open", appOpenProps);
|
|
1236
|
+
if (isFirstLaunch) try {
|
|
1237
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
1238
|
+
if (AsyncStorage) await AsyncStorage.setItem(firstLaunchTrackedKey(this.config.appId), "true");
|
|
1239
|
+
} catch {}
|
|
1069
1240
|
if (this.config.autoTrackAppUpdate !== false) try {
|
|
1070
1241
|
const currentVersion = this.core.getDeviceContext().appVersion ?? appOpenProps.app_version;
|
|
1071
1242
|
if (currentVersion && typeof currentVersion === "string") {
|
|
@@ -1081,6 +1252,7 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1081
1252
|
}
|
|
1082
1253
|
} catch {}
|
|
1083
1254
|
}
|
|
1255
|
+
if (this.initAborted(generation)) return;
|
|
1084
1256
|
if (this.config.autoTrackDeepLinks !== false) this.setupDeepLinkAutoTracking();
|
|
1085
1257
|
this._isInitialized = true;
|
|
1086
1258
|
const totalDurationMs = Date.now() - initStartTime;
|
|
@@ -1331,6 +1503,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1331
1503
|
* Returns the ATT status string.
|
|
1332
1504
|
*/
|
|
1333
1505
|
async requestTrackingPermission() {
|
|
1506
|
+
if (this.currentPlatform() === "android") {
|
|
1507
|
+
if (this.enableDebug) console.log("[Layers] requestTrackingPermission() is a no-op on Android — ATT is iOS-only; consent left untouched.");
|
|
1508
|
+
return "not_determined";
|
|
1509
|
+
}
|
|
1334
1510
|
let status;
|
|
1335
1511
|
try {
|
|
1336
1512
|
const ExpoTT = await import("./TrackingTransparency-DunpgkgS.mjs").catch(() => null);
|
|
@@ -1659,7 +1835,31 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1659
1835
|
if (this.enableDebug && this.errorListeners.size === 0) console.warn("[Layers]", err.message);
|
|
1660
1836
|
}
|
|
1661
1837
|
shutdown() {
|
|
1838
|
+
this._initGeneration += 1;
|
|
1839
|
+
this._initPromise = null;
|
|
1840
|
+
this._isInitialized = false;
|
|
1841
|
+
this._runtimeGeneration = this._initGeneration;
|
|
1842
|
+
this.teardownRuntime();
|
|
1843
|
+
this._attributionDeeplinkId = null;
|
|
1844
|
+
this._attributionGclid = null;
|
|
1845
|
+
this._attributionFbclid = null;
|
|
1846
|
+
this._attributionFbc = null;
|
|
1847
|
+
this._attributionTtclid = null;
|
|
1848
|
+
this._attributionMsclkid = null;
|
|
1849
|
+
this._initListener = null;
|
|
1850
|
+
this._skanManager = null;
|
|
1851
|
+
this._skanArmed = false;
|
|
1852
|
+
setSkanCore(null);
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Remove every listener and timer this instance installed, then shut the
|
|
1856
|
+
* core down. Shared by shutdown() and the mid-init abort path, so it must be
|
|
1857
|
+
* safe to call twice — every handle is nulled and the core's own shutdown()
|
|
1858
|
+
* is a no-op once it has run.
|
|
1859
|
+
*/
|
|
1860
|
+
teardownRuntime() {
|
|
1662
1861
|
this.stopConfigPolling();
|
|
1862
|
+
this.cancelLifecycleReachabilityCheck();
|
|
1663
1863
|
if (this.appStateSubscription) {
|
|
1664
1864
|
this.appStateSubscription.remove();
|
|
1665
1865
|
this.appStateSubscription = null;
|
|
@@ -1672,17 +1872,9 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1672
1872
|
this.deepLinkUnsubscribe();
|
|
1673
1873
|
this.deepLinkUnsubscribe = null;
|
|
1674
1874
|
}
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
this._attributionFbc = null;
|
|
1679
|
-
this._attributionTtclid = null;
|
|
1680
|
-
this._attributionMsclkid = null;
|
|
1681
|
-
this._initListener = null;
|
|
1682
|
-
this._skanManager = null;
|
|
1683
|
-
this._skanArmed = false;
|
|
1684
|
-
setSkanCore(null);
|
|
1685
|
-
this.core.shutdown();
|
|
1875
|
+
try {
|
|
1876
|
+
this.core.shutdown();
|
|
1877
|
+
} catch {}
|
|
1686
1878
|
}
|
|
1687
1879
|
/**
|
|
1688
1880
|
* Store attribution data that will be attached to all subsequent events.
|
|
@@ -1796,6 +1988,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1796
1988
|
}
|
|
1797
1989
|
_trackedDeepLinkUrls = /* @__PURE__ */ new Set();
|
|
1798
1990
|
setupDeepLinkAutoTracking() {
|
|
1991
|
+
if (this.deepLinkUnsubscribe) {
|
|
1992
|
+
this.deepLinkUnsubscribe();
|
|
1993
|
+
this.deepLinkUnsubscribe = null;
|
|
1994
|
+
}
|
|
1799
1995
|
this.deepLinkUnsubscribe = setupDeepLinkListener((data) => {
|
|
1800
1996
|
if (this._trackedDeepLinkUrls.has(data.url)) return;
|
|
1801
1997
|
this._trackedDeepLinkUrls.add(data.url);
|
|
@@ -1926,9 +2122,27 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1926
2122
|
} catch {}
|
|
1927
2123
|
} catch {}
|
|
1928
2124
|
}
|
|
2125
|
+
/**
|
|
2126
|
+
* The `react-native` module as this package resolves it.
|
|
2127
|
+
*
|
|
2128
|
+
* A method rather than 16 scattered `require` calls at the lifecycle sites,
|
|
2129
|
+
* so the module the listener binds to and the module the reachability check
|
|
2130
|
+
* inspects are provably the same one.
|
|
2131
|
+
*/
|
|
2132
|
+
requireReactNative() {
|
|
2133
|
+
return __require("react-native");
|
|
2134
|
+
}
|
|
1929
2135
|
setupAppStateListener() {
|
|
2136
|
+
if (this.appStateSubscription) {
|
|
2137
|
+
this.appStateSubscription.remove();
|
|
2138
|
+
this.appStateSubscription = null;
|
|
2139
|
+
}
|
|
2140
|
+
this.cancelLifecycleReachabilityCheck();
|
|
1930
2141
|
try {
|
|
1931
|
-
const
|
|
2142
|
+
const injected = this.config.appState;
|
|
2143
|
+
const rn = injected ? null : this.requireReactNative();
|
|
2144
|
+
const AppState = injected ?? rn?.AppState;
|
|
2145
|
+
if (!AppState) throw new Error("react-native AppState is unavailable");
|
|
1932
2146
|
let lastEmittedState = null;
|
|
1933
2147
|
this.appStateSubscription = AppState.addEventListener("change", (nextAppState) => {
|
|
1934
2148
|
if (nextAppState === "background" || nextAppState === "inactive") {
|
|
@@ -1947,7 +2161,45 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1947
2161
|
if (this.isOnline) this.core.flushAsync().catch(() => {});
|
|
1948
2162
|
}
|
|
1949
2163
|
});
|
|
1950
|
-
|
|
2164
|
+
if (rn) this.scheduleLifecycleReachabilityCheck(rn);
|
|
2165
|
+
} catch (e) {
|
|
2166
|
+
this.emitError(e);
|
|
2167
|
+
console.warn("[Layers] AppState listener failed to register — $app_background and the background crash-safety snapshot are disabled for this session:", e);
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
/**
|
|
2171
|
+
* Ask, one tick later, whether the listener just registered can ever fire.
|
|
2172
|
+
*
|
|
2173
|
+
* `AppState.addEventListener` hands back a subscription object no matter
|
|
2174
|
+
* which copy of react-native you call it on, and a duplicate copy's
|
|
2175
|
+
* `RCTDeviceEventEmitter` is never fed by the native side — so the
|
|
2176
|
+
* subscription is real, well-formed, and permanently silent. That is the
|
|
2177
|
+
* exact state a release build of examples/expo was in: registration logged
|
|
2178
|
+
* success on every launch while `$app_background`, `$app_foreground` and
|
|
2179
|
+
* the crash-safety snapshot had not run once. Nothing in the SDK could see
|
|
2180
|
+
* it, and nothing in the app could either.
|
|
2181
|
+
*
|
|
2182
|
+
* The check is DEFERRED by a tick because it reads `AppRegistry`, which the
|
|
2183
|
+
* host populates from its entry file. An SDK constructed at module scope
|
|
2184
|
+
* ahead of `AppRegistry.registerComponent` would otherwise look like a
|
|
2185
|
+
* duplicate to itself — a false alarm about a healthy integration, which is
|
|
2186
|
+
* a worse failure than the one being fixed.
|
|
2187
|
+
*/
|
|
2188
|
+
scheduleLifecycleReachabilityCheck(rn) {
|
|
2189
|
+
this.cancelLifecycleReachabilityCheck();
|
|
2190
|
+
this._lifecycleCheckTimer = setTimeout(() => {
|
|
2191
|
+
this._lifecycleCheckTimer = null;
|
|
2192
|
+
if (hostAppIsRegisteredOn(rn) !== false) return;
|
|
2193
|
+
const error = new Error(DUPLICATE_REACT_NATIVE_MESSAGE);
|
|
2194
|
+
this.emitError(error);
|
|
2195
|
+
console.warn(DUPLICATE_REACT_NATIVE_MESSAGE);
|
|
2196
|
+
}, 0);
|
|
2197
|
+
}
|
|
2198
|
+
cancelLifecycleReachabilityCheck() {
|
|
2199
|
+
if (this._lifecycleCheckTimer !== null) {
|
|
2200
|
+
clearTimeout(this._lifecycleCheckTimer);
|
|
2201
|
+
this._lifecycleCheckTimer = null;
|
|
2202
|
+
}
|
|
1951
2203
|
}
|
|
1952
2204
|
async configureSkanFromRemoteConfig() {
|
|
1953
2205
|
try {
|
|
@@ -1987,6 +2239,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1987
2239
|
} catch {}
|
|
1988
2240
|
}
|
|
1989
2241
|
setupNetInfoListener() {
|
|
2242
|
+
if (this.netInfoUnsubscribe) {
|
|
2243
|
+
this.netInfoUnsubscribe();
|
|
2244
|
+
this.netInfoUnsubscribe = null;
|
|
2245
|
+
}
|
|
1990
2246
|
try {
|
|
1991
2247
|
this.netInfoUnsubscribe = __require("@react-native-community/netinfo").addEventListener((state) => {
|
|
1992
2248
|
const wasOffline = !this.isOnline;
|
|
@@ -2109,7 +2365,23 @@ function getLocale() {
|
|
|
2109
2365
|
return "en-US";
|
|
2110
2366
|
}
|
|
2111
2367
|
const INSTALL_ID_KEY = "layers_install_id";
|
|
2112
|
-
|
|
2368
|
+
/**
|
|
2369
|
+
* Pre-scoping first-launch key. Read-only from here on: it is global, so a
|
|
2370
|
+
* staging→production `appId` switch made every app share one flag. We still
|
|
2371
|
+
* consult it so installs that predate the scoping don't re-fire `app_install`
|
|
2372
|
+
* on upgrade, but nothing writes it any more.
|
|
2373
|
+
*/
|
|
2374
|
+
const FIRST_LAUNCH_TRACKED_KEY_LEGACY = "@layers/first_launch_tracked";
|
|
2375
|
+
/**
|
|
2376
|
+
* First-launch flag, scoped by `appId` to match the engine's app-scoped
|
|
2377
|
+
* identity state (`layers_sdk_<appId>_identity_state`). With a single global
|
|
2378
|
+
* key the two disagreed: switching `appId` made the engine re-emit
|
|
2379
|
+
* `$first_open` (fresh identity state) while the wrapper suppressed
|
|
2380
|
+
* `app_install` (flag already set) — a first-open with no install.
|
|
2381
|
+
*/
|
|
2382
|
+
function firstLaunchTrackedKey(appId) {
|
|
2383
|
+
return `@layers/first_launch_tracked_${appId}`;
|
|
2384
|
+
}
|
|
2113
2385
|
/**
|
|
2114
2386
|
* Last-known app_version persisted across launches. Used to detect
|
|
2115
2387
|
* `$app_update` (version increment) vs. `$first_open` (no prior value).
|
|
@@ -2123,17 +2395,34 @@ const LAST_APP_VERSION_KEY = "@layers/last_app_version";
|
|
|
2123
2395
|
* new install — and suppresses `is_first_launch = true`.
|
|
2124
2396
|
*/
|
|
2125
2397
|
const INSTALL_EVENT_MAX_DIFF_MS = 1440 * 60 * 1e3;
|
|
2398
|
+
/**
|
|
2399
|
+
* Process-lifetime install ID used when AsyncStorage is unavailable. Minting a
|
|
2400
|
+
* fresh UUID per call made every launch — and every call within a launch —
|
|
2401
|
+
* look like a different install: rotating `install_id`, `app_install` +
|
|
2402
|
+
* `$first_open` on every start, no attribution persistence. Memoizing at least
|
|
2403
|
+
* keeps a single session internally consistent.
|
|
2404
|
+
*/
|
|
2405
|
+
let _ephemeralInstallId = null;
|
|
2406
|
+
let _warnedNoAsyncStorage = false;
|
|
2407
|
+
function ephemeralInstallId() {
|
|
2408
|
+
if (!_warnedNoAsyncStorage) {
|
|
2409
|
+
_warnedNoAsyncStorage = true;
|
|
2410
|
+
console.warn("[Layers] @react-native-async-storage/async-storage is not installed — install ID, first-launch state and the offline event queue cannot persist. Every app launch will look like a new install. Install the package to enable persistent identity.");
|
|
2411
|
+
}
|
|
2412
|
+
_ephemeralInstallId ??= generateUUID();
|
|
2413
|
+
return _ephemeralInstallId;
|
|
2414
|
+
}
|
|
2126
2415
|
async function getOrSetInstallId() {
|
|
2127
2416
|
try {
|
|
2128
2417
|
const AsyncStorage = await loadAsyncStorage();
|
|
2129
|
-
if (!AsyncStorage) return
|
|
2418
|
+
if (!AsyncStorage) return ephemeralInstallId();
|
|
2130
2419
|
const existing = await AsyncStorage.getItem(INSTALL_ID_KEY);
|
|
2131
2420
|
if (existing) return existing;
|
|
2132
2421
|
const newId = generateUUID();
|
|
2133
2422
|
await AsyncStorage.setItem(INSTALL_ID_KEY, newId);
|
|
2134
2423
|
return newId;
|
|
2135
2424
|
} catch {
|
|
2136
|
-
return
|
|
2425
|
+
return ephemeralInstallId();
|
|
2137
2426
|
}
|
|
2138
2427
|
}
|
|
2139
2428
|
function generateUUID() {
|
|
@@ -2318,6 +2607,32 @@ const INSTALL_REFERRER_ATTRIBUTION_PARAMS = new Set([
|
|
|
2318
2607
|
"click_id"
|
|
2319
2608
|
]);
|
|
2320
2609
|
/**
|
|
2610
|
+
* Decode one `application/x-www-form-urlencoded` token from a URL query
|
|
2611
|
+
* component. This is the single decoding rule every Layers SDK implements
|
|
2612
|
+
* (Kotlin, Swift, Dart, C#, and here):
|
|
2613
|
+
*
|
|
2614
|
+
* - `+` -> space (ad platforms emit `running+shoes` for "running shoes")
|
|
2615
|
+
* - `%XX` -> the byte 0xXX (then UTF-8)
|
|
2616
|
+
* - one pass: neither output feeds the other, so `%2B` yields a literal `+`
|
|
2617
|
+
*
|
|
2618
|
+
* The order below is load-bearing. Percent-decoding FIRST and then swapping
|
|
2619
|
+
* `+` for a space turns `%2B` into a space — a double decode that silently
|
|
2620
|
+
* corrupts any campaign name containing a real plus sign. Swapping `+` for
|
|
2621
|
+
* its own escape on the still-encoded token makes that impossible.
|
|
2622
|
+
*
|
|
2623
|
+
* Applies to the QUERY component only. Path and fragment are RFC 3986, where
|
|
2624
|
+
* `+` is an ordinary character.
|
|
2625
|
+
*
|
|
2626
|
+
* Never throws: a malformed escape (e.g. `%ZZ`) yields the raw token.
|
|
2627
|
+
*/
|
|
2628
|
+
function decodeFormUrlComponent(encoded) {
|
|
2629
|
+
try {
|
|
2630
|
+
return decodeURIComponent(encoded.replace(/\+/g, "%20"));
|
|
2631
|
+
} catch {
|
|
2632
|
+
return encoded;
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
/**
|
|
2321
2636
|
* Parse a raw Play Install Referrer string into a map of recognized attribution
|
|
2322
2637
|
* params. Accepts either a bare query string (`a=1&b=2`) or a full URL.
|
|
2323
2638
|
* Returns an empty object on parse failure.
|
|
@@ -2332,11 +2647,11 @@ function parseInstallReferrerUrl(referrer) {
|
|
|
2332
2647
|
if (!qs.includes("=") && qs.includes("%3D")) qs = decodeURIComponent(qs);
|
|
2333
2648
|
for (const pair of qs.split("&")) {
|
|
2334
2649
|
const eq = pair.indexOf("=");
|
|
2335
|
-
if (eq >= 0)
|
|
2336
|
-
const key =
|
|
2337
|
-
const value =
|
|
2650
|
+
if (eq >= 0) {
|
|
2651
|
+
const key = decodeFormUrlComponent(pair.slice(0, eq));
|
|
2652
|
+
const value = decodeFormUrlComponent(pair.slice(eq + 1));
|
|
2338
2653
|
if (value && INSTALL_REFERRER_ATTRIBUTION_PARAMS.has(key)) out[key] = value;
|
|
2339
|
-
}
|
|
2654
|
+
}
|
|
2340
2655
|
}
|
|
2341
2656
|
} catch {}
|
|
2342
2657
|
return out;
|
|
@@ -2416,6 +2731,7 @@ function parseDeepLink(url) {
|
|
|
2416
2731
|
}
|
|
2417
2732
|
}
|
|
2418
2733
|
const _expoRouterPreviousPath = /* @__PURE__ */ new WeakMap();
|
|
2734
|
+
const _expoRouterLastTracked = /* @__PURE__ */ new WeakMap();
|
|
2419
2735
|
/**
|
|
2420
2736
|
* Hook that emits `$screen_view` for every Expo Router pathname change.
|
|
2421
2737
|
*
|
|
@@ -2426,11 +2742,16 @@ const _expoRouterPreviousPath = /* @__PURE__ */ new WeakMap();
|
|
|
2426
2742
|
* — no need to join adjacent rows.
|
|
2427
2743
|
*/
|
|
2428
2744
|
function useLayersExpoRouterTracking(sdkInstance, usePathname, useGlobalSearchParams) {
|
|
2745
|
+
if (sdkInstance != null && typeof sdkInstance.screen !== "function") throw new TypeError("useLayersExpoRouterTracking: expected a LayersReactNative instance (or null before init).");
|
|
2429
2746
|
const { useEffect } = __require("react");
|
|
2430
2747
|
const pathname = usePathname();
|
|
2431
2748
|
const params = useGlobalSearchParams();
|
|
2749
|
+
const paramsString = JSON.stringify(params);
|
|
2432
2750
|
useEffect(() => {
|
|
2751
|
+
if (sdkInstance == null) return;
|
|
2433
2752
|
if (pathname) {
|
|
2753
|
+
const routeKey = `${pathname}${paramsString}`;
|
|
2754
|
+
if (_expoRouterLastTracked.get(sdkInstance) === routeKey) return;
|
|
2434
2755
|
const properties = {};
|
|
2435
2756
|
Object.entries(params).forEach(([key, value]) => {
|
|
2436
2757
|
properties[key] = Array.isArray(value) ? value.join(",") : value;
|
|
@@ -2439,10 +2760,15 @@ function useLayersExpoRouterTracking(sdkInstance, usePathname, useGlobalSearchPa
|
|
|
2439
2760
|
if (previous && previous !== pathname) properties.previous_screen_name = previous;
|
|
2440
2761
|
sdkInstance.screen(pathname, properties);
|
|
2441
2762
|
_expoRouterPreviousPath.set(sdkInstance, pathname);
|
|
2763
|
+
_expoRouterLastTracked.set(sdkInstance, routeKey);
|
|
2442
2764
|
}
|
|
2443
|
-
}, [
|
|
2765
|
+
}, [
|
|
2766
|
+
sdkInstance,
|
|
2767
|
+
pathname,
|
|
2768
|
+
paramsString
|
|
2769
|
+
]);
|
|
2444
2770
|
}
|
|
2445
2771
|
|
|
2446
2772
|
//#endregion
|
|
2447
2773
|
export { addToWishlistEvent as $, registerExpoBackgroundFlush as A, trackPurchaseFailed as B, SurveysModule as C, BACKGROUND_FLUSH_MIN_INTERVAL_MINUTES as D, useLayersNavigationTracking as E, trackRevenueCatPurchase as F, superwallOnEvent as G, trackRemoveFromCart as H, trackAddToCart as I, superwallTrackPurchase as J, superwallTrackDismiss as K, trackBeginCheckout as L, isRevenueCatConnected as M, resetRevenueCatForTesting as N, BACKGROUND_FLUSH_TASK_NAME as O, syncRevenueCatAttributes as P, addToCartEvent as Q, trackOrder as R, useLayersExpoRouterTracking as S, resolveActiveRoute as T, trackSubscription as U, trackRefund as V, trackViewProduct as W, superwallUserAttributes as X, superwallTrackSkip as Y, StandardEvents as Z, parseDeepLink as _, buildBeginCheckoutEvent as a, registerEvent as at, setupDeepLinkListener as b, buildStartTrialEvent as c, shareEvent as ct, formatFbc as d, subscribeEvent as dt, initiateCheckoutEvent as et, getAdServicesToken as f, tutorialCompleteEvent as ft, getOrSetInstallId as g, getInstallReferrer as h, buildAddToCartEvent as i, purchaseEvent as it, connectRevenueCat as j, createBackgroundFlushHandler as k, buildSubscribeEvent as l, signUpEvent as lt, getGoogleAdvertisingId as m, viewItemEvent as mt, LayersEvent as n, levelStartEvent as nt, buildPurchaseEvent as o, screenViewEvent as ot, getFirstInstallTime as p, viewContentEvent as pt, superwallTrackPresentation as q, LayersReactNative as r, loginEvent as rt, buildRefundEvent as s, searchEvent as st, LayersError$1 as t, levelCompleteEvent as tt, buildViewItemEvent as u, startTrialEvent as ut, parseInstallReferrerUrl as v, createNavigationListener as w, shouldTreatAsNewInstall as x, readClipboardAttribution as y, trackPurchase as z };
|
|
2448
|
-
//# sourceMappingURL=src-
|
|
2774
|
+
//# sourceMappingURL=src-A7xqoTvD.mjs.map
|