@layers/react-native 3.2.5 → 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/debug-overlay.d.mts +1 -1
- package/dist/debug-overlay.d.ts +1 -1
- package/dist/{index-NfkxionM.d.mts → index-BFkSi3wX.d.mts} +70 -2
- package/dist/{index-NfkxionM.d.mts.map → index-BFkSi3wX.d.mts.map} +1 -1
- package/dist/{index-D6lBf0N_.d.ts → index-BJ3l4nsV.d.ts} +70 -2
- package/dist/{index-D6lBf0N_.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-CiemkTIn.mjs → src-BRZ3Lfl5.mjs} +246 -24
- package/dist/src-BRZ3Lfl5.mjs.map +1 -0
- package/dist/{src-DvRveiFz.js → src-DPSm18ng.js} +245 -23
- 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
|
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,16 +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
1140
|
await this.restoreAttributionData();
|
|
1017
1141
|
await this.initializeDeviceInfo();
|
|
1142
|
+
if (this.initAborted(generation)) return;
|
|
1143
|
+
this._runtimeGeneration = generation;
|
|
1018
1144
|
this.setupAppStateListener();
|
|
1019
1145
|
this.setupNetInfoListener();
|
|
1020
1146
|
const mainThreadDurationMs = Date.now() - initStartTime;
|
|
1021
1147
|
await this.core.fetchRemoteConfig().catch(() => {});
|
|
1022
1148
|
await this.configureSkanFromRemoteConfig();
|
|
1149
|
+
if (this.initAborted(generation)) return;
|
|
1023
1150
|
this.startConfigPolling();
|
|
1024
1151
|
let clipboardData = null;
|
|
1025
1152
|
try {
|
|
@@ -1033,13 +1160,28 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1033
1160
|
if (clipboardEnabled) clipboardData = await readClipboardAttribution();
|
|
1034
1161
|
}
|
|
1035
1162
|
} catch {}
|
|
1163
|
+
if (this.initAborted(generation)) return;
|
|
1036
1164
|
if (this.config.autoTrackAppOpen !== false) {
|
|
1037
1165
|
const appOpenProps = {};
|
|
1038
1166
|
let isFirstLaunchByFlag = true;
|
|
1039
1167
|
try {
|
|
1040
1168
|
const AsyncStorage = await loadAsyncStorage();
|
|
1041
1169
|
if (AsyncStorage) {
|
|
1042
|
-
|
|
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 {}
|
|
1043
1185
|
}
|
|
1044
1186
|
} catch {}
|
|
1045
1187
|
const isFirstLaunch = await shouldTreatAsNewInstall(isFirstLaunchByFlag, this._hadPriorSdkState, this.enableDebug);
|
|
@@ -1048,10 +1190,6 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1048
1190
|
if (isFirstLaunch && !hasAttribution) try {
|
|
1049
1191
|
await this.resolveClickFromFingerprint();
|
|
1050
1192
|
} catch {}
|
|
1051
|
-
if (isFirstLaunch) try {
|
|
1052
|
-
const AsyncStorage = await loadAsyncStorage();
|
|
1053
|
-
if (AsyncStorage) await AsyncStorage.setItem(FIRST_LAUNCH_TRACKED_KEY, "true");
|
|
1054
|
-
} catch {}
|
|
1055
1193
|
if (clipboardData) {
|
|
1056
1194
|
appOpenProps.clipboard_attribution_url = clipboardData.clickUrl;
|
|
1057
1195
|
appOpenProps.clipboard_click_id = clipboardData.clickId;
|
|
@@ -1065,8 +1203,13 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1065
1203
|
if (this._installReferrerParams) {
|
|
1066
1204
|
for (const [key, value] of Object.entries(this._installReferrerParams)) if (appOpenProps[key] === void 0) appOpenProps[key] = value;
|
|
1067
1205
|
}
|
|
1206
|
+
if (this.initAborted(generation)) return;
|
|
1068
1207
|
if (isFirstLaunch) this.track("app_install", appOpenProps);
|
|
1069
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 {}
|
|
1070
1213
|
if (this.config.autoTrackAppUpdate !== false) try {
|
|
1071
1214
|
const currentVersion = this.core.getDeviceContext().appVersion ?? appOpenProps.app_version;
|
|
1072
1215
|
if (currentVersion && typeof currentVersion === "string") {
|
|
@@ -1082,6 +1225,7 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1082
1225
|
}
|
|
1083
1226
|
} catch {}
|
|
1084
1227
|
}
|
|
1228
|
+
if (this.initAborted(generation)) return;
|
|
1085
1229
|
if (this.config.autoTrackDeepLinks !== false) this.setupDeepLinkAutoTracking();
|
|
1086
1230
|
this._isInitialized = true;
|
|
1087
1231
|
const totalDurationMs = Date.now() - initStartTime;
|
|
@@ -1332,6 +1476,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1332
1476
|
* Returns the ATT status string.
|
|
1333
1477
|
*/
|
|
1334
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
|
+
}
|
|
1335
1483
|
let status;
|
|
1336
1484
|
try {
|
|
1337
1485
|
const ExpoTT = await Promise.resolve().then(() => require("./TrackingTransparency-D6ybvQzE.js")).catch(() => null);
|
|
@@ -1660,6 +1808,29 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1660
1808
|
if (this.enableDebug && this.errorListeners.size === 0) console.warn("[Layers]", err.message);
|
|
1661
1809
|
}
|
|
1662
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() {
|
|
1663
1834
|
this.stopConfigPolling();
|
|
1664
1835
|
if (this.appStateSubscription) {
|
|
1665
1836
|
this.appStateSubscription.remove();
|
|
@@ -1673,17 +1844,9 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1673
1844
|
this.deepLinkUnsubscribe();
|
|
1674
1845
|
this.deepLinkUnsubscribe = null;
|
|
1675
1846
|
}
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
this._attributionFbc = null;
|
|
1680
|
-
this._attributionTtclid = null;
|
|
1681
|
-
this._attributionMsclkid = null;
|
|
1682
|
-
this._initListener = null;
|
|
1683
|
-
this._skanManager = null;
|
|
1684
|
-
this._skanArmed = false;
|
|
1685
|
-
require_skan.setSkanCore(null);
|
|
1686
|
-
this.core.shutdown();
|
|
1847
|
+
try {
|
|
1848
|
+
this.core.shutdown();
|
|
1849
|
+
} catch {}
|
|
1687
1850
|
}
|
|
1688
1851
|
/**
|
|
1689
1852
|
* Store attribution data that will be attached to all subsequent events.
|
|
@@ -1797,6 +1960,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1797
1960
|
}
|
|
1798
1961
|
_trackedDeepLinkUrls = /* @__PURE__ */ new Set();
|
|
1799
1962
|
setupDeepLinkAutoTracking() {
|
|
1963
|
+
if (this.deepLinkUnsubscribe) {
|
|
1964
|
+
this.deepLinkUnsubscribe();
|
|
1965
|
+
this.deepLinkUnsubscribe = null;
|
|
1966
|
+
}
|
|
1800
1967
|
this.deepLinkUnsubscribe = setupDeepLinkListener((data) => {
|
|
1801
1968
|
if (this._trackedDeepLinkUrls.has(data.url)) return;
|
|
1802
1969
|
this._trackedDeepLinkUrls.add(data.url);
|
|
@@ -1928,6 +2095,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1928
2095
|
} catch {}
|
|
1929
2096
|
}
|
|
1930
2097
|
setupAppStateListener() {
|
|
2098
|
+
if (this.appStateSubscription) {
|
|
2099
|
+
this.appStateSubscription.remove();
|
|
2100
|
+
this.appStateSubscription = null;
|
|
2101
|
+
}
|
|
1931
2102
|
try {
|
|
1932
2103
|
const { AppState } = require("react-native");
|
|
1933
2104
|
let lastEmittedState = null;
|
|
@@ -1948,7 +2119,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1948
2119
|
if (this.isOnline) this.core.flushAsync().catch(() => {});
|
|
1949
2120
|
}
|
|
1950
2121
|
});
|
|
1951
|
-
} 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
|
+
}
|
|
1952
2126
|
}
|
|
1953
2127
|
async configureSkanFromRemoteConfig() {
|
|
1954
2128
|
try {
|
|
@@ -1988,6 +2162,10 @@ var LayersReactNative = class LayersReactNative {
|
|
|
1988
2162
|
} catch {}
|
|
1989
2163
|
}
|
|
1990
2164
|
setupNetInfoListener() {
|
|
2165
|
+
if (this.netInfoUnsubscribe) {
|
|
2166
|
+
this.netInfoUnsubscribe();
|
|
2167
|
+
this.netInfoUnsubscribe = null;
|
|
2168
|
+
}
|
|
1991
2169
|
try {
|
|
1992
2170
|
this.netInfoUnsubscribe = require("@react-native-community/netinfo").addEventListener((state) => {
|
|
1993
2171
|
const wasOffline = !this.isOnline;
|
|
@@ -2110,7 +2288,23 @@ function getLocale() {
|
|
|
2110
2288
|
return "en-US";
|
|
2111
2289
|
}
|
|
2112
2290
|
const INSTALL_ID_KEY = "layers_install_id";
|
|
2113
|
-
|
|
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
|
+
}
|
|
2114
2308
|
/**
|
|
2115
2309
|
* Last-known app_version persisted across launches. Used to detect
|
|
2116
2310
|
* `$app_update` (version increment) vs. `$first_open` (no prior value).
|
|
@@ -2124,17 +2318,34 @@ const LAST_APP_VERSION_KEY = "@layers/last_app_version";
|
|
|
2124
2318
|
* new install — and suppresses `is_first_launch = true`.
|
|
2125
2319
|
*/
|
|
2126
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
|
+
}
|
|
2127
2338
|
async function getOrSetInstallId() {
|
|
2128
2339
|
try {
|
|
2129
2340
|
const AsyncStorage = await loadAsyncStorage();
|
|
2130
|
-
if (!AsyncStorage) return
|
|
2341
|
+
if (!AsyncStorage) return ephemeralInstallId();
|
|
2131
2342
|
const existing = await AsyncStorage.getItem(INSTALL_ID_KEY);
|
|
2132
2343
|
if (existing) return existing;
|
|
2133
2344
|
const newId = generateUUID();
|
|
2134
2345
|
await AsyncStorage.setItem(INSTALL_ID_KEY, newId);
|
|
2135
2346
|
return newId;
|
|
2136
2347
|
} catch {
|
|
2137
|
-
return
|
|
2348
|
+
return ephemeralInstallId();
|
|
2138
2349
|
}
|
|
2139
2350
|
}
|
|
2140
2351
|
function generateUUID() {
|
|
@@ -2417,6 +2628,7 @@ function parseDeepLink(url) {
|
|
|
2417
2628
|
}
|
|
2418
2629
|
}
|
|
2419
2630
|
const _expoRouterPreviousPath = /* @__PURE__ */ new WeakMap();
|
|
2631
|
+
const _expoRouterLastTracked = /* @__PURE__ */ new WeakMap();
|
|
2420
2632
|
/**
|
|
2421
2633
|
* Hook that emits `$screen_view` for every Expo Router pathname change.
|
|
2422
2634
|
*
|
|
@@ -2427,11 +2639,16 @@ const _expoRouterPreviousPath = /* @__PURE__ */ new WeakMap();
|
|
|
2427
2639
|
* — no need to join adjacent rows.
|
|
2428
2640
|
*/
|
|
2429
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).");
|
|
2430
2643
|
const { useEffect } = require("react");
|
|
2431
2644
|
const pathname = usePathname();
|
|
2432
2645
|
const params = useGlobalSearchParams();
|
|
2646
|
+
const paramsString = JSON.stringify(params);
|
|
2433
2647
|
useEffect(() => {
|
|
2648
|
+
if (sdkInstance == null) return;
|
|
2434
2649
|
if (pathname) {
|
|
2650
|
+
const routeKey = `${pathname}${paramsString}`;
|
|
2651
|
+
if (_expoRouterLastTracked.get(sdkInstance) === routeKey) return;
|
|
2435
2652
|
const properties = {};
|
|
2436
2653
|
Object.entries(params).forEach(([key, value]) => {
|
|
2437
2654
|
properties[key] = Array.isArray(value) ? value.join(",") : value;
|
|
@@ -2440,8 +2657,13 @@ function useLayersExpoRouterTracking(sdkInstance, usePathname, useGlobalSearchPa
|
|
|
2440
2657
|
if (previous && previous !== pathname) properties.previous_screen_name = previous;
|
|
2441
2658
|
sdkInstance.screen(pathname, properties);
|
|
2442
2659
|
_expoRouterPreviousPath.set(sdkInstance, pathname);
|
|
2660
|
+
_expoRouterLastTracked.set(sdkInstance, routeKey);
|
|
2443
2661
|
}
|
|
2444
|
-
}, [
|
|
2662
|
+
}, [
|
|
2663
|
+
sdkInstance,
|
|
2664
|
+
pathname,
|
|
2665
|
+
paramsString
|
|
2666
|
+
]);
|
|
2445
2667
|
}
|
|
2446
2668
|
|
|
2447
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"}
|