@layers/react-native 0.2.0-alpha.8 → 1.0.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.
@@ -0,0 +1,108 @@
1
+ import "./att-Hyj9b7AG.js";
2
+ import "./skan-C-RMfcG8.js";
3
+ import { c as LayersRNConfig, l as LayersReactNative, o as EventProperties, t as ConsentState } from "./index-D4pdpobh.js";
4
+ import { ReactNode } from "react";
5
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
6
+
7
+ //#region src/react.d.ts
8
+ interface LayersRNProviderProps {
9
+ config: LayersRNConfig;
10
+ children: ReactNode;
11
+ }
12
+ /**
13
+ * Provides a LayersReactNative instance to the React component tree.
14
+ * Initializes the client on mount and shuts it down on unmount.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * import { LayersRNProvider } from '@layers/react-native/react';
19
+ *
20
+ * function App() {
21
+ * return (
22
+ * <LayersRNProvider config={{ apiKey: 'key', appId: 'app', environment: 'production' }}>
23
+ * <MyApp />
24
+ * </LayersRNProvider>
25
+ * );
26
+ * }
27
+ * ```
28
+ */
29
+ declare function LayersRNProvider({
30
+ config,
31
+ children
32
+ }: LayersRNProviderProps): react_jsx_runtime0.JSX.Element;
33
+ /**
34
+ * Returns the LayersReactNative instance from the nearest LayersRNProvider.
35
+ * Throws if used outside a LayersRNProvider.
36
+ */
37
+ declare function useLayers(): LayersReactNative;
38
+ /**
39
+ * Returns a stable, memoized track function bound to the current LayersReactNative instance.
40
+ *
41
+ * @example
42
+ * ```tsx
43
+ * import { useTrack } from '@layers/react-native/react';
44
+ *
45
+ * function PurchaseButton() {
46
+ * const track = useTrack();
47
+ * return <Button onPress={() => track('purchase_tap', { item: 'premium' })} title="Buy" />;
48
+ * }
49
+ * ```
50
+ */
51
+ declare function useTrack(): (eventName: string, properties?: EventProperties) => void;
52
+ /**
53
+ * Returns a stable, memoized screen function bound to the current LayersReactNative instance.
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * import { useScreen } from '@layers/react-native/react';
58
+ * import { useEffect } from 'react';
59
+ *
60
+ * function HomeScreen() {
61
+ * const screen = useScreen();
62
+ * useEffect(() => { screen('home'); }, [screen]);
63
+ * return <View />;
64
+ * }
65
+ * ```
66
+ */
67
+ declare function useScreen(): (screenName: string, properties?: EventProperties) => void;
68
+ /**
69
+ * Returns a stable, memoized identify function that sets the app user ID.
70
+ * Pass `undefined` to clear the current user ID.
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * import { useIdentify } from '@layers/react-native/react';
75
+ *
76
+ * function LoginScreen() {
77
+ * const identify = useIdentify();
78
+ * const onLogin = (userId: string) => identify(userId);
79
+ * const onLogout = () => identify(undefined);
80
+ * }
81
+ * ```
82
+ */
83
+ declare function useIdentify(): (userId: string | undefined) => void;
84
+ /**
85
+ * Returns stable, memoized consent functions bound to the current LayersReactNative instance.
86
+ *
87
+ * @example
88
+ * ```tsx
89
+ * import { useConsent } from '@layers/react-native/react';
90
+ *
91
+ * function ConsentScreen() {
92
+ * const { setConsent, getConsentState } = useConsent();
93
+ * return (
94
+ * <Button
95
+ * onPress={() => setConsent({ analytics: true, advertising: false })}
96
+ * title="Accept Analytics Only"
97
+ * />
98
+ * );
99
+ * }
100
+ * ```
101
+ */
102
+ declare function useConsent(): {
103
+ setConsent: (consent: ConsentState) => void;
104
+ getConsentState: () => ConsentState;
105
+ };
106
+ //#endregion
107
+ export { LayersRNProvider, LayersRNProviderProps, useConsent, useIdentify, useLayers, useScreen, useTrack };
108
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","names":[],"sources":["../src/react.tsx"],"sourcesContent":[],"mappings":";;;;;;;UAQiB,qBAAA;UACP;YACE;;AAFZ;AAsBA;;;;;;AA4BA;AAqBA;AAyBA;AAyBA;AAgCA;;;;;;iBAnIgB,gBAAA;;;GAAuC,wBAAqB,kBAAA,CAAA,GAAA,CAAA;;;;;iBA4B5D,SAAA,CAAA,GAAa;;;;;;;;;;;;;;iBAqBb,QAAA,CAAA,oCAA6C;;;;;;;;;;;;;;;;iBAyB7C,SAAA,CAAA,qCAA+C;;;;;;;;;;;;;;;;iBAyB/C,WAAA,CAAA;;;;;;;;;;;;;;;;;;;iBAgCA,UAAA,CAAA;wBACQ;yBACC"}
package/dist/react.js ADDED
@@ -0,0 +1,146 @@
1
+ import "./att-C5tL1hKX.js";
2
+ import "./skan-_aDXcXWQ.js";
3
+ import { n as LayersReactNative } from "./src-DV0LxJ__.js";
4
+ import { createContext, useCallback, useContext, useEffect, useRef } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+
7
+ //#region src/react.tsx
8
+ const LayersRNContext = createContext(null);
9
+ /**
10
+ * Provides a LayersReactNative instance to the React component tree.
11
+ * Initializes the client on mount and shuts it down on unmount.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * import { LayersRNProvider } from '@layers/react-native/react';
16
+ *
17
+ * function App() {
18
+ * return (
19
+ * <LayersRNProvider config={{ apiKey: 'key', appId: 'app', environment: 'production' }}>
20
+ * <MyApp />
21
+ * </LayersRNProvider>
22
+ * );
23
+ * }
24
+ * ```
25
+ */
26
+ function LayersRNProvider({ config, children }) {
27
+ const clientRef = useRef(null);
28
+ if (clientRef.current === null) clientRef.current = new LayersReactNative(config);
29
+ useEffect(() => {
30
+ const client = clientRef.current;
31
+ if (!client) return;
32
+ client.init();
33
+ return () => {
34
+ client.shutdown();
35
+ clientRef.current = null;
36
+ };
37
+ }, []);
38
+ return /* @__PURE__ */ jsx(LayersRNContext.Provider, {
39
+ value: clientRef.current,
40
+ children
41
+ });
42
+ }
43
+ /**
44
+ * Returns the LayersReactNative instance from the nearest LayersRNProvider.
45
+ * Throws if used outside a LayersRNProvider.
46
+ */
47
+ function useLayers() {
48
+ const client = useContext(LayersRNContext);
49
+ if (!client) throw new Error("useLayers must be used within a <LayersRNProvider>");
50
+ return client;
51
+ }
52
+ /**
53
+ * Returns a stable, memoized track function bound to the current LayersReactNative instance.
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * import { useTrack } from '@layers/react-native/react';
58
+ *
59
+ * function PurchaseButton() {
60
+ * const track = useTrack();
61
+ * return <Button onPress={() => track('purchase_tap', { item: 'premium' })} title="Buy" />;
62
+ * }
63
+ * ```
64
+ */
65
+ function useTrack() {
66
+ const client = useLayers();
67
+ return useCallback((eventName, properties) => {
68
+ client.track(eventName, properties);
69
+ }, [client]);
70
+ }
71
+ /**
72
+ * Returns a stable, memoized screen function bound to the current LayersReactNative instance.
73
+ *
74
+ * @example
75
+ * ```tsx
76
+ * import { useScreen } from '@layers/react-native/react';
77
+ * import { useEffect } from 'react';
78
+ *
79
+ * function HomeScreen() {
80
+ * const screen = useScreen();
81
+ * useEffect(() => { screen('home'); }, [screen]);
82
+ * return <View />;
83
+ * }
84
+ * ```
85
+ */
86
+ function useScreen() {
87
+ const client = useLayers();
88
+ return useCallback((screenName, properties) => {
89
+ client.screen(screenName, properties);
90
+ }, [client]);
91
+ }
92
+ /**
93
+ * Returns a stable, memoized identify function that sets the app user ID.
94
+ * Pass `undefined` to clear the current user ID.
95
+ *
96
+ * @example
97
+ * ```tsx
98
+ * import { useIdentify } from '@layers/react-native/react';
99
+ *
100
+ * function LoginScreen() {
101
+ * const identify = useIdentify();
102
+ * const onLogin = (userId: string) => identify(userId);
103
+ * const onLogout = () => identify(undefined);
104
+ * }
105
+ * ```
106
+ */
107
+ function useIdentify() {
108
+ const client = useLayers();
109
+ return useCallback((userId) => {
110
+ if (userId) client.setAppUserId(userId);
111
+ else client.clearAppUserId();
112
+ }, [client]);
113
+ }
114
+ /**
115
+ * Returns stable, memoized consent functions bound to the current LayersReactNative instance.
116
+ *
117
+ * @example
118
+ * ```tsx
119
+ * import { useConsent } from '@layers/react-native/react';
120
+ *
121
+ * function ConsentScreen() {
122
+ * const { setConsent, getConsentState } = useConsent();
123
+ * return (
124
+ * <Button
125
+ * onPress={() => setConsent({ analytics: true, advertising: false })}
126
+ * title="Accept Analytics Only"
127
+ * />
128
+ * );
129
+ * }
130
+ * ```
131
+ */
132
+ function useConsent() {
133
+ const client = useLayers();
134
+ return {
135
+ setConsent: useCallback((consent) => {
136
+ client.setConsent(consent);
137
+ }, [client]),
138
+ getConsentState: useCallback(() => {
139
+ return client.getConsentState();
140
+ }, [client])
141
+ };
142
+ }
143
+
144
+ //#endregion
145
+ export { LayersRNProvider, useConsent, useIdentify, useLayers, useScreen, useTrack };
146
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","names":[],"sources":["../src/react.tsx"],"sourcesContent":["import { createContext, useCallback, useContext, useEffect, useRef } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { LayersReactNative } from './index.js';\nimport type { ConsentState, EventProperties, LayersRNConfig } from './index.js';\n\nconst LayersRNContext = createContext<LayersReactNative | null>(null);\n\nexport interface LayersRNProviderProps {\n config: LayersRNConfig;\n children: ReactNode;\n}\n\n/**\n * Provides a LayersReactNative instance to the React component tree.\n * Initializes the client on mount and shuts it down on unmount.\n *\n * @example\n * ```tsx\n * import { LayersRNProvider } from '@layers/react-native/react';\n *\n * function App() {\n * return (\n * <LayersRNProvider config={{ apiKey: 'key', appId: 'app', environment: 'production' }}>\n * <MyApp />\n * </LayersRNProvider>\n * );\n * }\n * ```\n */\nexport function LayersRNProvider({ config, children }: LayersRNProviderProps) {\n const clientRef = useRef<LayersReactNative | null>(null);\n\n if (clientRef.current === null) {\n clientRef.current = new LayersReactNative(config);\n }\n\n useEffect(() => {\n const client = clientRef.current;\n if (!client) return;\n\n void client.init();\n\n return () => {\n client.shutdown();\n clientRef.current = null;\n };\n // Config is intentionally captured once at mount time via useRef above.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return <LayersRNContext.Provider value={clientRef.current}>{children}</LayersRNContext.Provider>;\n}\n\n/**\n * Returns the LayersReactNative instance from the nearest LayersRNProvider.\n * Throws if used outside a LayersRNProvider.\n */\nexport function useLayers(): LayersReactNative {\n const client = useContext(LayersRNContext);\n if (!client) {\n throw new Error('useLayers must be used within a <LayersRNProvider>');\n }\n return client;\n}\n\n/**\n * Returns a stable, memoized track function bound to the current LayersReactNative instance.\n *\n * @example\n * ```tsx\n * import { useTrack } from '@layers/react-native/react';\n *\n * function PurchaseButton() {\n * const track = useTrack();\n * return <Button onPress={() => track('purchase_tap', { item: 'premium' })} title=\"Buy\" />;\n * }\n * ```\n */\nexport function useTrack(): (eventName: string, properties?: EventProperties) => void {\n const client = useLayers();\n return useCallback(\n (eventName: string, properties?: EventProperties) => {\n void client.track(eventName, properties);\n },\n [client]\n );\n}\n\n/**\n * Returns a stable, memoized screen function bound to the current LayersReactNative instance.\n *\n * @example\n * ```tsx\n * import { useScreen } from '@layers/react-native/react';\n * import { useEffect } from 'react';\n *\n * function HomeScreen() {\n * const screen = useScreen();\n * useEffect(() => { screen('home'); }, [screen]);\n * return <View />;\n * }\n * ```\n */\nexport function useScreen(): (screenName: string, properties?: EventProperties) => void {\n const client = useLayers();\n return useCallback(\n (screenName: string, properties?: EventProperties) => {\n void client.screen(screenName, properties);\n },\n [client]\n );\n}\n\n/**\n * Returns a stable, memoized identify function that sets the app user ID.\n * Pass `undefined` to clear the current user ID.\n *\n * @example\n * ```tsx\n * import { useIdentify } from '@layers/react-native/react';\n *\n * function LoginScreen() {\n * const identify = useIdentify();\n * const onLogin = (userId: string) => identify(userId);\n * const onLogout = () => identify(undefined);\n * }\n * ```\n */\nexport function useIdentify(): (userId: string | undefined) => void {\n const client = useLayers();\n return useCallback(\n (userId: string | undefined) => {\n if (userId) {\n client.setAppUserId(userId);\n } else {\n client.clearAppUserId();\n }\n },\n [client]\n );\n}\n\n/**\n * Returns stable, memoized consent functions bound to the current LayersReactNative instance.\n *\n * @example\n * ```tsx\n * import { useConsent } from '@layers/react-native/react';\n *\n * function ConsentScreen() {\n * const { setConsent, getConsentState } = useConsent();\n * return (\n * <Button\n * onPress={() => setConsent({ analytics: true, advertising: false })}\n * title=\"Accept Analytics Only\"\n * />\n * );\n * }\n * ```\n */\nexport function useConsent(): {\n setConsent: (consent: ConsentState) => void;\n getConsentState: () => ConsentState;\n} {\n const client = useLayers();\n const setConsent = useCallback(\n (consent: ConsentState) => {\n void client.setConsent(consent);\n },\n [client]\n );\n const getConsentState = useCallback(() => {\n return client.getConsentState();\n }, [client]);\n return { setConsent, getConsentState };\n}\n"],"mappings":";;;;;;;AAMA,MAAM,kBAAkB,cAAwC,KAAK;;;;;;;;;;;;;;;;;;AAwBrE,SAAgB,iBAAiB,EAAE,QAAQ,YAAmC;CAC5E,MAAM,YAAY,OAAiC,KAAK;AAExD,KAAI,UAAU,YAAY,KACxB,WAAU,UAAU,IAAI,kBAAkB,OAAO;AAGnD,iBAAgB;EACd,MAAM,SAAS,UAAU;AACzB,MAAI,CAAC,OAAQ;AAEb,EAAK,OAAO,MAAM;AAElB,eAAa;AACX,UAAO,UAAU;AACjB,aAAU,UAAU;;IAIrB,EAAE,CAAC;AAEN,QAAO,oBAAC,gBAAgB;EAAS,OAAO,UAAU;EAAU;GAAoC;;;;;;AAOlG,SAAgB,YAA+B;CAC7C,MAAM,SAAS,WAAW,gBAAgB;AAC1C,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,qDAAqD;AAEvE,QAAO;;;;;;;;;;;;;;;AAgBT,SAAgB,WAAsE;CACpF,MAAM,SAAS,WAAW;AAC1B,QAAO,aACJ,WAAmB,eAAiC;AACnD,EAAK,OAAO,MAAM,WAAW,WAAW;IAE1C,CAAC,OAAO,CACT;;;;;;;;;;;;;;;;;AAkBH,SAAgB,YAAwE;CACtF,MAAM,SAAS,WAAW;AAC1B,QAAO,aACJ,YAAoB,eAAiC;AACpD,EAAK,OAAO,OAAO,YAAY,WAAW;IAE5C,CAAC,OAAO,CACT;;;;;;;;;;;;;;;;;AAkBH,SAAgB,cAAoD;CAClE,MAAM,SAAS,WAAW;AAC1B,QAAO,aACJ,WAA+B;AAC9B,MAAI,OACF,QAAO,aAAa,OAAO;MAE3B,QAAO,gBAAgB;IAG3B,CAAC,OAAO,CACT;;;;;;;;;;;;;;;;;;;;AAqBH,SAAgB,aAGd;CACA,MAAM,SAAS,WAAW;AAU1B,QAAO;EAAE,YATU,aAChB,YAA0B;AACzB,GAAK,OAAO,WAAW,QAAQ;KAEjC,CAAC,OAAO,CACT;EAIoB,iBAHG,kBAAkB;AACxC,UAAO,OAAO,iBAAiB;KAC9B,CAAC,OAAO,CAAC;EAC0B"}
@@ -0,0 +1,50 @@
1
+ //#region src/skan.d.ts
2
+ interface SKANConversionRule {
3
+ eventName: string;
4
+ conditions?: Record<string, unknown>;
5
+ conversionValue: number;
6
+ coarseValue?: 'low' | 'medium' | 'high';
7
+ lockWindow?: boolean;
8
+ priority?: number;
9
+ description?: string;
10
+ }
11
+ interface SKANPresetConfig {
12
+ name: 'subscriptions' | 'engagement' | 'iap';
13
+ rules: SKANConversionRule[];
14
+ description: string;
15
+ maxValue: number;
16
+ }
17
+ interface SKANMetrics {
18
+ isSupported: boolean;
19
+ version: string;
20
+ currentValue: number | null;
21
+ currentPreset: string | null;
22
+ ruleCount: number;
23
+ evaluationCount: number;
24
+ }
25
+ declare class SKANManager {
26
+ private rules;
27
+ private currentPreset;
28
+ private currentValue;
29
+ private evaluationCount;
30
+ private nativeModule;
31
+ private onConversionUpdate?;
32
+ constructor(onConversionUpdate?: (data: {
33
+ event: string;
34
+ previousValue: number;
35
+ newValue: number;
36
+ rule: SKANConversionRule;
37
+ }) => void);
38
+ initialize(): Promise<void>;
39
+ isSupported(): boolean;
40
+ setPreset(preset: 'subscriptions' | 'engagement' | 'iap'): void;
41
+ setCustomRules(rules: SKANConversionRule[]): void;
42
+ processEvent(eventName: string, properties: Record<string, unknown>): Promise<void>;
43
+ getCurrentValue(): number;
44
+ getCurrentPreset(): string | null;
45
+ getCurrentRules(): SKANConversionRule[];
46
+ getMetrics(): SKANMetrics;
47
+ }
48
+ //#endregion
49
+ export { SKANPresetConfig as i, SKANManager as n, SKANMetrics as r, SKANConversionRule as t };
50
+ //# sourceMappingURL=skan-C-RMfcG8.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skan-C-RMfcG8.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"}
@@ -0,0 +1,253 @@
1
+ import { t as __require } from "./chunk-B1JASekH.js";
2
+
3
+ //#region src/skan.ts
4
+ function getNativeModule() {
5
+ try {
6
+ const { NativeModules, Platform } = __require("react-native");
7
+ if (Platform.OS === "ios" && NativeModules.LayersSKAN) return NativeModules.LayersSKAN;
8
+ } catch {}
9
+ return null;
10
+ }
11
+ var SKANManager = class {
12
+ rules = [];
13
+ currentPreset = null;
14
+ currentValue = 0;
15
+ evaluationCount = 0;
16
+ nativeModule;
17
+ onConversionUpdate;
18
+ constructor(onConversionUpdate) {
19
+ this.nativeModule = getNativeModule();
20
+ if (onConversionUpdate) this.onConversionUpdate = onConversionUpdate;
21
+ }
22
+ async initialize() {
23
+ if (!this.nativeModule) return;
24
+ if (await this.nativeModule.isAvailable()) {
25
+ await this.nativeModule.registerAppForAdNetworkAttribution();
26
+ const val = await this.nativeModule.getCurrentConversionValue();
27
+ if (val !== null) this.currentValue = val;
28
+ }
29
+ }
30
+ isSupported() {
31
+ return this.nativeModule !== null;
32
+ }
33
+ setPreset(preset) {
34
+ this.rules = getPresetConfig(preset).rules.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
35
+ this.currentPreset = preset;
36
+ }
37
+ setCustomRules(rules) {
38
+ this.rules = rules.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
39
+ this.currentPreset = "custom";
40
+ }
41
+ async processEvent(eventName, properties) {
42
+ this.evaluationCount += 1;
43
+ let matchedRule;
44
+ for (const rule of this.rules) if (evaluateRule(rule, eventName, properties)) {
45
+ matchedRule = rule;
46
+ break;
47
+ }
48
+ if (!matchedRule || matchedRule.conversionValue <= this.currentValue) return;
49
+ const previousValue = this.currentValue;
50
+ this.currentValue = matchedRule.conversionValue;
51
+ if (this.nativeModule) try {
52
+ if (matchedRule.coarseValue) await this.nativeModule.updatePostbackConversionValue(matchedRule.conversionValue, matchedRule.coarseValue, matchedRule.lockWindow);
53
+ else await this.nativeModule.updateConversionValue(matchedRule.conversionValue);
54
+ } catch {}
55
+ this.onConversionUpdate?.({
56
+ event: eventName,
57
+ previousValue,
58
+ newValue: matchedRule.conversionValue,
59
+ rule: matchedRule
60
+ });
61
+ }
62
+ getCurrentValue() {
63
+ return this.currentValue;
64
+ }
65
+ getCurrentPreset() {
66
+ return this.currentPreset;
67
+ }
68
+ getCurrentRules() {
69
+ return [...this.rules];
70
+ }
71
+ getMetrics() {
72
+ return {
73
+ isSupported: this.isSupported(),
74
+ version: "4.0",
75
+ currentValue: this.currentValue,
76
+ currentPreset: this.currentPreset,
77
+ ruleCount: this.rules.length,
78
+ evaluationCount: this.evaluationCount
79
+ };
80
+ }
81
+ };
82
+ function evaluateRule(rule, eventName, properties) {
83
+ if (rule.eventName !== eventName) return false;
84
+ if (!rule.conditions) return true;
85
+ for (const [key, expected] of Object.entries(rule.conditions)) {
86
+ const actual = properties[key];
87
+ if (typeof expected === "object" && expected !== null && !Array.isArray(expected)) {
88
+ for (const [op, val] of Object.entries(expected)) if (!evaluateOperator(actual, op, val)) return false;
89
+ } else if (actual !== expected) return false;
90
+ }
91
+ return true;
92
+ }
93
+ function evaluateOperator(actual, operator, expected) {
94
+ const a = Number(actual);
95
+ const b = Number(expected);
96
+ switch (operator) {
97
+ case ">": return a > b;
98
+ case ">=": return a >= b;
99
+ case "<": return a < b;
100
+ case "<=": return a <= b;
101
+ case "==":
102
+ case "=": return actual === expected;
103
+ case "!=": return actual !== expected;
104
+ default: return false;
105
+ }
106
+ }
107
+ function getPresetConfig(preset) {
108
+ switch (preset) {
109
+ case "subscriptions": return {
110
+ name: "subscriptions",
111
+ description: "Optimized for subscription apps with trial-to-paid conversion tracking",
112
+ maxValue: 63,
113
+ rules: [
114
+ {
115
+ eventName: "app_open",
116
+ conversionValue: 1,
117
+ priority: 1,
118
+ description: "App opened"
119
+ },
120
+ {
121
+ eventName: "screen_view",
122
+ conditions: { screen_name: "onboarding_complete" },
123
+ conversionValue: 8,
124
+ priority: 3,
125
+ description: "Onboarding completed"
126
+ },
127
+ {
128
+ eventName: "trial_start",
129
+ conversionValue: 20,
130
+ priority: 5,
131
+ description: "Free trial started"
132
+ },
133
+ {
134
+ eventName: "purchase_success",
135
+ conditions: { revenue: { "<": 5 } },
136
+ conversionValue: 35,
137
+ priority: 7,
138
+ description: "Small purchase (<$5)"
139
+ },
140
+ {
141
+ eventName: "subscription_start",
142
+ conversionValue: 50,
143
+ priority: 10,
144
+ description: "Subscription started"
145
+ },
146
+ {
147
+ eventName: "subscription_renew",
148
+ conversionValue: 63,
149
+ priority: 15,
150
+ description: "Subscription renewed"
151
+ }
152
+ ]
153
+ };
154
+ case "engagement": return {
155
+ name: "engagement",
156
+ description: "Optimized for engagement-driven apps",
157
+ maxValue: 63,
158
+ rules: [
159
+ {
160
+ eventName: "app_open",
161
+ conversionValue: 1,
162
+ priority: 1,
163
+ description: "App opened"
164
+ },
165
+ {
166
+ eventName: "content_open",
167
+ conversionValue: 5,
168
+ priority: 2,
169
+ description: "Content viewed"
170
+ },
171
+ {
172
+ eventName: "search",
173
+ conversionValue: 12,
174
+ priority: 4,
175
+ description: "Search performed"
176
+ },
177
+ {
178
+ eventName: "bookmark_add",
179
+ conversionValue: 25,
180
+ priority: 6,
181
+ description: "Content bookmarked"
182
+ },
183
+ {
184
+ eventName: "app_open",
185
+ conditions: { session_count: { ">": 3 } },
186
+ conversionValue: 40,
187
+ priority: 8,
188
+ description: "Regular user (3+ sessions)"
189
+ },
190
+ {
191
+ eventName: "app_open",
192
+ conditions: { session_count: { ">": 10 } },
193
+ conversionValue: 63,
194
+ priority: 12,
195
+ description: "Power user (10+ sessions)"
196
+ }
197
+ ]
198
+ };
199
+ case "iap": return {
200
+ name: "iap",
201
+ description: "Optimized for in-app purchase revenue tracking",
202
+ maxValue: 63,
203
+ rules: [
204
+ {
205
+ eventName: "app_open",
206
+ conversionValue: 1,
207
+ priority: 1,
208
+ description: "App opened"
209
+ },
210
+ {
211
+ eventName: "paywall_show",
212
+ conversionValue: 8,
213
+ priority: 2,
214
+ description: "Paywall shown"
215
+ },
216
+ {
217
+ eventName: "purchase_attempt",
218
+ conversionValue: 15,
219
+ priority: 3,
220
+ description: "Purchase attempted"
221
+ },
222
+ {
223
+ eventName: "purchase_success",
224
+ conditions: { revenue: { "<": 1 } },
225
+ conversionValue: 25,
226
+ priority: 5,
227
+ description: "Small purchase (<$1)"
228
+ },
229
+ {
230
+ eventName: "purchase_success",
231
+ conditions: { revenue: {
232
+ ">=": 1,
233
+ "<": 10
234
+ } },
235
+ conversionValue: 40,
236
+ priority: 7,
237
+ description: "Medium purchase ($1-$10)"
238
+ },
239
+ {
240
+ eventName: "purchase_success",
241
+ conditions: { revenue: { ">=": 10 } },
242
+ conversionValue: 63,
243
+ priority: 10,
244
+ description: "Large purchase ($10+)"
245
+ }
246
+ ]
247
+ };
248
+ }
249
+ }
250
+
251
+ //#endregion
252
+ export { SKANManager as t };
253
+ //# sourceMappingURL=skan-_aDXcXWQ.js.map
@@ -0,0 +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,SA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AiB;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"}
package/dist/skan.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { i as SKANPresetConfig, n as SKANManager, r as SKANMetrics, t as SKANConversionRule } from "./skan-C-RMfcG8.js";
2
+ export { SKANConversionRule, SKANManager, SKANMetrics, SKANPresetConfig };
package/dist/skan.js ADDED
@@ -0,0 +1,3 @@
1
+ import { t as SKANManager } from "./skan-_aDXcXWQ.js";
2
+
3
+ export { SKANManager };