@layers/react-native 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +380 -149
- package/dist/TrackingTransparency-CMedp3bh.js +321 -0
- package/dist/TrackingTransparency-CMedp3bh.js.map +1 -0
- package/dist/{att-Hyj9b7AG.d.ts → att-BlUZv4_u.d.ts} +1 -1
- package/dist/{att-Hyj9b7AG.d.ts.map → att-BlUZv4_u.d.ts.map} +1 -1
- package/dist/{att-C5tL1hKX.js → att-DaUoQWpj.js} +2 -2
- package/dist/{att-C5tL1hKX.js.map → att-DaUoQWpj.js.map} +1 -1
- package/dist/att.d.ts +1 -1
- package/dist/att.js +1 -1
- package/dist/chunk-DyChAoct.js +27 -0
- package/dist/index-CSCJSzRS.d.ts +181 -0
- package/dist/index-CSCJSzRS.d.ts.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/react.d.ts +3 -3
- package/dist/react.js +3 -3
- package/dist/{skan-_aDXcXWQ.js → skan-DFFAN4wu.js} +2 -2
- package/dist/{skan-_aDXcXWQ.js.map → skan-DFFAN4wu.js.map} +1 -1
- package/dist/{skan-C-RMfcG8.d.ts → skan-DvnRgJo1.d.ts} +1 -1
- package/dist/{skan-C-RMfcG8.d.ts.map → skan-DvnRgJo1.d.ts.map} +1 -1
- package/dist/skan.d.ts +1 -1
- package/dist/skan.js +1 -1
- package/dist/{src-B_57eFbh.js → src-DTBDULvf.js} +258 -11
- package/dist/src-DTBDULvf.js.map +1 -0
- package/package.json +2 -2
- package/dist/chunk-B1JASekH.js +0 -7
- package/dist/index-yowJkVyZ.d.ts +0 -88
- package/dist/index-yowJkVyZ.d.ts.map +0 -1
- package/dist/src-B_57eFbh.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as requestTrackingAuthorization, i as isATTAvailable, n as getAdvertisingId, r as getVendorId, t as getATTStatus } from "./att-
|
|
2
|
-
import { t as SKANManager } from "./skan-
|
|
3
|
-
import { a as readClipboardAttribution, i as
|
|
1
|
+
import { a as requestTrackingAuthorization, i as isATTAvailable, n as getAdvertisingId, r as getVendorId, t as getATTStatus } from "./att-DaUoQWpj.js";
|
|
2
|
+
import { t as SKANManager } from "./skan-DFFAN4wu.js";
|
|
3
|
+
import { a as getInstallReferrer, c as readClipboardAttribution, i as getGoogleAdvertisingId, l as setupDeepLinkListener, n as LayersReactNative, o as getOrSetInstallId, r as getAdServicesToken, s as parseDeepLink, t as LayersError, u as useLayersExpoRouterTracking } from "./src-DTBDULvf.js";
|
|
4
4
|
|
|
5
|
-
export { LayersError, LayersReactNative, SKANManager, getATTStatus, getAdvertisingId, getOrSetInstallId, getVendorId, isATTAvailable, parseDeepLink, readClipboardAttribution, requestTrackingAuthorization, setupDeepLinkListener, useLayersExpoRouterTracking };
|
|
5
|
+
export { LayersError, LayersReactNative, SKANManager, getATTStatus, getAdServicesToken, getAdvertisingId, getGoogleAdvertisingId, getInstallReferrer, getOrSetInstallId, getVendorId, isATTAvailable, parseDeepLink, readClipboardAttribution, requestTrackingAuthorization, setupDeepLinkListener, useLayersExpoRouterTracking };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./att-
|
|
2
|
-
import "./skan-
|
|
3
|
-
import {
|
|
1
|
+
import "./att-BlUZv4_u.js";
|
|
2
|
+
import "./skan-DvnRgJo1.js";
|
|
3
|
+
import { d as LayersRNConfig, f as LayersReactNative, n as ConsentState, s as EventProperties } from "./index-CSCJSzRS.js";
|
|
4
4
|
import { ReactNode } from "react";
|
|
5
5
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
6
6
|
|
package/dist/react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./att-
|
|
2
|
-
import "./skan-
|
|
3
|
-
import { n as LayersReactNative } from "./src-
|
|
1
|
+
import "./att-DaUoQWpj.js";
|
|
2
|
+
import "./skan-DFFAN4wu.js";
|
|
3
|
+
import { n as LayersReactNative } from "./src-DTBDULvf.js";
|
|
4
4
|
import { createContext, useCallback, useContext, useEffect, useRef } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as __require } from "./chunk-
|
|
1
|
+
import { t as __require } from "./chunk-DyChAoct.js";
|
|
2
2
|
|
|
3
3
|
//#region src/skan.ts
|
|
4
4
|
function getNativeModule() {
|
|
@@ -250,4 +250,4 @@ function getPresetConfig(preset) {
|
|
|
250
250
|
|
|
251
251
|
//#endregion
|
|
252
252
|
export { SKANManager as t };
|
|
253
|
-
//# sourceMappingURL=skan-
|
|
253
|
+
//# sourceMappingURL=skan-DFFAN4wu.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skan-_aDXcXWQ.js","names":["matchedRule: SKANConversionRule | undefined"],"sources":["../src/skan.ts"],"sourcesContent":["// SKAN Module — iOS-only SKAdNetwork conversion value management.\n// Keeps the JS rule engine for evaluating events against conversion rules\n// and bridging to native iOS SKAdNetwork APIs via NativeModules.\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\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\nexport class SKANManager {\n private rules: SKANConversionRule[] = [];\n private currentPreset: string | null = null;\n private currentValue = 0;\n private evaluationCount = 0;\n private nativeModule: NativeSKANModule | null;\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 ) {\n this.nativeModule = getNativeModule();\n if (onConversionUpdate) {\n this.onConversionUpdate = onConversionUpdate;\n }\n }\n\n async initialize(): Promise<void> {\n if (!this.nativeModule) return;\n const available = await this.nativeModule.isAvailable();\n if (available) {\n await this.nativeModule.registerAppForAdNetworkAttribution();\n const val = await this.nativeModule.getCurrentConversionValue();\n if (val !== null) this.currentValue = val;\n }\n }\n\n isSupported(): boolean {\n return this.nativeModule !== null;\n }\n\n setPreset(preset: 'subscriptions' | 'engagement' | 'iap'): void {\n const config = getPresetConfig(preset);\n this.rules = config.rules.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));\n this.currentPreset = preset;\n }\n\n setCustomRules(rules: SKANConversionRule[]): void {\n this.rules = rules.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));\n this.currentPreset = 'custom';\n }\n\n async processEvent(eventName: string, properties: Record<string, unknown>): Promise<void> {\n this.evaluationCount += 1;\n\n let matchedRule: SKANConversionRule | undefined;\n\n for (const rule of this.rules) {\n if (evaluateRule(rule, eventName, properties)) {\n matchedRule = rule;\n break; // First match (highest priority) wins\n }\n }\n\n if (!matchedRule || matchedRule.conversionValue <= this.currentValue) {\n return;\n }\n\n const previousValue = this.currentValue;\n this.currentValue = matchedRule.conversionValue;\n\n // Update native SKAN\n if (this.nativeModule) {\n try {\n if (matchedRule.coarseValue) {\n await this.nativeModule.updatePostbackConversionValue(\n matchedRule.conversionValue,\n matchedRule.coarseValue,\n matchedRule.lockWindow\n );\n } else {\n await this.nativeModule.updateConversionValue(matchedRule.conversionValue);\n }\n } catch {\n // Native update failed — keep JS state updated\n }\n }\n\n this.onConversionUpdate?.({\n event: eventName,\n previousValue,\n newValue: matchedRule.conversionValue,\n rule: matchedRule\n });\n }\n\n getCurrentValue(): number {\n return this.currentValue;\n }\n\n getCurrentPreset(): string | null {\n return this.currentPreset;\n }\n\n getCurrentRules(): SKANConversionRule[] {\n return [...this.rules];\n }\n\n getMetrics(): SKANMetrics {\n return {\n isSupported: this.isSupported(),\n version: '4.0',\n currentValue: this.currentValue,\n currentPreset: this.currentPreset,\n ruleCount: this.rules.length,\n evaluationCount: this.evaluationCount\n };\n }\n}\n\n// --- Rule evaluation engine ---\n\nfunction evaluateRule(\n rule: SKANConversionRule,\n eventName: string,\n properties: Record<string, unknown>\n): boolean {\n if (rule.eventName !== eventName) return false;\n\n if (!rule.conditions) return true;\n\n for (const [key, expected] of Object.entries(rule.conditions)) {\n const actual = properties[key];\n\n if (typeof expected === 'object' && expected !== null && !Array.isArray(expected)) {\n // Operator-based condition: { '>': 10, '<': 100 }\n for (const [op, val] of Object.entries(expected as Record<string, unknown>)) {\n if (!evaluateOperator(actual, op, val)) return false;\n }\n } else if (actual !== expected) {\n // Direct equality\n return false;\n }\n }\n\n return true;\n}\n\nfunction evaluateOperator(actual: unknown, operator: string, expected: unknown): boolean {\n const a = Number(actual);\n const b = Number(expected);\n\n switch (operator) {\n case '>':\n return a > b;\n case '>=':\n return a >= b;\n case '<':\n return a < b;\n case '<=':\n return a <= b;\n case '==':\n case '=':\n return actual === expected;\n case '!=':\n return actual !== expected;\n default:\n return false;\n }\n}\n\n// --- Preset configurations ---\n\nfunction getPresetConfig(preset: 'subscriptions' | 'engagement' | 'iap'): SKANPresetConfig {\n switch (preset) {\n case 'subscriptions':\n return {\n name: 'subscriptions',\n description: 'Optimized for subscription apps with trial-to-paid conversion tracking',\n maxValue: 63,\n rules: [\n { eventName: 'app_open', conversionValue: 1, priority: 1, description: 'App opened' },\n {\n eventName: 'screen_view',\n conditions: { screen_name: 'onboarding_complete' },\n conversionValue: 8,\n priority: 3,\n description: 'Onboarding completed'\n },\n {\n eventName: 'trial_start',\n conversionValue: 20,\n priority: 5,\n description: 'Free trial started'\n },\n {\n eventName: 'purchase_success',\n conditions: { revenue: { '<': 5 } },\n conversionValue: 35,\n priority: 7,\n description: 'Small purchase (<$5)'\n },\n {\n eventName: 'subscription_start',\n conversionValue: 50,\n priority: 10,\n description: 'Subscription started'\n },\n {\n eventName: 'subscription_renew',\n conversionValue: 63,\n priority: 15,\n description: 'Subscription renewed'\n }\n ]\n };\n case 'engagement':\n return {\n name: 'engagement',\n description: 'Optimized for engagement-driven apps',\n maxValue: 63,\n rules: [\n { eventName: 'app_open', conversionValue: 1, priority: 1, description: 'App opened' },\n {\n eventName: 'content_open',\n conversionValue: 5,\n priority: 2,\n description: 'Content viewed'\n },\n {\n eventName: 'search',\n conversionValue: 12,\n priority: 4,\n description: 'Search performed'\n },\n {\n eventName: 'bookmark_add',\n conversionValue: 25,\n priority: 6,\n description: 'Content bookmarked'\n },\n {\n eventName: 'app_open',\n conditions: { session_count: { '>': 3 } },\n conversionValue: 40,\n priority: 8,\n description: 'Regular user (3+ sessions)'\n },\n {\n eventName: 'app_open',\n conditions: { session_count: { '>': 10 } },\n conversionValue: 63,\n priority: 12,\n description: 'Power user (10+ sessions)'\n }\n ]\n };\n case 'iap':\n return {\n name: 'iap',\n description: 'Optimized for in-app purchase revenue tracking',\n maxValue: 63,\n rules: [\n { eventName: 'app_open', conversionValue: 1, priority: 1, description: 'App opened' },\n {\n eventName: 'paywall_show',\n conversionValue: 8,\n priority: 2,\n description: 'Paywall shown'\n },\n {\n eventName: 'purchase_attempt',\n conversionValue: 15,\n priority: 3,\n description: 'Purchase attempted'\n },\n {\n eventName: 'purchase_success',\n conditions: { revenue: { '<': 1 } },\n conversionValue: 25,\n priority: 5,\n description: 'Small purchase (<$1)'\n },\n {\n eventName: 'purchase_success',\n conditions: { revenue: { '>=': 1, '<': 10 } },\n conversionValue: 40,\n priority: 7,\n description: 'Medium purchase ($1-$10)'\n },\n {\n eventName: 'purchase_success',\n conditions: { revenue: { '>=': 10 } },\n conversionValue: 63,\n priority: 10,\n description: 'Large purchase ($10+)'\n }\n ]\n };\n }\n}\n"],"mappings":";;;AA2CA,SAAS,kBAA2C;AAClD,KAAI;EACF,MAAM,EAAE,eAAe,uBAAqB,eAAe;AAC3D,MAAI,SAAS,OAAO,SAAS,cAAc,WACzC,QAAO,cAAc;SAEjB;AAGR,QAAO;;AAGT,IAAa,cAAb,MAAyB;CACvB,AAAQ,QAA8B,EAAE;CACxC,AAAQ,gBAA+B;CACvC,AAAQ,eAAe;CACvB,AAAQ,kBAAkB;CAC1B,AAAQ;CACR,AAAQ;CAOR,YACE,oBAMA;AACA,OAAK,eAAe,iBAAiB;AACrC,MAAI,mBACF,MAAK,qBAAqB;;CAI9B,MAAM,aAA4B;AAChC,MAAI,CAAC,KAAK,aAAc;AAExB,MADkB,MAAM,KAAK,aAAa,aAAa,EACxC;AACb,SAAM,KAAK,aAAa,oCAAoC;GAC5D,MAAM,MAAM,MAAM,KAAK,aAAa,2BAA2B;AAC/D,OAAI,QAAQ,KAAM,MAAK,eAAe;;;CAI1C,cAAuB;AACrB,SAAO,KAAK,iBAAiB;;CAG/B,UAAU,QAAsD;AAE9D,OAAK,QADU,gBAAgB,OAAO,CAClB,MAAM,MAAM,GAAG,OAAO,EAAE,YAAY,MAAM,EAAE,YAAY,GAAG;AAC/E,OAAK,gBAAgB;;CAGvB,eAAe,OAAmC;AAChD,OAAK,QAAQ,MAAM,MAAM,GAAG,OAAO,EAAE,YAAY,MAA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AG,EAAE;KACzC,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,YAAY,EAAE,eAAe,EAAE,KAAK,IAAI,EAAE;KAC1C,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACF;GACF;EACH,KAAK,MACH,QAAO;GACL,MAAM;GACN,aAAa;GACb,UAAU;GACV,OAAO;IACL;KAAE,WAAW;KAAY,iBAAiB;KAAG,UAAU;KAAG,aAAa;KAAc;IACrF;KACE,WAAW;KACX,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,YAAY,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE;KACnC,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,YAAY,EAAE,SAAS;MAAE,MAAM;MAAG,KAAK;MAAI,EAAE;KAC7C,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,YAAY,EAAE,SAAS,EAAE,MAAM,IAAI,EAAE;KACrC,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACF;GACF"}
|
|
1
|
+
{"version":3,"file":"skan-DFFAN4wu.js","names":["matchedRule: SKANConversionRule | undefined"],"sources":["../src/skan.ts"],"sourcesContent":["// SKAN Module — iOS-only SKAdNetwork conversion value management.\n// Keeps the JS rule engine for evaluating events against conversion rules\n// and bridging to native iOS SKAdNetwork APIs via NativeModules.\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\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\nexport class SKANManager {\n private rules: SKANConversionRule[] = [];\n private currentPreset: string | null = null;\n private currentValue = 0;\n private evaluationCount = 0;\n private nativeModule: NativeSKANModule | null;\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 ) {\n this.nativeModule = getNativeModule();\n if (onConversionUpdate) {\n this.onConversionUpdate = onConversionUpdate;\n }\n }\n\n async initialize(): Promise<void> {\n if (!this.nativeModule) return;\n const available = await this.nativeModule.isAvailable();\n if (available) {\n await this.nativeModule.registerAppForAdNetworkAttribution();\n const val = await this.nativeModule.getCurrentConversionValue();\n if (val !== null) this.currentValue = val;\n }\n }\n\n isSupported(): boolean {\n return this.nativeModule !== null;\n }\n\n setPreset(preset: 'subscriptions' | 'engagement' | 'iap'): void {\n const config = getPresetConfig(preset);\n this.rules = config.rules.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));\n this.currentPreset = preset;\n }\n\n setCustomRules(rules: SKANConversionRule[]): void {\n this.rules = rules.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));\n this.currentPreset = 'custom';\n }\n\n async processEvent(eventName: string, properties: Record<string, unknown>): Promise<void> {\n this.evaluationCount += 1;\n\n let matchedRule: SKANConversionRule | undefined;\n\n for (const rule of this.rules) {\n if (evaluateRule(rule, eventName, properties)) {\n matchedRule = rule;\n break; // First match (highest priority) wins\n }\n }\n\n if (!matchedRule || matchedRule.conversionValue <= this.currentValue) {\n return;\n }\n\n const previousValue = this.currentValue;\n this.currentValue = matchedRule.conversionValue;\n\n // Update native SKAN\n if (this.nativeModule) {\n try {\n if (matchedRule.coarseValue) {\n await this.nativeModule.updatePostbackConversionValue(\n matchedRule.conversionValue,\n matchedRule.coarseValue,\n matchedRule.lockWindow\n );\n } else {\n await this.nativeModule.updateConversionValue(matchedRule.conversionValue);\n }\n } catch {\n // Native update failed — keep JS state updated\n }\n }\n\n this.onConversionUpdate?.({\n event: eventName,\n previousValue,\n newValue: matchedRule.conversionValue,\n rule: matchedRule\n });\n }\n\n getCurrentValue(): number {\n return this.currentValue;\n }\n\n getCurrentPreset(): string | null {\n return this.currentPreset;\n }\n\n getCurrentRules(): SKANConversionRule[] {\n return [...this.rules];\n }\n\n getMetrics(): SKANMetrics {\n return {\n isSupported: this.isSupported(),\n version: '4.0',\n currentValue: this.currentValue,\n currentPreset: this.currentPreset,\n ruleCount: this.rules.length,\n evaluationCount: this.evaluationCount\n };\n }\n}\n\n// --- Rule evaluation engine ---\n\nfunction evaluateRule(\n rule: SKANConversionRule,\n eventName: string,\n properties: Record<string, unknown>\n): boolean {\n if (rule.eventName !== eventName) return false;\n\n if (!rule.conditions) return true;\n\n for (const [key, expected] of Object.entries(rule.conditions)) {\n const actual = properties[key];\n\n if (typeof expected === 'object' && expected !== null && !Array.isArray(expected)) {\n // Operator-based condition: { '>': 10, '<': 100 }\n for (const [op, val] of Object.entries(expected as Record<string, unknown>)) {\n if (!evaluateOperator(actual, op, val)) return false;\n }\n } else if (actual !== expected) {\n // Direct equality\n return false;\n }\n }\n\n return true;\n}\n\nfunction evaluateOperator(actual: unknown, operator: string, expected: unknown): boolean {\n const a = Number(actual);\n const b = Number(expected);\n\n switch (operator) {\n case '>':\n return a > b;\n case '>=':\n return a >= b;\n case '<':\n return a < b;\n case '<=':\n return a <= b;\n case '==':\n case '=':\n return actual === expected;\n case '!=':\n return actual !== expected;\n default:\n return false;\n }\n}\n\n// --- Preset configurations ---\n\nfunction getPresetConfig(preset: 'subscriptions' | 'engagement' | 'iap'): SKANPresetConfig {\n switch (preset) {\n case 'subscriptions':\n return {\n name: 'subscriptions',\n description: 'Optimized for subscription apps with trial-to-paid conversion tracking',\n maxValue: 63,\n rules: [\n { eventName: 'app_open', conversionValue: 1, priority: 1, description: 'App opened' },\n {\n eventName: 'screen_view',\n conditions: { screen_name: 'onboarding_complete' },\n conversionValue: 8,\n priority: 3,\n description: 'Onboarding completed'\n },\n {\n eventName: 'trial_start',\n conversionValue: 20,\n priority: 5,\n description: 'Free trial started'\n },\n {\n eventName: 'purchase_success',\n conditions: { revenue: { '<': 5 } },\n conversionValue: 35,\n priority: 7,\n description: 'Small purchase (<$5)'\n },\n {\n eventName: 'subscription_start',\n conversionValue: 50,\n priority: 10,\n description: 'Subscription started'\n },\n {\n eventName: 'subscription_renew',\n conversionValue: 63,\n priority: 15,\n description: 'Subscription renewed'\n }\n ]\n };\n case 'engagement':\n return {\n name: 'engagement',\n description: 'Optimized for engagement-driven apps',\n maxValue: 63,\n rules: [\n { eventName: 'app_open', conversionValue: 1, priority: 1, description: 'App opened' },\n {\n eventName: 'content_open',\n conversionValue: 5,\n priority: 2,\n description: 'Content viewed'\n },\n {\n eventName: 'search',\n conversionValue: 12,\n priority: 4,\n description: 'Search performed'\n },\n {\n eventName: 'bookmark_add',\n conversionValue: 25,\n priority: 6,\n description: 'Content bookmarked'\n },\n {\n eventName: 'app_open',\n conditions: { session_count: { '>': 3 } },\n conversionValue: 40,\n priority: 8,\n description: 'Regular user (3+ sessions)'\n },\n {\n eventName: 'app_open',\n conditions: { session_count: { '>': 10 } },\n conversionValue: 63,\n priority: 12,\n description: 'Power user (10+ sessions)'\n }\n ]\n };\n case 'iap':\n return {\n name: 'iap',\n description: 'Optimized for in-app purchase revenue tracking',\n maxValue: 63,\n rules: [\n { eventName: 'app_open', conversionValue: 1, priority: 1, description: 'App opened' },\n {\n eventName: 'paywall_show',\n conversionValue: 8,\n priority: 2,\n description: 'Paywall shown'\n },\n {\n eventName: 'purchase_attempt',\n conversionValue: 15,\n priority: 3,\n description: 'Purchase attempted'\n },\n {\n eventName: 'purchase_success',\n conditions: { revenue: { '<': 1 } },\n conversionValue: 25,\n priority: 5,\n description: 'Small purchase (<$1)'\n },\n {\n eventName: 'purchase_success',\n conditions: { revenue: { '>=': 1, '<': 10 } },\n conversionValue: 40,\n priority: 7,\n description: 'Medium purchase ($1-$10)'\n },\n {\n eventName: 'purchase_success',\n conditions: { revenue: { '>=': 10 } },\n conversionValue: 63,\n priority: 10,\n description: 'Large purchase ($10+)'\n }\n ]\n };\n }\n}\n"],"mappings":";;;AA2CA,SAAS,kBAA2C;AAClD,KAAI;EACF,MAAM,EAAE,eAAe,uBAAqB,eAAe;AAC3D,MAAI,SAAS,OAAO,SAAS,cAAc,WACzC,QAAO,cAAc;SAEjB;AAGR,QAAO;;AAGT,IAAa,cAAb,MAAyB;CACvB,AAAQ,QAA8B,EAAE;CACxC,AAAQ,gBAA+B;CACvC,AAAQ,eAAe;CACvB,AAAQ,kBAAkB;CAC1B,AAAQ;CACR,AAAQ;CAOR,YACE,oBAMA;AACA,OAAK,eAAe,iBAAiB;AACrC,MAAI,mBACF,MAAK,qBAAqB;;CAI9B,MAAM,aAA4B;AAChC,MAAI,CAAC,KAAK,aAAc;AAExB,MADkB,MAAM,KAAK,aAAa,aAAa,EACxC;AACb,SAAM,KAAK,aAAa,oCAAoC;GAC5D,MAAM,MAAM,MAAM,KAAK,aAAa,2BAA2B;AAC/D,OAAI,QAAQ,KAAM,MAAK,eAAe;;;CAI1C,cAAuB;AACrB,SAAO,KAAK,iBAAi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;IACrF;KACE,WAAW;KACX,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,YAAY,EAAE,eAAe,EAAE,KAAK,GAAG,EAAE;KACzC,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,YAAY,EAAE,eAAe,EAAE,KAAK,IAAI,EAAE;KAC1C,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACF;GACF;EACH,KAAK,MACH,QAAO;GACL,MAAM;GACN,aAAa;GACb,UAAU;GACV,OAAO;IACL;KAAE,WAAW;KAAY,iBAAiB;KAAG,UAAU;KAAG,aAAa;KAAc;IACrF;KACE,WAAW;KACX,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,YAAY,EAAE,SAAS,EAAE,KAAK,GAAG,EAAE;KACnC,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,YAAY,EAAE,SAAS;MAAE,MAAM;MAAG,KAAK;MAAI,EAAE;KAC7C,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACD;KACE,WAAW;KACX,YAAY,EAAE,SAAS,EAAE,MAAM,IAAI,EAAE;KACrC,iBAAiB;KACjB,UAAU;KACV,aAAa;KACd;IACF;GACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skan-
|
|
1
|
+
{"version":3,"file":"skan-DvnRgJo1.d.ts","names":[],"sources":["../src/skan.ts"],"sourcesContent":[],"mappings":";UAIiB,kBAAA;EAAA,SAAA,EAAA,MAAA;EAUA,UAAA,CAAA,EARF,MAQkB,CAAA,MAAA,EAAA,OAExB,CAAA;EAKQ,eAAW,EAAA,MAAA;EAkCf,WAAA,CAAA,EAAW,KAAA,GAAA,QAAA,GAAA,MAAA;EAkBZ,UAAA,CAAA,EAAA,OAAA;EASU,QAAA,CAAA,EAAA,MAAA;EAoBE,WAAA,CAAA,EAAA,MAAA;;AAKsD,UA7F7D,gBAAA,CA6F6D;EAoDzD,IAAA,EAAA,eAAA,GAAA,YAAA,GAAA,KAAA;EAIL,KAAA,EAnJP,kBAmJO,EAAA;EAAW,WAAA,EAAA,MAAA;;;UA9IV,WAAA;;;;;;;;cAkCJ,WAAA;;;;;;;;;;;UAkBD;;gBASU;;;wBAoBE;8CAK4B,0BAA0B;;;qBAoDzD;gBAIL"}
|
package/dist/skan.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as SKANPresetConfig, n as SKANManager, r as SKANMetrics, t as SKANConversionRule } from "./skan-
|
|
1
|
+
import { i as SKANPresetConfig, n as SKANManager, r as SKANMetrics, t as SKANConversionRule } from "./skan-DvnRgJo1.js";
|
|
2
2
|
export { SKANConversionRule, SKANManager, SKANMetrics, SKANPresetConfig };
|
package/dist/skan.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { t as __require } from "./chunk-
|
|
2
|
-
import { a as requestTrackingAuthorization, n as getAdvertisingId, r as getVendorId } from "./att-
|
|
1
|
+
import { t as __require } from "./chunk-DyChAoct.js";
|
|
2
|
+
import { a as requestTrackingAuthorization, n as getAdvertisingId, r as getVendorId } from "./att-DaUoQWpj.js";
|
|
3
|
+
import { t as SKANManager } from "./skan-DFFAN4wu.js";
|
|
3
4
|
import { FetchHttpClient, LayersCore, LayersError as LayersError$1, MemoryPersistence } from "@layers/core-wasm";
|
|
4
5
|
|
|
5
6
|
//#region src/index.ts
|
|
@@ -14,6 +15,10 @@ var LayersReactNative = class {
|
|
|
14
15
|
config;
|
|
15
16
|
userIdLocked = false;
|
|
16
17
|
errorListeners = /* @__PURE__ */ new Set();
|
|
18
|
+
_skanManager = null;
|
|
19
|
+
deepLinkUnsubscribe = null;
|
|
20
|
+
_adServicesToken = null;
|
|
21
|
+
_installReferrer = null;
|
|
17
22
|
constructor(config) {
|
|
18
23
|
this.enableDebug = config.enableDebug ?? false;
|
|
19
24
|
this.appUserId = config.appUserId;
|
|
@@ -63,6 +68,7 @@ var LayersReactNative = class {
|
|
|
63
68
|
this.setupAppStateListener();
|
|
64
69
|
this.setupNetInfoListener();
|
|
65
70
|
await this.core.fetchRemoteConfig().catch(() => {});
|
|
71
|
+
await this.configureSkanFromRemoteConfig();
|
|
66
72
|
let clipboardData = null;
|
|
67
73
|
try {
|
|
68
74
|
const { Platform } = __require("react-native");
|
|
@@ -75,17 +81,27 @@ var LayersReactNative = class {
|
|
|
75
81
|
if (clipboardEnabled) clipboardData = await readClipboardAttribution();
|
|
76
82
|
}
|
|
77
83
|
} catch {}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
if (this.config.autoTrackAppOpen !== false) {
|
|
85
|
+
const appOpenProps = {};
|
|
86
|
+
if (clipboardData) {
|
|
87
|
+
appOpenProps.clipboard_attribution_url = clipboardData.clickUrl;
|
|
88
|
+
appOpenProps.clipboard_click_id = clipboardData.clickId;
|
|
89
|
+
}
|
|
90
|
+
if (this._adServicesToken) appOpenProps.adservices_token = this._adServicesToken;
|
|
91
|
+
if (this._installReferrer) {
|
|
92
|
+
appOpenProps.install_referrer_url = this._installReferrer.referrerUrl;
|
|
93
|
+
if (this._installReferrer.referrerClickTimestamp) appOpenProps.install_referrer_click_timestamp = this._installReferrer.referrerClickTimestamp;
|
|
94
|
+
if (this._installReferrer.installBeginTimestamp) appOpenProps.install_referrer_install_timestamp = this._installReferrer.installBeginTimestamp;
|
|
95
|
+
}
|
|
96
|
+
this.track("app_open", appOpenProps);
|
|
82
97
|
}
|
|
83
|
-
this.
|
|
98
|
+
if (this.config.autoTrackDeepLinks !== false) this.setupDeepLinkAutoTracking();
|
|
84
99
|
}
|
|
85
100
|
track(eventName, properties) {
|
|
86
101
|
if (this.enableDebug) console.log(`[Layers] track("${eventName}", ${Object.keys(properties ?? {}).length} properties)`);
|
|
87
102
|
try {
|
|
88
103
|
this.core.track(eventName, properties, this.appUserId);
|
|
104
|
+
if (this._skanManager) this._skanManager.processEvent(eventName, properties ?? {}).catch(() => {});
|
|
89
105
|
} catch (e) {
|
|
90
106
|
this.emitError(e);
|
|
91
107
|
}
|
|
@@ -101,6 +117,9 @@ var LayersReactNative = class {
|
|
|
101
117
|
async setUserProperties(properties) {
|
|
102
118
|
this.core.setUserProperties(properties);
|
|
103
119
|
}
|
|
120
|
+
async setUserPropertiesOnce(properties) {
|
|
121
|
+
this.core.setUserPropertiesOnce(properties);
|
|
122
|
+
}
|
|
104
123
|
async setConsent(consent) {
|
|
105
124
|
this.core.setConsent(consent);
|
|
106
125
|
}
|
|
@@ -114,7 +133,21 @@ var LayersReactNative = class {
|
|
|
114
133
|
* Returns the ATT status string.
|
|
115
134
|
*/
|
|
116
135
|
async requestTrackingPermission() {
|
|
117
|
-
|
|
136
|
+
let status;
|
|
137
|
+
try {
|
|
138
|
+
const ExpoTT = await import("./TrackingTransparency-CMedp3bh.js").catch(() => null);
|
|
139
|
+
if (ExpoTT) {
|
|
140
|
+
const { status: expoStatus } = await ExpoTT.requestTrackingPermissionsAsync();
|
|
141
|
+
status = {
|
|
142
|
+
granted: "authorized",
|
|
143
|
+
denied: "denied",
|
|
144
|
+
restricted: "restricted",
|
|
145
|
+
undetermined: "not_determined"
|
|
146
|
+
}[expoStatus] ?? "not_determined";
|
|
147
|
+
} else status = await requestTrackingAuthorization();
|
|
148
|
+
} catch {
|
|
149
|
+
status = await requestTrackingAuthorization();
|
|
150
|
+
}
|
|
118
151
|
const updates = {
|
|
119
152
|
...this.core.getDeviceContext(),
|
|
120
153
|
attStatus: status
|
|
@@ -147,6 +180,29 @@ var LayersReactNative = class {
|
|
|
147
180
|
this.appUserId = void 0;
|
|
148
181
|
this.userIdLocked = false;
|
|
149
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Reset the SDK state: clears the user ID, unlocks set-user-once,
|
|
185
|
+
* clears user properties, and starts a new session.
|
|
186
|
+
*
|
|
187
|
+
* After reset(), the SDK behaves as if no user has been identified.
|
|
188
|
+
* A new anonymous session is started. Events tracked after reset()
|
|
189
|
+
* will not carry the previous user's identity.
|
|
190
|
+
*/
|
|
191
|
+
reset() {
|
|
192
|
+
if (this.enableDebug) console.log("[Layers] reset()");
|
|
193
|
+
this.appUserId = void 0;
|
|
194
|
+
this.userIdLocked = false;
|
|
195
|
+
try {
|
|
196
|
+
this.core.setUserProperties({});
|
|
197
|
+
} catch (e) {
|
|
198
|
+
this.emitError(e);
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
this.core.startNewSession();
|
|
202
|
+
} catch (e) {
|
|
203
|
+
this.emitError(e);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
150
206
|
getAppUserId() {
|
|
151
207
|
return this.appUserId;
|
|
152
208
|
}
|
|
@@ -168,6 +224,29 @@ var LayersReactNative = class {
|
|
|
168
224
|
}
|
|
169
225
|
}
|
|
170
226
|
/**
|
|
227
|
+
* Flush all queued events synchronously (blocking).
|
|
228
|
+
*
|
|
229
|
+
* Drains all batches from the queue and sends them via HTTP, awaiting
|
|
230
|
+
* each batch before proceeding. Does not return until all batches have
|
|
231
|
+
* been sent or failed.
|
|
232
|
+
*
|
|
233
|
+
* This is useful for AppState background transitions where the app may
|
|
234
|
+
* be suspended shortly after the call returns.
|
|
235
|
+
*/
|
|
236
|
+
async flushBlocking() {
|
|
237
|
+
try {
|
|
238
|
+
let depth = this.core.queueDepth();
|
|
239
|
+
while (depth > 0) {
|
|
240
|
+
await this.core.flushAsync();
|
|
241
|
+
const newDepth = this.core.queueDepth();
|
|
242
|
+
if (newDepth >= depth) break;
|
|
243
|
+
depth = newDepth;
|
|
244
|
+
}
|
|
245
|
+
} catch (e) {
|
|
246
|
+
this.emitError(e);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
171
250
|
* Register an error listener. Errors from track/screen/flush
|
|
172
251
|
* that would otherwise be silently dropped are forwarded here.
|
|
173
252
|
*/
|
|
@@ -182,6 +261,31 @@ var LayersReactNative = class {
|
|
|
182
261
|
if (event === "error") this.errorListeners.delete(listener);
|
|
183
262
|
return this;
|
|
184
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Returns the AdServices attribution token (iOS only), or null if not
|
|
266
|
+
* available. Collected automatically during init() on iOS 14.3+.
|
|
267
|
+
* Does NOT require ATT consent.
|
|
268
|
+
*/
|
|
269
|
+
getAdServicesToken() {
|
|
270
|
+
return this._adServicesToken;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Returns the Google Play install referrer data (Android only), or null
|
|
274
|
+
* if not available. Collected automatically during init() on Android.
|
|
275
|
+
*/
|
|
276
|
+
getInstallReferrer() {
|
|
277
|
+
return this._installReferrer;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Returns the auto-configured SKANManager instance, or null if SKAN was not
|
|
281
|
+
* configured by the server's remote config.
|
|
282
|
+
* On iOS, when remote config contains a `skan` section with `preset` or
|
|
283
|
+
* `customRules`, the SDK automatically creates and configures a SKANManager.
|
|
284
|
+
* Every `track()` call is automatically forwarded to SKAN rule evaluation.
|
|
285
|
+
*/
|
|
286
|
+
getSkanManager() {
|
|
287
|
+
return this._skanManager;
|
|
288
|
+
}
|
|
185
289
|
emitError(error) {
|
|
186
290
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
187
291
|
for (const listener of this.errorListeners) try {
|
|
@@ -198,8 +302,33 @@ var LayersReactNative = class {
|
|
|
198
302
|
this.netInfoUnsubscribe();
|
|
199
303
|
this.netInfoUnsubscribe = null;
|
|
200
304
|
}
|
|
305
|
+
if (this.deepLinkUnsubscribe) {
|
|
306
|
+
this.deepLinkUnsubscribe();
|
|
307
|
+
this.deepLinkUnsubscribe = null;
|
|
308
|
+
}
|
|
201
309
|
this.core.shutdown();
|
|
202
310
|
}
|
|
311
|
+
_trackedDeepLinkUrls = /* @__PURE__ */ new Set();
|
|
312
|
+
setupDeepLinkAutoTracking() {
|
|
313
|
+
this.deepLinkUnsubscribe = setupDeepLinkListener((data) => {
|
|
314
|
+
if (this._trackedDeepLinkUrls.has(data.url)) return;
|
|
315
|
+
this._trackedDeepLinkUrls.add(data.url);
|
|
316
|
+
setTimeout(() => this._trackedDeepLinkUrls.delete(data.url), 2e3);
|
|
317
|
+
try {
|
|
318
|
+
const properties = {
|
|
319
|
+
...data.queryParams,
|
|
320
|
+
url: data.url,
|
|
321
|
+
scheme: data.scheme,
|
|
322
|
+
host: data.host,
|
|
323
|
+
path: data.path
|
|
324
|
+
};
|
|
325
|
+
this.track("deep_link_opened", properties);
|
|
326
|
+
if (this.enableDebug) console.log(`[Layers] auto-tracked deep_link_opened: ${data.url}`);
|
|
327
|
+
} catch (e) {
|
|
328
|
+
this.emitError(e);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
203
332
|
async initializeDeviceInfo() {
|
|
204
333
|
try {
|
|
205
334
|
const { Platform, Dimensions, NativeModules } = __require("react-native");
|
|
@@ -217,18 +346,28 @@ var LayersReactNative = class {
|
|
|
217
346
|
deviceModel = "iPhone";
|
|
218
347
|
}
|
|
219
348
|
else deviceModel = "unknown";
|
|
349
|
+
let appVersion;
|
|
350
|
+
try {
|
|
351
|
+
appVersion = await getAppVersion(Platform, NativeModules);
|
|
352
|
+
} catch {}
|
|
220
353
|
const context = {
|
|
221
354
|
platform,
|
|
222
355
|
osVersion,
|
|
223
356
|
deviceModel,
|
|
224
357
|
locale: getLocale(),
|
|
225
358
|
screenSize: `${Math.round(window.width)}x${Math.round(window.height)}`,
|
|
226
|
-
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
359
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
360
|
+
...appVersion != null && { appVersion }
|
|
227
361
|
};
|
|
228
362
|
if (Platform.OS === "ios") try {
|
|
229
363
|
const idfv = await getVendorId();
|
|
230
364
|
if (idfv) context.idfv = idfv;
|
|
231
365
|
} catch {}
|
|
366
|
+
if (Platform.OS === "android") try {
|
|
367
|
+
const gaid = await getGoogleAdvertisingId();
|
|
368
|
+
if (gaid) context.idfa = gaid.id;
|
|
369
|
+
if (gaid && gaid.isLimitAdTrackingEnabled != null) context.attStatus = gaid.isLimitAdTrackingEnabled ? "denied" : "authorized";
|
|
370
|
+
} catch {}
|
|
232
371
|
try {
|
|
233
372
|
const installId = await getOrSetInstallId();
|
|
234
373
|
if (installId) context.installId = installId;
|
|
@@ -247,6 +386,17 @@ var LayersReactNative = class {
|
|
|
247
386
|
} catch {}
|
|
248
387
|
this.core.setDeviceContext(context);
|
|
249
388
|
}
|
|
389
|
+
try {
|
|
390
|
+
const { Platform } = __require("react-native");
|
|
391
|
+
if (Platform.OS === "ios") try {
|
|
392
|
+
const token = await getAdServicesToken();
|
|
393
|
+
if (token) this._adServicesToken = token;
|
|
394
|
+
} catch {}
|
|
395
|
+
if (Platform.OS === "android") try {
|
|
396
|
+
const referrer = await getInstallReferrer();
|
|
397
|
+
if (referrer) this._installReferrer = referrer;
|
|
398
|
+
} catch {}
|
|
399
|
+
} catch {}
|
|
250
400
|
}
|
|
251
401
|
setupAppStateListener() {
|
|
252
402
|
try {
|
|
@@ -257,6 +407,28 @@ var LayersReactNative = class {
|
|
|
257
407
|
});
|
|
258
408
|
} catch {}
|
|
259
409
|
}
|
|
410
|
+
async configureSkanFromRemoteConfig() {
|
|
411
|
+
try {
|
|
412
|
+
const { Platform } = __require("react-native");
|
|
413
|
+
if (Platform.OS !== "ios") return;
|
|
414
|
+
} catch {}
|
|
415
|
+
try {
|
|
416
|
+
const configJson = this.core.getRemoteConfigJson?.();
|
|
417
|
+
if (!configJson) return;
|
|
418
|
+
const skanConfig = JSON.parse(configJson)?.skan;
|
|
419
|
+
if (!skanConfig || skanConfig.enabled === false) return;
|
|
420
|
+
const manager = new SKANManager();
|
|
421
|
+
if (skanConfig.preset) manager.setPreset(skanConfig.preset);
|
|
422
|
+
else if (skanConfig.customRules && Array.isArray(skanConfig.customRules)) manager.setCustomRules(skanConfig.customRules);
|
|
423
|
+
else return;
|
|
424
|
+
await manager.initialize();
|
|
425
|
+
this._skanManager = manager;
|
|
426
|
+
if (this.enableDebug) {
|
|
427
|
+
const metrics = manager.getMetrics();
|
|
428
|
+
console.log(`[Layers] SKAN auto-configured from remote config: preset=${metrics.currentPreset}, rules=${String(metrics.ruleCount)}`);
|
|
429
|
+
}
|
|
430
|
+
} catch {}
|
|
431
|
+
}
|
|
260
432
|
setupNetInfoListener() {
|
|
261
433
|
try {
|
|
262
434
|
this.netInfoUnsubscribe = __require("@react-native-community/netinfo").addEventListener((state) => {
|
|
@@ -434,6 +606,81 @@ async function readClipboardAttribution() {
|
|
|
434
606
|
clickId: match[2]
|
|
435
607
|
};
|
|
436
608
|
}
|
|
609
|
+
/**
|
|
610
|
+
* Attempt to read the host app version from platform-specific APIs.
|
|
611
|
+
* On Android, reads from PackageInfo via Platform.constants or a native module.
|
|
612
|
+
* On iOS, reads from the LayersDeviceInfo native module which can access the Info.plist.
|
|
613
|
+
*/
|
|
614
|
+
async function getAppVersion(Platform, NativeModules) {
|
|
615
|
+
try {
|
|
616
|
+
if (Platform.OS === "android") {
|
|
617
|
+
const mod = NativeModules.LayersDeviceInfo;
|
|
618
|
+
if (mod?.getAppVersion) {
|
|
619
|
+
const version = await mod.getAppVersion();
|
|
620
|
+
if (version) return version;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
if (Platform.OS === "ios") {
|
|
624
|
+
const mod = NativeModules.LayersDeviceInfo;
|
|
625
|
+
if (mod?.getAppVersion) {
|
|
626
|
+
const version = await mod.getAppVersion();
|
|
627
|
+
if (version) return version;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
} catch {}
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Fetch the Google Advertising ID (GAID) on Android via NativeModules.
|
|
634
|
+
* Returns null on iOS or when the native module is not available.
|
|
635
|
+
*/
|
|
636
|
+
async function getGoogleAdvertisingId() {
|
|
637
|
+
try {
|
|
638
|
+
const { NativeModules, Platform } = __require("react-native");
|
|
639
|
+
if (Platform.OS !== "android") return null;
|
|
640
|
+
const mod = NativeModules.LayersAdvertisingId;
|
|
641
|
+
if (!mod?.getAdvertisingInfo) return null;
|
|
642
|
+
const info = await mod.getAdvertisingInfo();
|
|
643
|
+
if (!info || !info.id || info.id === "00000000-0000-0000-0000-000000000000") return null;
|
|
644
|
+
return info;
|
|
645
|
+
} catch {
|
|
646
|
+
return null;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Request the AdServices attribution token on iOS 14.3+.
|
|
651
|
+
* Uses the LayersAdServices native module which calls AAAttribution.attributionToken().
|
|
652
|
+
* Does NOT require ATT consent.
|
|
653
|
+
* Returns null on Android or when the native module is not available.
|
|
654
|
+
*/
|
|
655
|
+
async function getAdServicesToken() {
|
|
656
|
+
try {
|
|
657
|
+
const { NativeModules, Platform } = __require("react-native");
|
|
658
|
+
if (Platform.OS !== "ios") return null;
|
|
659
|
+
const mod = NativeModules.LayersAdServices;
|
|
660
|
+
if (!mod?.getAttributionToken) return null;
|
|
661
|
+
return await mod.getAttributionToken();
|
|
662
|
+
} catch {
|
|
663
|
+
return null;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Fetch the Google Play install referrer on Android via NativeModules.
|
|
668
|
+
* Requires the `com.android.installreferrer` library on the native side.
|
|
669
|
+
* Returns null on iOS or when the native module is not available.
|
|
670
|
+
*/
|
|
671
|
+
async function getInstallReferrer() {
|
|
672
|
+
try {
|
|
673
|
+
const { NativeModules, Platform } = __require("react-native");
|
|
674
|
+
if (Platform.OS !== "android") return null;
|
|
675
|
+
const mod = NativeModules.LayersInstallReferrer;
|
|
676
|
+
if (!mod?.getInstallReferrer) return null;
|
|
677
|
+
const data = await mod.getInstallReferrer();
|
|
678
|
+
if (!data || !data.referrerUrl) return null;
|
|
679
|
+
return data;
|
|
680
|
+
} catch {
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
437
684
|
function setupDeepLinkListener(onDeepLink) {
|
|
438
685
|
try {
|
|
439
686
|
const { Linking } = __require("react-native");
|
|
@@ -490,5 +737,5 @@ function useLayersExpoRouterTracking(layersInstance, usePathname, useGlobalSearc
|
|
|
490
737
|
}
|
|
491
738
|
|
|
492
739
|
//#endregion
|
|
493
|
-
export {
|
|
494
|
-
//# sourceMappingURL=src-
|
|
740
|
+
export { getInstallReferrer as a, readClipboardAttribution as c, getGoogleAdvertisingId as i, setupDeepLinkListener as l, LayersReactNative as n, getOrSetInstallId as o, getAdServicesToken as r, parseDeepLink as s, LayersError$1 as t, useLayersExpoRouterTracking as u };
|
|
741
|
+
//# sourceMappingURL=src-DTBDULvf.js.map
|