@layers/react-native 3.2.4 → 3.2.6
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/dist/att-BDPyE-Gs.d.mts.map +1 -1
- package/dist/debug-overlay.d.mts +1 -1
- package/dist/debug-overlay.d.ts +1 -1
- package/dist/{index-DWTdnuyU.d.mts → index-BFkSi3wX.d.mts} +71 -3
- package/dist/{index-DWTdnuyU.d.mts.map → index-BFkSi3wX.d.mts.map} +1 -1
- package/dist/{index-BHp0kMOu.d.ts → index-BJ3l4nsV.d.ts} +71 -3
- package/dist/{index-BHp0kMOu.d.ts.map → index-BJ3l4nsV.d.ts.map} +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- 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-DYpxIj1b.mjs → src-BRZ3Lfl5.mjs} +251 -26
- package/dist/src-BRZ3Lfl5.mjs.map +1 -0
- package/dist/{src-beiBZV58.js → src-DPSm18ng.js} +250 -25
- package/package.json +3 -2
- package/dist/skan-CYTZtEAI.mjs.map +0 -1
- package/dist/src-DYpxIj1b.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-nOFOJqeH.js');
|
|
2
2
|
const require_att = require('./att-CauvkIKr.js');
|
|
3
|
-
const require_skan = require('./skan-
|
|
3
|
+
const require_skan = require('./skan-BRhw9sPC.js');
|
|
4
4
|
let __layers_core_wasm = require("@layers/core-wasm");
|
|
5
5
|
__layers_core_wasm = require_chunk.__toESM(__layers_core_wasm);
|
|
6
6
|
|
|
@@ -910,7 +910,7 @@ var SurveysModule = class {
|
|
|
910
910
|
|
|
911
911
|
//#endregion
|
|
912
912
|
//#region src/index.ts
|
|
913
|
-
const SDK_VERSION = "3.2.
|
|
913
|
+
const SDK_VERSION = "3.2.6";
|
|
914
914
|
var LayersReactNative = class LayersReactNative {
|
|
915
915
|
core;
|
|
916
916
|
eagerPersistence;
|
|
@@ -928,6 +928,9 @@ var LayersReactNative = class LayersReactNative {
|
|
|
928
928
|
static MAX_RECENT_EVENTS = 20;
|
|
929
929
|
_recentEvents = [];
|
|
930
930
|
_isInitialized = false;
|
|
931
|
+
_initPromise = null;
|
|
932
|
+
_initGeneration = 0;
|
|
933
|
+
_runtimeGeneration = 0;
|
|
931
934
|
_configPollTimer = null;
|
|
932
935
|
static CONFIG_POLL_INTERVAL_MS = 3e5;
|
|
933
936
|
_adServicesToken = null;
|
|
@@ -969,16 +972,136 @@ var LayersReactNative = class LayersReactNative {
|
|
|
969
972
|
persistence: this.eagerPersistence
|
|
970
973
|
});
|
|
971
974
|
require_skan.setSkanCore(this.core);
|
|
975
|
+
this.applyEagerDeviceContext();
|
|
972
976
|
if (this.appUserId) {
|
|
973
977
|
this.core.identify(this.appUserId);
|
|
974
978
|
this.userIdLocked = true;
|
|
975
979
|
}
|
|
976
980
|
}
|
|
981
|
+
/**
|
|
982
|
+
* Best-effort device context available at construction time — no `await`,
|
|
983
|
+
* so it can run in the constructor before any pre-init event is tracked.
|
|
984
|
+
* Only the synchronously readable fields; the rest arrive with
|
|
985
|
+
* initializeDeviceInfo().
|
|
986
|
+
*/
|
|
987
|
+
applyEagerDeviceContext() {
|
|
988
|
+
const context = {
|
|
989
|
+
platform: "react-native",
|
|
990
|
+
osVersion: "unknown",
|
|
991
|
+
deviceModel: "unknown",
|
|
992
|
+
locale: "en-US"
|
|
993
|
+
};
|
|
994
|
+
try {
|
|
995
|
+
const { Platform, Dimensions } = require("react-native");
|
|
996
|
+
context.platform = Platform.OS === "ios" ? "ios" : Platform.OS === "android" ? "android" : "react-native";
|
|
997
|
+
context.osVersion = typeof Platform.Version === "string" ? Platform.Version : String(Platform.Version);
|
|
998
|
+
context.locale = getLocale();
|
|
999
|
+
if (Platform.OS === "android") {
|
|
1000
|
+
const brand = Platform.constants?.Brand ?? "";
|
|
1001
|
+
const model = Platform.constants?.Model ?? "";
|
|
1002
|
+
const deviceModel = brand && model ? `${brand} ${model}` : model || brand;
|
|
1003
|
+
if (deviceModel) context.deviceModel = deviceModel;
|
|
1004
|
+
}
|
|
1005
|
+
try {
|
|
1006
|
+
const window = Dimensions.get("window");
|
|
1007
|
+
context.screenSize = `${Math.round(window.width)}x${Math.round(window.height)}`;
|
|
1008
|
+
} catch {}
|
|
1009
|
+
try {
|
|
1010
|
+
context.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1011
|
+
} catch {}
|
|
1012
|
+
} catch {}
|
|
1013
|
+
try {
|
|
1014
|
+
this.core.setDeviceContext(context);
|
|
1015
|
+
} catch {}
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* The platform this instance runs on: 'ios' | 'android' | 'react-native'.
|
|
1019
|
+
* Reads the device context the constructor stamped (applyEagerDeviceContext)
|
|
1020
|
+
* and falls back to a direct `Platform.OS` read, so it answers correctly
|
|
1021
|
+
* before init() has completed.
|
|
1022
|
+
*/
|
|
1023
|
+
currentPlatform() {
|
|
1024
|
+
try {
|
|
1025
|
+
const platform = this.core.getDeviceContext().platform;
|
|
1026
|
+
if (platform) return platform;
|
|
1027
|
+
} catch {}
|
|
1028
|
+
try {
|
|
1029
|
+
const { Platform } = require("react-native");
|
|
1030
|
+
return String(Platform.OS);
|
|
1031
|
+
} catch {
|
|
1032
|
+
return "react-native";
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Initialize the SDK. Idempotent: concurrent calls await the same in-flight
|
|
1037
|
+
* run, and a completed init() returns immediately. shutdown() releases the
|
|
1038
|
+
* latch, so shutdown() → init() re-initializes.
|
|
1039
|
+
*/
|
|
977
1040
|
async init() {
|
|
1041
|
+
if (this._initPromise) return this._initPromise;
|
|
1042
|
+
const promise = this.runInit(this._initGeneration);
|
|
1043
|
+
this._initPromise = promise;
|
|
1044
|
+
try {
|
|
1045
|
+
await promise;
|
|
1046
|
+
} catch (e) {
|
|
1047
|
+
if (this._initPromise === promise) this._initPromise = null;
|
|
1048
|
+
throw e;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
/**
|
|
1052
|
+
* True when a shutdown() landed after this init() run started. The caller
|
|
1053
|
+
* must return immediately.
|
|
1054
|
+
*
|
|
1055
|
+
* Without this gate init() ran to completion on an abandoned instance: it
|
|
1056
|
+
* built a second live core (the AsyncStorage rebuild below), installed the
|
|
1057
|
+
* AppState/NetInfo/deep-link listeners and the 300s config-poll timer on it,
|
|
1058
|
+
* and tracked a duplicate `app_open` — one orphaned SDK, with its own
|
|
1059
|
+
* timers, per remount. React 18 StrictMode mounts → unmounts → remounts
|
|
1060
|
+
* every effect, so the Expo `LayersProvider` (which calls shutdown() in
|
|
1061
|
+
* cleanup while init() is still awaiting) hit this on every dev launch.
|
|
1062
|
+
*
|
|
1063
|
+
* **This check has no side effects, deliberately.** It used to tear the
|
|
1064
|
+
* runtime down on any generation mismatch, which is wrong the moment two
|
|
1065
|
+
* runs overlap: init A → shutdown → init B completes → A finally reaches a
|
|
1066
|
+
* checkpoint and demolishes *B's* listeners, core and timer, leaving an SDK
|
|
1067
|
+
* that reported `isInitialized === true` and delivered nothing. Cleanup
|
|
1068
|
+
* belongs to shutdown() (which owns everything installed at the moment it
|
|
1069
|
+
* runs) and to {@link abandonRun} (which proves ownership by generation
|
|
1070
|
+
* first).
|
|
1071
|
+
*/
|
|
1072
|
+
isRunAbandoned(generation) {
|
|
1073
|
+
return generation !== this._initGeneration;
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Abandon this run and release only the resources it installed itself.
|
|
1077
|
+
*
|
|
1078
|
+
* Every install site below is *synchronously* adjacent to its preceding
|
|
1079
|
+
* checkpoint — no `await` sits between "still current?" and the assignment —
|
|
1080
|
+
* so a shutdown() can never slip in between the two, and anything this run
|
|
1081
|
+
* did install was already torn down by that shutdown(). The ownership check
|
|
1082
|
+
* is what keeps that true if a future edit ever puts an await in between:
|
|
1083
|
+
* the run cleans up only while it is still the runtime's owner.
|
|
1084
|
+
*/
|
|
1085
|
+
abandonRun(generation) {
|
|
1086
|
+
if (this._runtimeGeneration !== generation) return;
|
|
1087
|
+
this.teardownRuntime();
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Checkpoint used at every await boundary in runInit(): report whether this
|
|
1091
|
+
* run has been abandoned and, if so, release only what it still owns.
|
|
1092
|
+
*/
|
|
1093
|
+
initAborted(generation) {
|
|
1094
|
+
if (!this.isRunAbandoned(generation)) return false;
|
|
1095
|
+
this.abandonRun(generation);
|
|
1096
|
+
return true;
|
|
1097
|
+
}
|
|
1098
|
+
async runInit(generation) {
|
|
978
1099
|
const initStartTime = Date.now();
|
|
979
1100
|
if (typeof WebAssembly !== "undefined") await (0, __layers_core_wasm.initWasm)();
|
|
1101
|
+
if (this.initAborted(generation)) return;
|
|
980
1102
|
try {
|
|
981
1103
|
const persistence = await createAsyncStoragePersistence(this.config.appId);
|
|
1104
|
+
if (this.initAborted(generation)) return;
|
|
982
1105
|
const httpClient = new __layers_core_wasm.FetchHttpClient();
|
|
983
1106
|
const migrationState = this.core.exportMigrationState();
|
|
984
1107
|
this.core.shutdown();
|
|
@@ -1010,17 +1133,20 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1010
1133
|
persistence
|
|
1011
1134
|
});
|
|
1012
1135
|
this.core.applyMigrationState(migrationState);
|
|
1136
|
+
this._runtimeGeneration = generation;
|
|
1013
1137
|
require_skan.setSkanCore(this.core);
|
|
1014
1138
|
if (this.appUserId) this.core.identify(this.appUserId);
|
|
1015
1139
|
} catch {}
|
|
1016
|
-
if (typeof WebAssembly !== "undefined" && !this.core.isWasmActive()) console.warn("[Layers] WebAssembly is available but the Rust core failed to load — running on the JS fallback engine. Check Metro asset handling for layers_core_bg.wasm.");
|
|
1017
1140
|
await this.restoreAttributionData();
|
|
1018
1141
|
await this.initializeDeviceInfo();
|
|
1142
|
+
if (this.initAborted(generation)) return;
|
|
1143
|
+
this._runtimeGeneration = generation;
|
|
1019
1144
|
this.setupAppStateListener();
|
|
1020
1145
|
this.setupNetInfoListener();
|
|
1021
1146
|
const mainThreadDurationMs = Date.now() - initStartTime;
|
|
1022
1147
|
await this.core.fetchRemoteConfig().catch(() => {});
|
|
1023
1148
|
await this.configureSkanFromRemoteConfig();
|
|
1149
|
+
if (this.initAborted(generation)) return;
|
|
1024
1150
|
this.startConfigPolling();
|
|
1025
1151
|
let clipboardData = null;
|
|
1026
1152
|
try {
|
|
@@ -1034,13 +1160,28 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1034
1160
|
if (clipboardEnabled) clipboardData = await readClipboardAttribution();
|
|
1035
1161
|
}
|
|
1036
1162
|
} catch {}
|
|
1163
|
+
if (this.initAborted(generation)) return;
|
|
1037
1164
|
if (this.config.autoTrackAppOpen !== false) {
|
|
1038
1165
|
const appOpenProps = {};
|
|
1039
1166
|
let isFirstLaunchByFlag = true;
|
|
1040
1167
|
try {
|
|
1041
1168
|
const AsyncStorage = await loadAsyncStorage();
|
|
1042
1169
|
if (AsyncStorage) {
|
|
1043
|
-
|
|
1170
|
+
const scopedKey = firstLaunchTrackedKey(this.config.appId);
|
|
1171
|
+
let flag = await AsyncStorage.getItem(scopedKey);
|
|
1172
|
+
let adoptLegacy = false;
|
|
1173
|
+
if (flag === null) {
|
|
1174
|
+
const legacy = await AsyncStorage.getItem(FIRST_LAUNCH_TRACKED_KEY_LEGACY);
|
|
1175
|
+
if (legacy === "true") {
|
|
1176
|
+
flag = legacy;
|
|
1177
|
+
adoptLegacy = true;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
if (flag === "true") isFirstLaunchByFlag = false;
|
|
1181
|
+
if (adoptLegacy) try {
|
|
1182
|
+
await AsyncStorage.setItem(scopedKey, "true");
|
|
1183
|
+
await AsyncStorage.removeItem(FIRST_LAUNCH_TRACKED_KEY_LEGACY);
|
|
1184
|
+
} catch {}
|
|
1044
1185
|
}
|
|
1045
1186
|
} catch {}
|
|
1046
1187
|
const isFirstLaunch = await shouldTreatAsNewInstall(isFirstLaunchByFlag, this._hadPriorSdkState, this.enableDebug);
|
|
@@ -1049,10 +1190,6 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1049
1190
|
if (isFirstLaunch && !hasAttribution) try {
|
|
1050
1191
|
await this.resolveClickFromFingerprint();
|
|
1051
1192
|
} catch {}
|
|
1052
|
-
if (isFirstLaunch) try {
|
|
1053
|
-
const AsyncStorage = await loadAsyncStorage();
|
|
1054
|
-
if (AsyncStorage) await AsyncStorage.setItem(FIRST_LAUNCH_TRACKED_KEY, "true");
|
|
1055
|
-
} catch {}
|
|
1056
1193
|
if (clipboardData) {
|
|
1057
1194
|
appOpenProps.clipboard_attribution_url = clipboardData.clickUrl;
|
|
1058
1195
|
appOpenProps.clipboard_click_id = clipboardData.clickId;
|
|
@@ -1066,8 +1203,13 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1066
1203
|
if (this._installReferrerParams) {
|
|
1067
1204
|
for (const [key, value] of Object.entries(this._installReferrerParams)) if (appOpenProps[key] === void 0) appOpenProps[key] = value;
|
|
1068
1205
|
}
|
|
1206
|
+
if (this.initAborted(generation)) return;
|
|
1069
1207
|
if (isFirstLaunch) this.track("app_install", appOpenProps);
|
|
1070
1208
|
this.track("app_open", appOpenProps);
|
|
1209
|
+
if (isFirstLaunch) try {
|
|
1210
|
+
const AsyncStorage = await loadAsyncStorage();
|
|
1211
|
+
if (AsyncStorage) await AsyncStorage.setItem(firstLaunchTrackedKey(this.config.appId), "true");
|
|
1212
|
+
} catch {}
|
|
1071
1213
|
if (this.config.autoTrackAppUpdate !== false) try {
|
|
1072
1214
|
const currentVersion = this.core.getDeviceContext().appVersion ?? appOpenProps.app_version;
|
|
1073
1215
|
if (currentVersion && typeof currentVersion === "string") {
|
|
@@ -1083,6 +1225,7 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1083
1225
|
}
|
|
1084
1226
|
} catch {}
|
|
1085
1227
|
}
|
|
1228
|
+
if (this.initAborted(generation)) return;
|
|
1086
1229
|
if (this.config.autoTrackDeepLinks !== false) this.setupDeepLinkAutoTracking();
|
|
1087
1230
|
this._isInitialized = true;
|
|
1088
1231
|
const totalDurationMs = Date.now() - initStartTime;
|
|
@@ -1333,6 +1476,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1333
1476
|
* Returns the ATT status string.
|
|
1334
1477
|
*/
|
|
1335
1478
|
async requestTrackingPermission() {
|
|
1479
|
+
if (this.currentPlatform() === "android") {
|
|
1480
|
+
if (this.enableDebug) console.log("[Layers] requestTrackingPermission() is a no-op on Android — ATT is iOS-only; consent left untouched.");
|
|
1481
|
+
return "not_determined";
|
|
1482
|
+
}
|
|
1336
1483
|
let status;
|
|
1337
1484
|
try {
|
|
1338
1485
|
const ExpoTT = await Promise.resolve().then(() => require("./TrackingTransparency-D6ybvQzE.js")).catch(() => null);
|
|
@@ -1420,7 +1567,11 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1420
1567
|
return this.core.getConsentState();
|
|
1421
1568
|
}
|
|
1422
1569
|
setDeviceInfo(deviceInfo) {
|
|
1423
|
-
this.core.
|
|
1570
|
+
const current = this.core.getDeviceContext();
|
|
1571
|
+
this.core.setDeviceContext({
|
|
1572
|
+
...current,
|
|
1573
|
+
...deviceInfo
|
|
1574
|
+
});
|
|
1424
1575
|
}
|
|
1425
1576
|
async flush() {
|
|
1426
1577
|
try {
|
|
@@ -1657,6 +1808,29 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1657
1808
|
if (this.enableDebug && this.errorListeners.size === 0) console.warn("[Layers]", err.message);
|
|
1658
1809
|
}
|
|
1659
1810
|
shutdown() {
|
|
1811
|
+
this._initGeneration += 1;
|
|
1812
|
+
this._initPromise = null;
|
|
1813
|
+
this._isInitialized = false;
|
|
1814
|
+
this._runtimeGeneration = this._initGeneration;
|
|
1815
|
+
this.teardownRuntime();
|
|
1816
|
+
this._attributionDeeplinkId = null;
|
|
1817
|
+
this._attributionGclid = null;
|
|
1818
|
+
this._attributionFbclid = null;
|
|
1819
|
+
this._attributionFbc = null;
|
|
1820
|
+
this._attributionTtclid = null;
|
|
1821
|
+
this._attributionMsclkid = null;
|
|
1822
|
+
this._initListener = null;
|
|
1823
|
+
this._skanManager = null;
|
|
1824
|
+
this._skanArmed = false;
|
|
1825
|
+
require_skan.setSkanCore(null);
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Remove every listener and timer this instance installed, then shut the
|
|
1829
|
+
* core down. Shared by shutdown() and the mid-init abort path, so it must be
|
|
1830
|
+
* safe to call twice — every handle is nulled and the core's own shutdown()
|
|
1831
|
+
* is a no-op once it has run.
|
|
1832
|
+
*/
|
|
1833
|
+
teardownRuntime() {
|
|
1660
1834
|
this.stopConfigPolling();
|
|
1661
1835
|
if (this.appStateSubscription) {
|
|
1662
1836
|
this.appStateSubscription.remove();
|
|
@@ -1670,17 +1844,9 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1670
1844
|
this.deepLinkUnsubscribe();
|
|
1671
1845
|
this.deepLinkUnsubscribe = null;
|
|
1672
1846
|
}
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
this._attributionFbc = null;
|
|
1677
|
-
this._attributionTtclid = null;
|
|
1678
|
-
this._attributionMsclkid = null;
|
|
1679
|
-
this._initListener = null;
|
|
1680
|
-
this._skanManager = null;
|
|
1681
|
-
this._skanArmed = false;
|
|
1682
|
-
require_skan.setSkanCore(null);
|
|
1683
|
-
this.core.shutdown();
|
|
1847
|
+
try {
|
|
1848
|
+
this.core.shutdown();
|
|
1849
|
+
} catch {}
|
|
1684
1850
|
}
|
|
1685
1851
|
/**
|
|
1686
1852
|
* Store attribution data that will be attached to all subsequent events.
|
|
@@ -1794,6 +1960,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1794
1960
|
}
|
|
1795
1961
|
_trackedDeepLinkUrls = /* @__PURE__ */ new Set();
|
|
1796
1962
|
setupDeepLinkAutoTracking() {
|
|
1963
|
+
if (this.deepLinkUnsubscribe) {
|
|
1964
|
+
this.deepLinkUnsubscribe();
|
|
1965
|
+
this.deepLinkUnsubscribe = null;
|
|
1966
|
+
}
|
|
1797
1967
|
this.deepLinkUnsubscribe = setupDeepLinkListener((data) => {
|
|
1798
1968
|
if (this._trackedDeepLinkUrls.has(data.url)) return;
|
|
1799
1969
|
this._trackedDeepLinkUrls.add(data.url);
|
|
@@ -1925,6 +2095,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1925
2095
|
} catch {}
|
|
1926
2096
|
}
|
|
1927
2097
|
setupAppStateListener() {
|
|
2098
|
+
if (this.appStateSubscription) {
|
|
2099
|
+
this.appStateSubscription.remove();
|
|
2100
|
+
this.appStateSubscription = null;
|
|
2101
|
+
}
|
|
1928
2102
|
try {
|
|
1929
2103
|
const { AppState } = require("react-native");
|
|
1930
2104
|
let lastEmittedState = null;
|
|
@@ -1945,7 +2119,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1945
2119
|
if (this.isOnline) this.core.flushAsync().catch(() => {});
|
|
1946
2120
|
}
|
|
1947
2121
|
});
|
|
1948
|
-
} catch {
|
|
2122
|
+
} catch (e) {
|
|
2123
|
+
this.emitError(e);
|
|
2124
|
+
console.warn("[Layers] AppState listener failed to register — $app_background and the background crash-safety snapshot are disabled for this session:", e);
|
|
2125
|
+
}
|
|
1949
2126
|
}
|
|
1950
2127
|
async configureSkanFromRemoteConfig() {
|
|
1951
2128
|
try {
|
|
@@ -1985,6 +2162,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1985
2162
|
} catch {}
|
|
1986
2163
|
}
|
|
1987
2164
|
setupNetInfoListener() {
|
|
2165
|
+
if (this.netInfoUnsubscribe) {
|
|
2166
|
+
this.netInfoUnsubscribe();
|
|
2167
|
+
this.netInfoUnsubscribe = null;
|
|
2168
|
+
}
|
|
1988
2169
|
try {
|
|
1989
2170
|
this.netInfoUnsubscribe = require("@react-native-community/netinfo").addEventListener((state) => {
|
|
1990
2171
|
const wasOffline = !this.isOnline;
|
|
@@ -2107,7 +2288,23 @@ function getLocale() {
|
|
|
2107
2288
|
return "en-US";
|
|
2108
2289
|
}
|
|
2109
2290
|
const INSTALL_ID_KEY = "layers_install_id";
|
|
2110
|
-
|
|
2291
|
+
/**
|
|
2292
|
+
* Pre-scoping first-launch key. Read-only from here on: it is global, so a
|
|
2293
|
+
* staging→production `appId` switch made every app share one flag. We still
|
|
2294
|
+
* consult it so installs that predate the scoping don't re-fire `app_install`
|
|
2295
|
+
* on upgrade, but nothing writes it any more.
|
|
2296
|
+
*/
|
|
2297
|
+
const FIRST_LAUNCH_TRACKED_KEY_LEGACY = "@layers/first_launch_tracked";
|
|
2298
|
+
/**
|
|
2299
|
+
* First-launch flag, scoped by `appId` to match the engine's app-scoped
|
|
2300
|
+
* identity state (`layers_sdk_<appId>_identity_state`). With a single global
|
|
2301
|
+
* key the two disagreed: switching `appId` made the engine re-emit
|
|
2302
|
+
* `$first_open` (fresh identity state) while the wrapper suppressed
|
|
2303
|
+
* `app_install` (flag already set) — a first-open with no install.
|
|
2304
|
+
*/
|
|
2305
|
+
function firstLaunchTrackedKey(appId) {
|
|
2306
|
+
return `@layers/first_launch_tracked_${appId}`;
|
|
2307
|
+
}
|
|
2111
2308
|
/**
|
|
2112
2309
|
* Last-known app_version persisted across launches. Used to detect
|
|
2113
2310
|
* `$app_update` (version increment) vs. `$first_open` (no prior value).
|
|
@@ -2121,17 +2318,34 @@ const LAST_APP_VERSION_KEY = "@layers/last_app_version";
|
|
|
2121
2318
|
* new install — and suppresses `is_first_launch = true`.
|
|
2122
2319
|
*/
|
|
2123
2320
|
const INSTALL_EVENT_MAX_DIFF_MS = 1440 * 60 * 1e3;
|
|
2321
|
+
/**
|
|
2322
|
+
* Process-lifetime install ID used when AsyncStorage is unavailable. Minting a
|
|
2323
|
+
* fresh UUID per call made every launch — and every call within a launch —
|
|
2324
|
+
* look like a different install: rotating `install_id`, `app_install` +
|
|
2325
|
+
* `$first_open` on every start, no attribution persistence. Memoizing at least
|
|
2326
|
+
* keeps a single session internally consistent.
|
|
2327
|
+
*/
|
|
2328
|
+
let _ephemeralInstallId = null;
|
|
2329
|
+
let _warnedNoAsyncStorage = false;
|
|
2330
|
+
function ephemeralInstallId() {
|
|
2331
|
+
if (!_warnedNoAsyncStorage) {
|
|
2332
|
+
_warnedNoAsyncStorage = true;
|
|
2333
|
+
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.");
|
|
2334
|
+
}
|
|
2335
|
+
_ephemeralInstallId ??= generateUUID();
|
|
2336
|
+
return _ephemeralInstallId;
|
|
2337
|
+
}
|
|
2124
2338
|
async function getOrSetInstallId() {
|
|
2125
2339
|
try {
|
|
2126
2340
|
const AsyncStorage = await loadAsyncStorage();
|
|
2127
|
-
if (!AsyncStorage) return
|
|
2341
|
+
if (!AsyncStorage) return ephemeralInstallId();
|
|
2128
2342
|
const existing = await AsyncStorage.getItem(INSTALL_ID_KEY);
|
|
2129
2343
|
if (existing) return existing;
|
|
2130
2344
|
const newId = generateUUID();
|
|
2131
2345
|
await AsyncStorage.setItem(INSTALL_ID_KEY, newId);
|
|
2132
2346
|
return newId;
|
|
2133
2347
|
} catch {
|
|
2134
|
-
return
|
|
2348
|
+
return ephemeralInstallId();
|
|
2135
2349
|
}
|
|
2136
2350
|
}
|
|
2137
2351
|
function generateUUID() {
|
|
@@ -2414,6 +2628,7 @@ function parseDeepLink(url) {
|
|
|
2414
2628
|
}
|
|
2415
2629
|
}
|
|
2416
2630
|
const _expoRouterPreviousPath = /* @__PURE__ */ new WeakMap();
|
|
2631
|
+
const _expoRouterLastTracked = /* @__PURE__ */ new WeakMap();
|
|
2417
2632
|
/**
|
|
2418
2633
|
* Hook that emits `$screen_view` for every Expo Router pathname change.
|
|
2419
2634
|
*
|
|
@@ -2424,11 +2639,16 @@ const _expoRouterPreviousPath = /* @__PURE__ */ new WeakMap();
|
|
|
2424
2639
|
* — no need to join adjacent rows.
|
|
2425
2640
|
*/
|
|
2426
2641
|
function useLayersExpoRouterTracking(sdkInstance, usePathname, useGlobalSearchParams) {
|
|
2642
|
+
if (sdkInstance != null && typeof sdkInstance.screen !== "function") throw new TypeError("useLayersExpoRouterTracking: expected a LayersReactNative instance (or null before init).");
|
|
2427
2643
|
const { useEffect } = require("react");
|
|
2428
2644
|
const pathname = usePathname();
|
|
2429
2645
|
const params = useGlobalSearchParams();
|
|
2646
|
+
const paramsString = JSON.stringify(params);
|
|
2430
2647
|
useEffect(() => {
|
|
2648
|
+
if (sdkInstance == null) return;
|
|
2431
2649
|
if (pathname) {
|
|
2650
|
+
const routeKey = `${pathname}${paramsString}`;
|
|
2651
|
+
if (_expoRouterLastTracked.get(sdkInstance) === routeKey) return;
|
|
2432
2652
|
const properties = {};
|
|
2433
2653
|
Object.entries(params).forEach(([key, value]) => {
|
|
2434
2654
|
properties[key] = Array.isArray(value) ? value.join(",") : value;
|
|
@@ -2437,8 +2657,13 @@ function useLayersExpoRouterTracking(sdkInstance, usePathname, useGlobalSearchPa
|
|
|
2437
2657
|
if (previous && previous !== pathname) properties.previous_screen_name = previous;
|
|
2438
2658
|
sdkInstance.screen(pathname, properties);
|
|
2439
2659
|
_expoRouterPreviousPath.set(sdkInstance, pathname);
|
|
2660
|
+
_expoRouterLastTracked.set(sdkInstance, routeKey);
|
|
2440
2661
|
}
|
|
2441
|
-
}, [
|
|
2662
|
+
}, [
|
|
2663
|
+
sdkInstance,
|
|
2664
|
+
pathname,
|
|
2665
|
+
paramsString
|
|
2666
|
+
]);
|
|
2442
2667
|
}
|
|
2443
2668
|
|
|
2444
2669
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layers/react-native",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"dist",
|
|
55
55
|
"ios",
|
|
56
56
|
"android",
|
|
57
|
+
"!android/build",
|
|
57
58
|
"layers-react-native.podspec"
|
|
58
59
|
],
|
|
59
60
|
"keywords": [
|
|
@@ -66,7 +67,7 @@
|
|
|
66
67
|
"mobile"
|
|
67
68
|
],
|
|
68
69
|
"dependencies": {
|
|
69
|
-
"@layers/core-wasm": "3.2.
|
|
70
|
+
"@layers/core-wasm": "3.2.6"
|
|
70
71
|
},
|
|
71
72
|
"peerDependencies": {
|
|
72
73
|
"@react-native-async-storage/async-storage": ">=1.21.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skan-CYTZtEAI.mjs","names":["sharedCore: SkanCore | null"],"sources":["../src/skan.ts"],"sourcesContent":["// SKAN Module — iOS-only SKAdNetwork conversion value management.\n//\n// Thin facade over the Rust core's SKAN engine, which is the single source of\n// truth for rule evaluation, presets, the monotonic floor, and persistence. This\n// wrapper only bridges to the native iOS SKAdNetwork APIs (which the core cannot\n// call) and reports the native apply outcome back to the core via\n// `skanRecordConversionResult`. There is no parallel JS rule engine.\n\nexport interface SKANConversionRule {\n eventName: string;\n conditions?: Record<string, unknown>;\n conversionValue: number; // 0-63 for SKAN 3.0, 0-7 fine values in SKAN 4.0\n coarseValue?: 'low' | 'medium' | 'high'; // SKAN 4.0 only\n lockWindow?: boolean; // SKAN 4.0 only\n priority?: number;\n description?: string;\n}\n\nexport interface SKANPresetConfig {\n name: 'subscriptions' | 'engagement' | 'iap';\n rules: SKANConversionRule[];\n description: string;\n maxValue: number;\n}\n\nexport interface SKANMetrics {\n isSupported: boolean;\n version: string;\n currentValue: number | null;\n currentPreset: string | null;\n ruleCount: number;\n evaluationCount: number;\n}\n\n/**\n * The subset of the Rust core (`LayersCore`) the SKAN facade delegates to. The\n * core owns all rule evaluation, presets, and the monotonic floor.\n */\nexport interface SkanCore {\n skanSetPreset(preset: string): void;\n skanSetRules(rulesJson: string): void;\n skanProcessEvent(\n eventName: string,\n properties: Record<string, unknown> | null\n ): { fineValue: number; coarseValue: string | null; lockWindow: boolean } | null;\n skanRecordConversionResult(value: number, success: boolean): void;\n skanCurrentValue(): number;\n skanCurrentPreset(): string | null;\n skanIsEnabled(): boolean;\n}\n\ninterface NativeSKANModule {\n isAvailable(): Promise<boolean>;\n getVersion(): Promise<string>;\n registerAppForAdNetworkAttribution(): Promise<void>;\n updateConversionValue(value: number): Promise<void>;\n updatePostbackConversionValue(\n value: number,\n coarseValue?: string,\n lockWindow?: boolean\n ): Promise<void>;\n getCurrentConversionValue(): Promise<number | null>;\n}\n\nfunction getNativeModule(): NativeSKANModule | null {\n try {\n const { NativeModules, Platform } = require('react-native');\n if (Platform.OS === 'ios' && NativeModules.LayersSKAN) {\n return NativeModules.LayersSKAN as NativeSKANModule;\n }\n } catch {\n // Not available\n }\n return null;\n}\n\nlet sharedCore: SkanCore | null = null;\n\n/**\n * Wire the SKAN facade to the SDK's Rust core. Called by the SDK on init so that\n * a directly-constructed `new SKANManager()` and the SDK's own auto-config both\n * delegate to the same core engine.\n */\nexport function setSkanCore(core: SkanCore | null): void {\n sharedCore = core;\n}\n\n/**\n * Apply a native SKAN conversion update returned by the core, then report the\n * outcome so the core commits its monotonic floor only on success. Shared by the\n * facade and the SDK's track/screen forwarding.\n */\nexport async function applySkanDecision(\n core: SkanCore,\n native: NativeSKANModule | null,\n decision: { fineValue: number; coarseValue: string | null; lockWindow: boolean }\n): Promise<boolean> {\n if (!native) {\n // No native module (non-iOS / test): there is no postback to fail, so commit\n // the floor so the core's monotonic state stays consistent.\n core.skanRecordConversionResult(decision.fineValue, true);\n return true;\n }\n try {\n if (decision.coarseValue) {\n await native.updatePostbackConversionValue(\n decision.fineValue,\n decision.coarseValue,\n decision.lockWindow\n );\n } else {\n await native.updateConversionValue(decision.fineValue);\n }\n core.skanRecordConversionResult(decision.fineValue, true);\n return true;\n } catch {\n // Native update failed — the core leaves the floor unchanged so the next\n // matching event re-issues it (no silently-lost value).\n core.skanRecordConversionResult(decision.fineValue, false);\n return false;\n }\n}\n\nexport class SKANManager {\n private nativeModule: NativeSKANModule | null;\n private core: SkanCore | null;\n private evaluationCount = 0;\n private onConversionUpdate?: (data: {\n event: string;\n previousValue: number;\n newValue: number;\n rule: SKANConversionRule;\n }) => void;\n\n constructor(\n onConversionUpdate?: (data: {\n event: string;\n previousValue: number;\n newValue: number;\n rule: SKANConversionRule;\n }) => void,\n core?: SkanCore | null\n ) {\n this.nativeModule = getNativeModule();\n this.core = core ?? sharedCore;\n if (onConversionUpdate) {\n this.onConversionUpdate = onConversionUpdate;\n }\n }\n\n /**\n * Initialize the manager. `arm` controls whether Apple's postback window is\n * registered — pass `false` on re-config so we don't re-arm mid-session\n * (re-registering would reset the OS conversion value). Returns `true` only if\n * the native register was attempted and succeeded (a rejection throws; an\n * unavailable/no-module case returns false).\n */\n async initialize(arm = true): Promise<boolean> {\n if (!this.nativeModule) return false;\n const available = await this.nativeModule.isAvailable();\n if (!available) return false;\n if (arm) {\n await this.nativeModule.registerAppForAdNetworkAttribution();\n return true;\n }\n return false;\n }\n\n isSupported(): boolean {\n return this.nativeModule !== null;\n }\n\n /** Load a built-in preset in the core (subscriptions/engagement/iap). */\n setPreset(preset: string): void {\n this.core?.skanSetPreset(preset);\n }\n\n /** Replace the core's active rules with a custom set. */\n setCustomRules(rules: SKANConversionRule[]): void {\n this.core?.skanSetRules(JSON.stringify(rules));\n }\n\n /**\n * Evaluate an event via the core. If the core returns an update, apply it to\n * native SKAdNetwork and report the result back so the core commits its floor\n * only on success.\n */\n async processEvent(eventName: string, properties: Record<string, unknown>): Promise<void> {\n this.evaluationCount += 1;\n const core = this.core;\n if (!core) return;\n const previousValue = core.skanCurrentValue();\n const decision = core.skanProcessEvent(eventName, properties ?? {});\n if (!decision) return;\n const applied = await applySkanDecision(core, this.nativeModule, decision);\n // Only notify on a confirmed apply — a failed native postback leaves the\n // core's floor un-advanced, so the consumer must not see it as posted.\n if (!applied) return;\n this.onConversionUpdate?.({\n event: eventName,\n previousValue,\n newValue: decision.fineValue,\n rule: {\n eventName,\n conversionValue: decision.fineValue,\n lockWindow: decision.lockWindow,\n ...(decision.coarseValue\n ? { coarseValue: decision.coarseValue as 'low' | 'medium' | 'high' }\n : {})\n }\n });\n }\n\n /** The highest SKAN conversion value posted so far (from the core). */\n getCurrentValue(): number {\n return this.core?.skanCurrentValue() ?? 0;\n }\n\n /** The active preset name (from the core), or null. */\n getCurrentPreset(): string | null {\n return this.core?.skanCurrentPreset() ?? null;\n }\n\n /**\n * The active rules. The core owns the rule set and does not expose it, so this\n * returns an empty array; use the core's metrics for introspection.\n */\n getCurrentRules(): SKANConversionRule[] {\n return [];\n }\n\n getMetrics(): SKANMetrics {\n return {\n isSupported: this.isSupported(),\n version: '4.0',\n currentValue: this.core?.skanCurrentValue() ?? 0,\n currentPreset: this.core?.skanCurrentPreset() ?? null,\n ruleCount: 0,\n evaluationCount: this.evaluationCount\n };\n }\n}\n"],"mappings":";;;AAgEA,SAAS,kBAA2C;AAClD,KAAI;EACF,MAAM,EAAE,eAAe,uBAAqB,eAAe;AAC3D,MAAI,SAAS,OAAO,SAAS,cAAc,WACzC,QAAO,cAAc;SAEjB;AAGR,QAAO;;AAGT,IAAIA,aAA8B;;;;;;AAOlC,SAAgB,YAAY,MAA6B;AACvD,cAAa;;;;;;;AAQf,eAAsB,kBACpB,MACA,QACA,UACkB;AAClB,KAAI,CAAC,QAAQ;AAGX,OAAK,2BAA2B,SAAS,WAAW,KAAK;AACzD,SAAO;;AAET,KAAI;AACF,MAAI,SAAS,YACX,OAAM,OAAO,8BACX,SAAS,WACT,SAAS,aACT,SAAS,WACV;MAED,OAAM,OAAO,sBAAsB,SAAS,UAAU;AAExD,OAAK,2BAA2B,SAAS,WAAW,KAAK;AACzD,SAAO;SACD;AAGN,OAAK,2BAA2B,SAAS,WAAW,MAAM;AAC1D,SAAO;;;AAIX,IAAa,cAAb,MAAyB;CACvB,AAAQ;CACR,AAAQ;CACR,AAAQ,kBAAkB;CAC1B,AAAQ;CAOR,YACE,oBAMA,MACA;AACA,OAAK,eAAe,iBAAiB;AACrC,OAAK,OAAO,QAAQ;AACpB,MAAI,mBACF,MAAK,qBAAqB;;;;;;;;;CAW9B,MAAM,WAAW,MAAM,MAAwB;AAC7C,MAAI,CAAC,KAAK,aAAc,QAAO;AAE/B,MAAI,CADc,MAAM,KAAK,aAAa,aAAa,CACvC,QAAO;AACvB,MAAI,KAAK;AACP,SAAM,KAAK,aAAa,oCAAoC;AAC5D,UAAO;;AAET,SAAO;;CAGT,cAAuB;AACrB,SAAO,KAAK,iBAAiB;;;CAI/B,UAAU,QAAsB;AAC9B,OAAK,MAAM,cAAc,OAAO;;;CAIlC,eAAe,OAAmC;AAChD,OAAK,MAAM,aAAa,KAAK,UAAU,MAAM,CAAC;;;;;;;CAQhD,MAAM,aAAa,WAAmB,YAAoD;AACxF,OAAK,mBAAmB;EACxB,MAAM,OAAO,KAAK;AAClB,MAAI,CAAC,KAAM;EACX,MAAM,gBAAgB,KAAK,kBAAkB;EAC7C,MAAM,WAAW,KAAK,iBAAiB,WAAW,cAAc,EAAE,CAAC;AACnE,MAAI,CAAC,SAAU;AAIf,MAAI,CAHY,MAAM,kBAAkB,MAAM,KAAK,cAAc,SAAS,CAG5D;AACd,OAAK,qBAAqB;GACxB,OAAO;GACP;GACA,UAAU,SAAS;GACnB,MAAM;IACJ;IACA,iBAAiB,SAAS;IAC1B,YAAY,SAAS;IACrB,GAAI,SAAS,cACT,EAAE,aAAa,SAAS,aAA0C,GAClE,EAAE;IACP;GACF,CAAC;;;CAIJ,kBAA0B;AACxB,SAAO,KAAK,MAAM,kBAAkB,IAAI;;;CAI1C,mBAAkC;AAChC,SAAO,KAAK,MAAM,mBAAmB,IAAI;;;;;;CAO3C,kBAAwC;AACtC,SAAO,EAAE;;CAGX,aAA0B;AACxB,SAAO;GACL,aAAa,KAAK,aAAa;GAC/B,SAAS;GACT,cAAc,KAAK,MAAM,kBAAkB,IAAI;GAC/C,eAAe,KAAK,MAAM,mBAAmB,IAAI;GACjD,WAAW;GACX,iBAAiB,KAAK;GACvB"}
|