@adshift/react-native-plugin 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.
- package/AdShiftReactNativePlugin.podspec +30 -0
- package/LICENSE +45 -0
- package/README.md +810 -0
- package/android/build.gradle +80 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginModule.kt +420 -0
- package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginPackage.kt +33 -0
- package/ios/AdShiftReactNativePlugin.h +24 -0
- package/ios/AdShiftReactNativePlugin.mm +258 -0
- package/ios/AdShiftReactNativePluginHelper.swift +413 -0
- package/lib/module/Adshift.js +468 -0
- package/lib/module/Adshift.js.map +1 -0
- package/lib/module/NativeAdShiftReactNativePlugin.js +18 -0
- package/lib/module/NativeAdShiftReactNativePlugin.js.map +1 -0
- package/lib/module/index.js +57 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types/AdshiftConfig.js +44 -0
- package/lib/module/types/AdshiftConfig.js.map +1 -0
- package/lib/module/types/AdshiftConsent.js +101 -0
- package/lib/module/types/AdshiftConsent.js.map +1 -0
- package/lib/module/types/AdshiftDeepLink.js +121 -0
- package/lib/module/types/AdshiftDeepLink.js.map +1 -0
- package/lib/module/types/AdshiftEventType.js +108 -0
- package/lib/module/types/AdshiftEventType.js.map +1 -0
- package/lib/module/types/index.js +10 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/Adshift.d.ts +335 -0
- package/lib/typescript/src/Adshift.d.ts.map +1 -0
- package/lib/typescript/src/NativeAdShiftReactNativePlugin.d.ts +143 -0
- package/lib/typescript/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +47 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types/AdshiftConfig.d.ts +74 -0
- package/lib/typescript/src/types/AdshiftConfig.d.ts.map +1 -0
- package/lib/typescript/src/types/AdshiftConsent.d.ts +88 -0
- package/lib/typescript/src/types/AdshiftConsent.d.ts.map +1 -0
- package/lib/typescript/src/types/AdshiftDeepLink.d.ts +93 -0
- package/lib/typescript/src/types/AdshiftDeepLink.d.ts.map +1 -0
- package/lib/typescript/src/types/AdshiftEventType.d.ts +87 -0
- package/lib/typescript/src/types/AdshiftEventType.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +5 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/package.json +143 -0
- package/src/Adshift.ts +539 -0
- package/src/NativeAdShiftReactNativePlugin.ts +177 -0
- package/src/index.tsx +68 -0
- package/src/types/AdshiftConfig.ts +108 -0
- package/src/types/AdshiftConsent.ts +127 -0
- package/src/types/AdshiftDeepLink.ts +194 -0
- package/src/types/AdshiftEventType.ts +135 -0
- package/src/types/index.ts +7 -0
package/src/index.tsx
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AdShift React Native Plugin
|
|
3
|
+
*
|
|
4
|
+
* Mobile Attribution, Event Tracking, SKAdNetwork 4.0+, Deep Linking
|
|
5
|
+
* and GDPR/TCF 2.2 Compliance.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* Adshift,
|
|
11
|
+
* AdshiftEventType,
|
|
12
|
+
* AdshiftConsent,
|
|
13
|
+
* AdshiftDeepLinkStatus,
|
|
14
|
+
* } from '@adshift/react-native-plugin';
|
|
15
|
+
*
|
|
16
|
+
* // 1. Initialize
|
|
17
|
+
* Adshift.initialize({ apiKey: 'your-api-key', isDebug: __DEV__ });
|
|
18
|
+
*
|
|
19
|
+
* // 2. Start tracking
|
|
20
|
+
* await Adshift.start();
|
|
21
|
+
*
|
|
22
|
+
* // 3. Track events
|
|
23
|
+
* await Adshift.trackEvent(AdshiftEventType.Purchase, { price: 9.99 });
|
|
24
|
+
*
|
|
25
|
+
* // 4. Handle deep links
|
|
26
|
+
* const subscription = Adshift.onDeepLink((deepLink) => {
|
|
27
|
+
* if (deepLink.status === AdshiftDeepLinkStatus.Found) {
|
|
28
|
+
* // Navigate based on deep link
|
|
29
|
+
* }
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @packageDocumentation
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
// ============ Main SDK API ============
|
|
37
|
+
export { Adshift, default } from './Adshift';
|
|
38
|
+
|
|
39
|
+
// ============ Types from Adshift.ts ============
|
|
40
|
+
export type {
|
|
41
|
+
StartResult,
|
|
42
|
+
EventValues,
|
|
43
|
+
PurchaseParams,
|
|
44
|
+
DeepLinkSubscription,
|
|
45
|
+
DeepLinkCallback,
|
|
46
|
+
} from './Adshift';
|
|
47
|
+
|
|
48
|
+
// ============ Config ============
|
|
49
|
+
export type { AdshiftConfig } from './types';
|
|
50
|
+
export { configToMap } from './types';
|
|
51
|
+
|
|
52
|
+
// ============ Consent ============
|
|
53
|
+
// Note: AdshiftConsent is both a type (interface) and value (helper object)
|
|
54
|
+
export { AdshiftConsent, consentToMap } from './types';
|
|
55
|
+
export type { AdshiftConsent as AdshiftConsentType } from './types';
|
|
56
|
+
|
|
57
|
+
// ============ Deep Link ============
|
|
58
|
+
// Note: AdshiftDeepLink is both a type (interface) and value (helper object)
|
|
59
|
+
export { AdshiftDeepLinkStatus, AdshiftDeepLink, deepLinkToMap } from './types';
|
|
60
|
+
export type { AdshiftDeepLink as AdshiftDeepLinkType } from './types';
|
|
61
|
+
|
|
62
|
+
// ============ Event Types ============
|
|
63
|
+
export { AdshiftEventType, getAllEventTypes } from './types';
|
|
64
|
+
export type { AdshiftEventTypeValue } from './types';
|
|
65
|
+
|
|
66
|
+
// ============ Native Module (Advanced Usage) ============
|
|
67
|
+
export { default as NativeAdShiftReactNativePlugin } from './NativeAdShiftReactNativePlugin';
|
|
68
|
+
export type { Spec as AdShiftNativeSpec } from './NativeAdShiftReactNativePlugin';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for initializing the AdShift SDK.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* const config: AdshiftConfig = {
|
|
7
|
+
* apiKey: 'your-api-key',
|
|
8
|
+
* isDebug: true,
|
|
9
|
+
* };
|
|
10
|
+
* await Adshift.initialize(config);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface AdshiftConfig {
|
|
14
|
+
/**
|
|
15
|
+
* API key for authenticating with AdShift backend.
|
|
16
|
+
*
|
|
17
|
+
* Required. Get your API key from the AdShift dashboard.
|
|
18
|
+
*/
|
|
19
|
+
apiKey: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Enable debug logging.
|
|
23
|
+
*
|
|
24
|
+
* When true, SDK will output verbose logs for debugging.
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
isDebug?: boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Debounce interval for automatic APP_OPEN events (in milliseconds).
|
|
31
|
+
*
|
|
32
|
+
* Controls how often APP_OPEN events are sent when app returns from background.
|
|
33
|
+
* @default 10000 (10 seconds)
|
|
34
|
+
*/
|
|
35
|
+
appOpenDebounceMs?: number;
|
|
36
|
+
|
|
37
|
+
// ============ iOS-only options ============
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Disable SKAdNetwork integration (iOS only).
|
|
41
|
+
*
|
|
42
|
+
* Set to true to completely disable SKAN functionality.
|
|
43
|
+
* @default false (SKAN enabled)
|
|
44
|
+
* @platform ios
|
|
45
|
+
*/
|
|
46
|
+
disableSKAN?: boolean;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Wait for ATT authorization before sending install event (iOS only).
|
|
50
|
+
*
|
|
51
|
+
* When enabled, SDK will wait for App Tracking Transparency authorization
|
|
52
|
+
* before sending the install event to include IDFA if user grants permission.
|
|
53
|
+
* @default false
|
|
54
|
+
* @platform ios
|
|
55
|
+
*/
|
|
56
|
+
waitForATTBeforeStart?: boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Timeout for ATT authorization wait in milliseconds (iOS only).
|
|
60
|
+
*
|
|
61
|
+
* Maximum time to wait for ATT response when `waitForATTBeforeStart` is enabled.
|
|
62
|
+
* Range: 5000 - 120000 (5s - 2 minutes)
|
|
63
|
+
* @default 30000 (30 seconds)
|
|
64
|
+
* @platform ios
|
|
65
|
+
*/
|
|
66
|
+
attTimeoutMs?: number;
|
|
67
|
+
|
|
68
|
+
// ============ Android-only options ============
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Enable OAID collection (Android only).
|
|
72
|
+
*
|
|
73
|
+
* OAID is an alternative to Google Advertising ID used on Chinese Android devices.
|
|
74
|
+
* @default true
|
|
75
|
+
* @platform android
|
|
76
|
+
*/
|
|
77
|
+
collectOaid?: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Converts AdshiftConfig to a plain object for native bridge communication.
|
|
82
|
+
* Filters out undefined values.
|
|
83
|
+
*/
|
|
84
|
+
export function configToMap(config: AdshiftConfig): Record<string, unknown> {
|
|
85
|
+
const map: Record<string, unknown> = {
|
|
86
|
+
apiKey: config.apiKey,
|
|
87
|
+
isDebug: config.isDebug ?? false,
|
|
88
|
+
appOpenDebounceMs: config.appOpenDebounceMs ?? 10000,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// iOS only
|
|
92
|
+
if (config.disableSKAN !== undefined) {
|
|
93
|
+
map.disableSKAN = config.disableSKAN;
|
|
94
|
+
}
|
|
95
|
+
if (config.waitForATTBeforeStart !== undefined) {
|
|
96
|
+
map.waitForATTBeforeStart = config.waitForATTBeforeStart;
|
|
97
|
+
}
|
|
98
|
+
if (config.attTimeoutMs !== undefined) {
|
|
99
|
+
map.attTimeoutMs = config.attTimeoutMs;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Android only
|
|
103
|
+
if (config.collectOaid !== undefined) {
|
|
104
|
+
map.collectOaid = config.collectOaid;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return map;
|
|
108
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User consent data for GDPR/DMA compliance.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* // For GDPR users who accepted all
|
|
7
|
+
* const consent = AdshiftConsent.forGDPRUser({
|
|
8
|
+
* hasConsentForDataUsage: true,
|
|
9
|
+
* hasConsentForAdsPersonalization: true,
|
|
10
|
+
* hasConsentForAdStorage: true,
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* // For non-GDPR users
|
|
14
|
+
* const consent = AdshiftConsent.forNonGDPRUser();
|
|
15
|
+
*
|
|
16
|
+
* await Adshift.setConsentData(consent);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface AdshiftConsent {
|
|
20
|
+
/**
|
|
21
|
+
* Whether the user is subject to GDPR.
|
|
22
|
+
*/
|
|
23
|
+
isUserSubjectToGDPR: boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether user has consented to data usage.
|
|
27
|
+
*/
|
|
28
|
+
hasConsentForDataUsage: boolean;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Whether user has consented to ads personalization.
|
|
32
|
+
*/
|
|
33
|
+
hasConsentForAdsPersonalization: boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Whether user has consented to ad storage.
|
|
37
|
+
*/
|
|
38
|
+
hasConsentForAdStorage: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Helper functions for creating AdshiftConsent objects.
|
|
43
|
+
*/
|
|
44
|
+
export const AdshiftConsent = {
|
|
45
|
+
/**
|
|
46
|
+
* Creates consent for a user subject to GDPR.
|
|
47
|
+
*
|
|
48
|
+
* Use this when user is in a GDPR region and has provided explicit consent.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const consent = AdshiftConsent.forGDPRUser({
|
|
53
|
+
* hasConsentForDataUsage: true,
|
|
54
|
+
* hasConsentForAdsPersonalization: true,
|
|
55
|
+
* hasConsentForAdStorage: true,
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
forGDPRUser(options: {
|
|
60
|
+
hasConsentForDataUsage: boolean;
|
|
61
|
+
hasConsentForAdsPersonalization: boolean;
|
|
62
|
+
hasConsentForAdStorage: boolean;
|
|
63
|
+
}): AdshiftConsent {
|
|
64
|
+
return {
|
|
65
|
+
isUserSubjectToGDPR: true,
|
|
66
|
+
hasConsentForDataUsage: options.hasConsentForDataUsage,
|
|
67
|
+
hasConsentForAdsPersonalization: options.hasConsentForAdsPersonalization,
|
|
68
|
+
hasConsentForAdStorage: options.hasConsentForAdStorage,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Creates consent for a user NOT subject to GDPR.
|
|
74
|
+
*
|
|
75
|
+
* Use this when user is in a non-GDPR region (e.g., US, Asia).
|
|
76
|
+
* All consent flags are set to true by default.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const consent = AdshiftConsent.forNonGDPRUser();
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
forNonGDPRUser(): AdshiftConsent {
|
|
84
|
+
return {
|
|
85
|
+
isUserSubjectToGDPR: false,
|
|
86
|
+
hasConsentForDataUsage: true,
|
|
87
|
+
hasConsentForAdsPersonalization: true,
|
|
88
|
+
hasConsentForAdStorage: true,
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Determines whether consent is granted for tracking.
|
|
94
|
+
*
|
|
95
|
+
* If user is not subject to GDPR, consent is assumed granted.
|
|
96
|
+
* If subject to GDPR, both data usage and ad storage must be granted.
|
|
97
|
+
*/
|
|
98
|
+
isConsentGranted(consent: AdshiftConsent): boolean {
|
|
99
|
+
if (!consent.isUserSubjectToGDPR) return true;
|
|
100
|
+
return consent.hasConsentForDataUsage && consent.hasConsentForAdStorage;
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates consent from a plain object (native bridge response).
|
|
105
|
+
*/
|
|
106
|
+
fromMap(map: Record<string, unknown>): AdshiftConsent {
|
|
107
|
+
return {
|
|
108
|
+
isUserSubjectToGDPR: (map.isUserSubjectToGDPR as boolean) ?? false,
|
|
109
|
+
hasConsentForDataUsage: (map.hasConsentForDataUsage as boolean) ?? false,
|
|
110
|
+
hasConsentForAdsPersonalization:
|
|
111
|
+
(map.hasConsentForAdsPersonalization as boolean) ?? false,
|
|
112
|
+
hasConsentForAdStorage: (map.hasConsentForAdStorage as boolean) ?? false,
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Converts AdshiftConsent to a plain object for native bridge communication.
|
|
119
|
+
*/
|
|
120
|
+
export function consentToMap(consent: AdshiftConsent): Record<string, boolean> {
|
|
121
|
+
return {
|
|
122
|
+
isUserSubjectToGDPR: consent.isUserSubjectToGDPR,
|
|
123
|
+
hasConsentForDataUsage: consent.hasConsentForDataUsage,
|
|
124
|
+
hasConsentForAdsPersonalization: consent.hasConsentForAdsPersonalization,
|
|
125
|
+
hasConsentForAdStorage: consent.hasConsentForAdStorage,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status of a deep link resolution.
|
|
3
|
+
*/
|
|
4
|
+
export enum AdshiftDeepLinkStatus {
|
|
5
|
+
/** Deep link was found and resolved successfully. */
|
|
6
|
+
Found = 'found',
|
|
7
|
+
|
|
8
|
+
/** No deep link was found (e.g., organic install). */
|
|
9
|
+
NotFound = 'notFound',
|
|
10
|
+
|
|
11
|
+
/** Error occurred while resolving deep link. */
|
|
12
|
+
Error = 'error',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Response from deep link handling.
|
|
17
|
+
*
|
|
18
|
+
* Contains the resolved deep link URL, parameters, and status.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const deepLink = await Adshift.handleDeepLink(url);
|
|
23
|
+
* if (deepLink.status === AdshiftDeepLinkStatus.Found) {
|
|
24
|
+
* const productId = deepLink.params?.['product_id'];
|
|
25
|
+
* // Navigate to product
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface AdshiftDeepLink {
|
|
30
|
+
/** The deep link URL string. */
|
|
31
|
+
deepLink?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Standardized resolved value for routing.
|
|
35
|
+
* This is the main routing value extracted from the deep link.
|
|
36
|
+
*/
|
|
37
|
+
deepLinkValue?: string;
|
|
38
|
+
|
|
39
|
+
/** Query parameters extracted from the deep link. */
|
|
40
|
+
params?: Record<string, unknown>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether this is a deferred deep link.
|
|
44
|
+
*
|
|
45
|
+
* Deferred deep links are resolved after app install,
|
|
46
|
+
* typically from ad campaigns.
|
|
47
|
+
*/
|
|
48
|
+
isDeferred: boolean;
|
|
49
|
+
|
|
50
|
+
/** Status of the deep link resolution. */
|
|
51
|
+
status: AdshiftDeepLinkStatus;
|
|
52
|
+
|
|
53
|
+
/** Error message if status is Error. */
|
|
54
|
+
errorMessage?: string;
|
|
55
|
+
|
|
56
|
+
// ============ Custom sub-parameters (OneLink style) ============
|
|
57
|
+
|
|
58
|
+
/** Custom sub-parameter 1. */
|
|
59
|
+
deepLinkSub1?: string;
|
|
60
|
+
|
|
61
|
+
/** Custom sub-parameter 2. */
|
|
62
|
+
deepLinkSub2?: string;
|
|
63
|
+
|
|
64
|
+
/** Custom sub-parameter 3. */
|
|
65
|
+
deepLinkSub3?: string;
|
|
66
|
+
|
|
67
|
+
/** Custom sub-parameter 4. */
|
|
68
|
+
deepLinkSub4?: string;
|
|
69
|
+
|
|
70
|
+
/** Custom sub-parameter 5. */
|
|
71
|
+
deepLinkSub5?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Helper functions for creating AdshiftDeepLink objects.
|
|
76
|
+
*/
|
|
77
|
+
export const AdshiftDeepLink = {
|
|
78
|
+
/**
|
|
79
|
+
* Creates a successful deep link response.
|
|
80
|
+
*/
|
|
81
|
+
found(options: {
|
|
82
|
+
deepLink: string;
|
|
83
|
+
deepLinkValue?: string;
|
|
84
|
+
params?: Record<string, unknown>;
|
|
85
|
+
isDeferred?: boolean;
|
|
86
|
+
deepLinkSub1?: string;
|
|
87
|
+
deepLinkSub2?: string;
|
|
88
|
+
deepLinkSub3?: string;
|
|
89
|
+
deepLinkSub4?: string;
|
|
90
|
+
deepLinkSub5?: string;
|
|
91
|
+
}): AdshiftDeepLink {
|
|
92
|
+
return {
|
|
93
|
+
deepLink: options.deepLink,
|
|
94
|
+
deepLinkValue: options.deepLinkValue,
|
|
95
|
+
params: options.params,
|
|
96
|
+
isDeferred: options.isDeferred ?? false,
|
|
97
|
+
status: AdshiftDeepLinkStatus.Found,
|
|
98
|
+
deepLinkSub1: options.deepLinkSub1,
|
|
99
|
+
deepLinkSub2: options.deepLinkSub2,
|
|
100
|
+
deepLinkSub3: options.deepLinkSub3,
|
|
101
|
+
deepLinkSub4: options.deepLinkSub4,
|
|
102
|
+
deepLinkSub5: options.deepLinkSub5,
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Creates a "not found" deep link response.
|
|
108
|
+
*/
|
|
109
|
+
notFound(): AdshiftDeepLink {
|
|
110
|
+
return {
|
|
111
|
+
isDeferred: false,
|
|
112
|
+
status: AdshiftDeepLinkStatus.NotFound,
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Creates an error deep link response.
|
|
118
|
+
*/
|
|
119
|
+
error(message: string): AdshiftDeepLink {
|
|
120
|
+
return {
|
|
121
|
+
isDeferred: false,
|
|
122
|
+
status: AdshiftDeepLinkStatus.Error,
|
|
123
|
+
errorMessage: message,
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Creates deep link from a plain object (native bridge response).
|
|
129
|
+
*/
|
|
130
|
+
fromMap(map: Record<string, unknown>): AdshiftDeepLink {
|
|
131
|
+
const statusStr = (map.status as string) ?? 'notFound';
|
|
132
|
+
let status: AdshiftDeepLinkStatus;
|
|
133
|
+
|
|
134
|
+
switch (statusStr) {
|
|
135
|
+
case 'found':
|
|
136
|
+
status = AdshiftDeepLinkStatus.Found;
|
|
137
|
+
break;
|
|
138
|
+
case 'error':
|
|
139
|
+
status = AdshiftDeepLinkStatus.Error;
|
|
140
|
+
break;
|
|
141
|
+
default:
|
|
142
|
+
status = AdshiftDeepLinkStatus.NotFound;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
deepLink: (map.deepLink ?? map.deeplink) as string | undefined,
|
|
147
|
+
deepLinkValue: (map.deepLinkValue ?? map.deep_link_value) as
|
|
148
|
+
| string
|
|
149
|
+
| undefined,
|
|
150
|
+
params: (map.params ?? map.queryParams) as
|
|
151
|
+
| Record<string, unknown>
|
|
152
|
+
| undefined,
|
|
153
|
+
isDeferred: (map.isDeferred as boolean) ?? false,
|
|
154
|
+
status,
|
|
155
|
+
errorMessage: (map.errorMessage ?? map.error) as string | undefined,
|
|
156
|
+
deepLinkSub1: (map.deepLinkSub1 ?? map.deep_link_sub1 ?? map.sub1) as
|
|
157
|
+
| string
|
|
158
|
+
| undefined,
|
|
159
|
+
deepLinkSub2: (map.deepLinkSub2 ?? map.deep_link_sub2 ?? map.sub2) as
|
|
160
|
+
| string
|
|
161
|
+
| undefined,
|
|
162
|
+
deepLinkSub3: (map.deepLinkSub3 ?? map.deep_link_sub3 ?? map.sub3) as
|
|
163
|
+
| string
|
|
164
|
+
| undefined,
|
|
165
|
+
deepLinkSub4: (map.deepLinkSub4 ?? map.deep_link_sub4 ?? map.sub4) as
|
|
166
|
+
| string
|
|
167
|
+
| undefined,
|
|
168
|
+
deepLinkSub5: (map.deepLinkSub5 ?? map.deep_link_sub5 ?? map.sub5) as
|
|
169
|
+
| string
|
|
170
|
+
| undefined,
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Converts AdshiftDeepLink to a plain object for native bridge communication.
|
|
177
|
+
*/
|
|
178
|
+
export function deepLinkToMap(
|
|
179
|
+
deepLink: AdshiftDeepLink
|
|
180
|
+
): Record<string, unknown> {
|
|
181
|
+
return {
|
|
182
|
+
deepLink: deepLink.deepLink,
|
|
183
|
+
deepLinkValue: deepLink.deepLinkValue,
|
|
184
|
+
params: deepLink.params,
|
|
185
|
+
isDeferred: deepLink.isDeferred,
|
|
186
|
+
status: deepLink.status,
|
|
187
|
+
errorMessage: deepLink.errorMessage,
|
|
188
|
+
deepLinkSub1: deepLink.deepLinkSub1,
|
|
189
|
+
deepLinkSub2: deepLink.deepLinkSub2,
|
|
190
|
+
deepLinkSub3: deepLink.deepLinkSub3,
|
|
191
|
+
deepLinkSub4: deepLink.deepLinkSub4,
|
|
192
|
+
deepLinkSub5: deepLink.deepLinkSub5,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Predefined event types for AdShift SDK.
|
|
3
|
+
*
|
|
4
|
+
* Use these constants for consistent event naming across your app.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* await Adshift.trackEvent(AdshiftEventType.AddToCart, {
|
|
9
|
+
* product_id: 'SKU123',
|
|
10
|
+
* price: 29.99,
|
|
11
|
+
* });
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* You can also use custom event names as strings:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* await Adshift.trackEvent('custom_event_name');
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const AdshiftEventType = {
|
|
20
|
+
// ============ E-commerce Events ============
|
|
21
|
+
|
|
22
|
+
/** User added item to cart. */
|
|
23
|
+
AddToCart: 'as_add_to_cart',
|
|
24
|
+
|
|
25
|
+
/** User added item to wishlist. */
|
|
26
|
+
AddToWishList: 'as_add_to_wishlist',
|
|
27
|
+
|
|
28
|
+
/** User added payment info. */
|
|
29
|
+
AddPaymentInfo: 'as_add_payment_info',
|
|
30
|
+
|
|
31
|
+
/** User initiated checkout. */
|
|
32
|
+
InitiatedCheckout: 'as_initiated_checkout',
|
|
33
|
+
|
|
34
|
+
/** User completed a purchase. */
|
|
35
|
+
Purchase: 'as_purchase',
|
|
36
|
+
|
|
37
|
+
/** User viewed content/product. */
|
|
38
|
+
ContentView: 'as_content_view',
|
|
39
|
+
|
|
40
|
+
/** User viewed a list of items. */
|
|
41
|
+
ListView: 'as_list_view',
|
|
42
|
+
|
|
43
|
+
/** User searched. */
|
|
44
|
+
Search: 'as_search',
|
|
45
|
+
|
|
46
|
+
// ============ User Lifecycle Events ============
|
|
47
|
+
|
|
48
|
+
/** User completed registration. */
|
|
49
|
+
CompleteRegistration: 'as_complete_registration',
|
|
50
|
+
|
|
51
|
+
/** User logged in. */
|
|
52
|
+
Login: 'as_login',
|
|
53
|
+
|
|
54
|
+
/** User completed tutorial. */
|
|
55
|
+
TutorialCompletion: 'as_tutorial_completion',
|
|
56
|
+
|
|
57
|
+
/** User subscribed. */
|
|
58
|
+
Subscribe: 'as_subscribe',
|
|
59
|
+
|
|
60
|
+
/** User started a trial. */
|
|
61
|
+
StartTrial: 'as_start_trial',
|
|
62
|
+
|
|
63
|
+
// ============ Gaming Events ============
|
|
64
|
+
|
|
65
|
+
/** User achieved a level. */
|
|
66
|
+
LevelAchieved: 'as_level_achieved',
|
|
67
|
+
|
|
68
|
+
/** User unlocked an achievement. */
|
|
69
|
+
AchievementUnlocked: 'as_achievement_unlocked',
|
|
70
|
+
|
|
71
|
+
/** User spent credits/currency. */
|
|
72
|
+
SpentCredit: 'as_spent_credits',
|
|
73
|
+
|
|
74
|
+
// ============ Engagement Events ============
|
|
75
|
+
|
|
76
|
+
/** User rated the app/content. */
|
|
77
|
+
Rate: 'as_rate',
|
|
78
|
+
|
|
79
|
+
/** User shared content. */
|
|
80
|
+
Share: 'as_share',
|
|
81
|
+
|
|
82
|
+
/** User invited others. */
|
|
83
|
+
Invite: 'as_invite',
|
|
84
|
+
|
|
85
|
+
/** User re-engaged with the app. */
|
|
86
|
+
ReEngage: 'as_re_engage',
|
|
87
|
+
|
|
88
|
+
/** User updated the app. */
|
|
89
|
+
Update: 'as_update',
|
|
90
|
+
|
|
91
|
+
/** User opened from push notification. */
|
|
92
|
+
OpenedFromPushNotification: 'as_opened_from_push_notification',
|
|
93
|
+
|
|
94
|
+
// ============ Travel Events ============
|
|
95
|
+
|
|
96
|
+
/** User made a travel booking. */
|
|
97
|
+
TravelBooking: 'as_travel_booking',
|
|
98
|
+
|
|
99
|
+
// ============ Ad Events ============
|
|
100
|
+
|
|
101
|
+
/** User clicked an ad. */
|
|
102
|
+
AdClick: 'as_ad_click',
|
|
103
|
+
|
|
104
|
+
/** User viewed an ad. */
|
|
105
|
+
AdView: 'as_ad_view',
|
|
106
|
+
|
|
107
|
+
// ============ Location Events ============
|
|
108
|
+
|
|
109
|
+
/** User location changed. */
|
|
110
|
+
LocationChanged: 'as_location_changed',
|
|
111
|
+
|
|
112
|
+
/** User location coordinates updated. */
|
|
113
|
+
LocationCoordinates: 'as_location_coordinates',
|
|
114
|
+
|
|
115
|
+
// ============ Other Events ============
|
|
116
|
+
|
|
117
|
+
/** Order ID event. */
|
|
118
|
+
OrderId: 'as_order_id',
|
|
119
|
+
|
|
120
|
+
/** Customer segment event. */
|
|
121
|
+
CustomerSegment: 'as_customer_segment',
|
|
122
|
+
} as const;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Type representing all predefined event type values.
|
|
126
|
+
*/
|
|
127
|
+
export type AdshiftEventTypeValue =
|
|
128
|
+
(typeof AdshiftEventType)[keyof typeof AdshiftEventType];
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Returns all predefined event types as an array.
|
|
132
|
+
*/
|
|
133
|
+
export function getAllEventTypes(): string[] {
|
|
134
|
+
return Object.values(AdshiftEventType);
|
|
135
|
+
}
|