@datalyr/react-native 1.1.1 → 1.2.1

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +31 -140
  2. package/LICENSE +21 -0
  3. package/README.md +434 -217
  4. package/datalyr-react-native.podspec +31 -0
  5. package/ios/DatalyrNative.m +74 -0
  6. package/ios/DatalyrNative.swift +332 -0
  7. package/ios/DatalyrSKAdNetwork.m +26 -0
  8. package/lib/datalyr-sdk.d.ts +73 -3
  9. package/lib/datalyr-sdk.js +353 -3
  10. package/lib/index.d.ts +2 -0
  11. package/lib/index.js +4 -2
  12. package/lib/integrations/apple-search-ads-integration.d.ts +43 -0
  13. package/lib/integrations/apple-search-ads-integration.js +106 -0
  14. package/lib/integrations/index.d.ts +7 -0
  15. package/lib/integrations/index.js +7 -0
  16. package/lib/integrations/meta-integration.d.ts +76 -0
  17. package/lib/integrations/meta-integration.js +218 -0
  18. package/lib/integrations/tiktok-integration.d.ts +82 -0
  19. package/lib/integrations/tiktok-integration.js +356 -0
  20. package/lib/native/DatalyrNativeBridge.d.ts +57 -0
  21. package/lib/native/DatalyrNativeBridge.js +187 -0
  22. package/lib/native/index.d.ts +5 -0
  23. package/lib/native/index.js +5 -0
  24. package/lib/types.d.ts +29 -0
  25. package/package.json +11 -5
  26. package/src/datalyr-sdk-expo.ts +997 -0
  27. package/src/datalyr-sdk.ts +455 -19
  28. package/src/expo.ts +42 -18
  29. package/src/index.ts +8 -2
  30. package/src/integrations/apple-search-ads-integration.ts +119 -0
  31. package/src/integrations/index.ts +8 -0
  32. package/src/integrations/meta-integration.ts +238 -0
  33. package/src/integrations/tiktok-integration.ts +360 -0
  34. package/src/native/DatalyrNativeBridge.ts +313 -0
  35. package/src/native/index.ts +11 -0
  36. package/src/types.ts +39 -0
  37. package/src/utils-expo.ts +25 -3
  38. package/src/utils-interface.ts +38 -0
  39. package/EXPO_INSTALL.md +0 -297
  40. package/INSTALL.md +0 -402
  41. package/examples/attribution-example.tsx +0 -377
  42. package/examples/auto-events-example.tsx +0 -403
  43. package/examples/example.tsx +0 -250
  44. package/examples/skadnetwork-example.tsx +0 -380
  45. package/examples/test-implementation.tsx +0 -163
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Meta (Facebook) SDK Integration
3
+ * Uses bundled native iOS SDK for deferred deep linking, event forwarding, and Advanced Matching
4
+ */
5
+ import { MetaConfig, DeferredDeepLinkResult } from '../types';
6
+ /**
7
+ * Meta Integration class for handling Facebook SDK operations
8
+ * Uses native iOS SDK bundled via CocoaPods (no additional npm packages required)
9
+ */
10
+ export declare class MetaIntegration {
11
+ private config;
12
+ private initialized;
13
+ private available;
14
+ private debug;
15
+ private deferredDeepLinkData;
16
+ /**
17
+ * Initialize Meta SDK with configuration
18
+ */
19
+ initialize(config: MetaConfig, debug?: boolean): Promise<void>;
20
+ /**
21
+ * Update tracking authorization status (call after ATT prompt)
22
+ */
23
+ updateTrackingAuthorization(enabled: boolean): Promise<void>;
24
+ /**
25
+ * Fetch deferred deep link from Meta SDK
26
+ * This captures fbclid for installs that went through App Store
27
+ */
28
+ fetchDeferredDeepLink(): Promise<DeferredDeepLinkResult | null>;
29
+ /**
30
+ * Parse deep link URL to extract attribution parameters
31
+ */
32
+ private parseDeepLinkUrl;
33
+ /**
34
+ * Log purchase event to Meta
35
+ */
36
+ logPurchase(value: number, currency: string, parameters?: Record<string, any>): Promise<void>;
37
+ /**
38
+ * Log custom event to Meta
39
+ */
40
+ logEvent(eventName: string, valueToSum?: number, parameters?: Record<string, any>): Promise<void>;
41
+ /**
42
+ * Set user data for Advanced Matching (improves conversion attribution)
43
+ * Note: Meta's Advanced Matching uses these specific fields - externalId is not supported
44
+ */
45
+ setUserData(userData: {
46
+ email?: string;
47
+ firstName?: string;
48
+ lastName?: string;
49
+ phone?: string;
50
+ dateOfBirth?: string;
51
+ gender?: string;
52
+ city?: string;
53
+ state?: string;
54
+ zip?: string;
55
+ country?: string;
56
+ }): Promise<void>;
57
+ /**
58
+ * Clear user data (call on logout)
59
+ */
60
+ clearUserData(): Promise<void>;
61
+ /**
62
+ * Get cached deferred deep link data
63
+ */
64
+ getDeferredDeepLinkData(): DeferredDeepLinkResult | null;
65
+ /**
66
+ * Check if Meta SDK is available and initialized
67
+ */
68
+ isAvailable(): boolean;
69
+ /**
70
+ * Check if Meta SDK native module is installed
71
+ */
72
+ isInstalled(): boolean;
73
+ private log;
74
+ private logError;
75
+ }
76
+ export declare const metaIntegration: MetaIntegration;
@@ -0,0 +1,218 @@
1
+ /**
2
+ * Meta (Facebook) SDK Integration
3
+ * Uses bundled native iOS SDK for deferred deep linking, event forwarding, and Advanced Matching
4
+ */
5
+ import { Platform } from 'react-native';
6
+ import { MetaNativeBridge, isNativeModuleAvailable } from '../native/DatalyrNativeBridge';
7
+ /**
8
+ * Meta Integration class for handling Facebook SDK operations
9
+ * Uses native iOS SDK bundled via CocoaPods (no additional npm packages required)
10
+ */
11
+ export class MetaIntegration {
12
+ constructor() {
13
+ this.config = null;
14
+ this.initialized = false;
15
+ this.available = false;
16
+ this.debug = false;
17
+ this.deferredDeepLinkData = null;
18
+ }
19
+ /**
20
+ * Initialize Meta SDK with configuration
21
+ */
22
+ async initialize(config, debug = false) {
23
+ var _a;
24
+ this.debug = debug;
25
+ this.config = config;
26
+ // Only available on iOS via native module
27
+ if (Platform.OS !== 'ios') {
28
+ this.log('Meta SDK only available on iOS');
29
+ return;
30
+ }
31
+ this.available = isNativeModuleAvailable();
32
+ if (!this.available) {
33
+ this.log('Meta native module not available');
34
+ return;
35
+ }
36
+ try {
37
+ const success = await MetaNativeBridge.initialize(config.appId, config.clientToken, (_a = config.advertiserTrackingEnabled) !== null && _a !== void 0 ? _a : false);
38
+ if (success) {
39
+ this.initialized = true;
40
+ this.log(`Meta SDK initialized with App ID: ${config.appId}`);
41
+ }
42
+ }
43
+ catch (error) {
44
+ this.logError('Failed to initialize Meta SDK:', error);
45
+ }
46
+ }
47
+ /**
48
+ * Update tracking authorization status (call after ATT prompt)
49
+ */
50
+ async updateTrackingAuthorization(enabled) {
51
+ if (!this.available || !this.initialized)
52
+ return;
53
+ try {
54
+ await MetaNativeBridge.updateTrackingAuthorization(enabled);
55
+ this.log(`Meta ATT status updated: ${enabled ? 'authorized' : 'not authorized'}`);
56
+ }
57
+ catch (error) {
58
+ this.logError('Failed to update Meta tracking authorization:', error);
59
+ }
60
+ }
61
+ /**
62
+ * Fetch deferred deep link from Meta SDK
63
+ * This captures fbclid for installs that went through App Store
64
+ */
65
+ async fetchDeferredDeepLink() {
66
+ var _a;
67
+ if (!this.available || !this.initialized) {
68
+ return null;
69
+ }
70
+ if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableDeferredDeepLink) === false) {
71
+ return null;
72
+ }
73
+ try {
74
+ const url = await MetaNativeBridge.fetchDeferredAppLink();
75
+ if (!url) {
76
+ this.log('No deferred deep link available from Meta');
77
+ return null;
78
+ }
79
+ // Parse the URL for attribution parameters
80
+ const result = this.parseDeepLinkUrl(url);
81
+ this.deferredDeepLinkData = result;
82
+ this.log(`Meta deferred deep link fetched: ${url}`);
83
+ return result;
84
+ }
85
+ catch (error) {
86
+ // This is expected to fail in some scenarios - log but don't treat as error
87
+ this.log('Could not fetch Meta deferred deep link (may not be available)');
88
+ return null;
89
+ }
90
+ }
91
+ /**
92
+ * Parse deep link URL to extract attribution parameters
93
+ */
94
+ parseDeepLinkUrl(urlString) {
95
+ const result = {
96
+ url: urlString,
97
+ source: 'meta',
98
+ };
99
+ try {
100
+ const url = new URL(urlString);
101
+ const params = url.searchParams;
102
+ // Extract known parameters
103
+ if (params.get('fbclid'))
104
+ result.fbclid = params.get('fbclid');
105
+ if (params.get('utm_source'))
106
+ result.utmSource = params.get('utm_source');
107
+ if (params.get('utm_medium'))
108
+ result.utmMedium = params.get('utm_medium');
109
+ if (params.get('utm_campaign'))
110
+ result.utmCampaign = params.get('utm_campaign');
111
+ if (params.get('utm_content'))
112
+ result.utmContent = params.get('utm_content');
113
+ if (params.get('utm_term'))
114
+ result.utmTerm = params.get('utm_term');
115
+ if (params.get('campaign_id'))
116
+ result.campaignId = params.get('campaign_id');
117
+ if (params.get('adset_id'))
118
+ result.adsetId = params.get('adset_id');
119
+ if (params.get('ad_id'))
120
+ result.adId = params.get('ad_id');
121
+ }
122
+ catch (error) {
123
+ this.logError('Failed to parse deep link URL:', error);
124
+ }
125
+ return result;
126
+ }
127
+ /**
128
+ * Log purchase event to Meta
129
+ */
130
+ async logPurchase(value, currency, parameters) {
131
+ var _a;
132
+ if (!this.available || !this.initialized)
133
+ return;
134
+ if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
135
+ return;
136
+ try {
137
+ await MetaNativeBridge.logPurchase(value, currency, parameters);
138
+ this.log(`Meta purchase event logged: ${value} ${currency}`);
139
+ }
140
+ catch (error) {
141
+ this.logError('Failed to log Meta purchase:', error);
142
+ }
143
+ }
144
+ /**
145
+ * Log custom event to Meta
146
+ */
147
+ async logEvent(eventName, valueToSum, parameters) {
148
+ var _a;
149
+ if (!this.available || !this.initialized)
150
+ return;
151
+ if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
152
+ return;
153
+ try {
154
+ await MetaNativeBridge.logEvent(eventName, valueToSum, parameters);
155
+ this.log(`Meta event logged: ${eventName}`);
156
+ }
157
+ catch (error) {
158
+ this.logError('Failed to log Meta event:', error);
159
+ }
160
+ }
161
+ /**
162
+ * Set user data for Advanced Matching (improves conversion attribution)
163
+ * Note: Meta's Advanced Matching uses these specific fields - externalId is not supported
164
+ */
165
+ async setUserData(userData) {
166
+ if (!this.available || !this.initialized)
167
+ return;
168
+ try {
169
+ await MetaNativeBridge.setUserData(userData);
170
+ this.log('Meta user data set for Advanced Matching');
171
+ }
172
+ catch (error) {
173
+ this.logError('Failed to set Meta user data:', error);
174
+ }
175
+ }
176
+ /**
177
+ * Clear user data (call on logout)
178
+ */
179
+ async clearUserData() {
180
+ if (!this.available || !this.initialized)
181
+ return;
182
+ try {
183
+ await MetaNativeBridge.clearUserData();
184
+ this.log('Meta user data cleared');
185
+ }
186
+ catch (error) {
187
+ this.logError('Failed to clear Meta user data:', error);
188
+ }
189
+ }
190
+ /**
191
+ * Get cached deferred deep link data
192
+ */
193
+ getDeferredDeepLinkData() {
194
+ return this.deferredDeepLinkData;
195
+ }
196
+ /**
197
+ * Check if Meta SDK is available and initialized
198
+ */
199
+ isAvailable() {
200
+ return this.available && this.initialized;
201
+ }
202
+ /**
203
+ * Check if Meta SDK native module is installed
204
+ */
205
+ isInstalled() {
206
+ return this.available;
207
+ }
208
+ log(message, data) {
209
+ if (this.debug) {
210
+ console.log(`[Datalyr/Meta] ${message}`, data || '');
211
+ }
212
+ }
213
+ logError(message, error) {
214
+ console.error(`[Datalyr/Meta] ${message}`, error);
215
+ }
216
+ }
217
+ // Export singleton instance
218
+ export const metaIntegration = new MetaIntegration();
@@ -0,0 +1,82 @@
1
+ /**
2
+ * TikTok Business SDK Integration
3
+ * Uses bundled native iOS SDK for event forwarding and user identification
4
+ */
5
+ import { TikTokConfig } from '../types';
6
+ /**
7
+ * TikTok Integration class for handling TikTok Business SDK operations
8
+ * Uses native iOS SDK bundled via CocoaPods (no additional npm packages required)
9
+ */
10
+ export declare class TikTokIntegration {
11
+ private config;
12
+ private initialized;
13
+ private available;
14
+ private debug;
15
+ /**
16
+ * Initialize TikTok SDK with configuration
17
+ */
18
+ initialize(config: TikTokConfig, debug?: boolean): Promise<void>;
19
+ /**
20
+ * Update tracking authorization status (call after ATT prompt)
21
+ */
22
+ updateTrackingAuthorization(enabled: boolean): Promise<void>;
23
+ /**
24
+ * Log purchase event to TikTok (uses Purchase - TikTok's current standard event)
25
+ */
26
+ logPurchase(value: number, currency: string, contentId?: string, contentType?: string, parameters?: Record<string, any>): Promise<void>;
27
+ /**
28
+ * Log subscription event to TikTok
29
+ */
30
+ logSubscription(value: number, currency: string, plan?: string): Promise<void>;
31
+ /**
32
+ * Log add to cart event
33
+ */
34
+ logAddToCart(value: number, currency: string, contentId?: string, contentType?: string): Promise<void>;
35
+ /**
36
+ * Log view content event
37
+ */
38
+ logViewContent(contentId?: string, contentName?: string, contentType?: string): Promise<void>;
39
+ /**
40
+ * Log initiate checkout event
41
+ */
42
+ logInitiateCheckout(value: number, currency: string, numItems?: number): Promise<void>;
43
+ /**
44
+ * Log complete registration event
45
+ */
46
+ logCompleteRegistration(method?: string): Promise<void>;
47
+ /**
48
+ * Log search event
49
+ */
50
+ logSearch(query: string): Promise<void>;
51
+ /**
52
+ * Log lead event (uses Lead - current standard, SubmitForm is legacy)
53
+ */
54
+ logLead(value?: number, currency?: string): Promise<void>;
55
+ /**
56
+ * Log add payment info event
57
+ */
58
+ logAddPaymentInfo(success: boolean): Promise<void>;
59
+ /**
60
+ * Log custom event to TikTok
61
+ */
62
+ trackEvent(eventName: string, properties?: Record<string, any>): Promise<void>;
63
+ /**
64
+ * Identify user for improved attribution matching
65
+ */
66
+ identify(email?: string, phone?: string, externalId?: string): Promise<void>;
67
+ /**
68
+ * Clear user session (call on logout)
69
+ */
70
+ logout(): Promise<void>;
71
+ /**
72
+ * Check if TikTok SDK is available and initialized
73
+ */
74
+ isAvailable(): boolean;
75
+ /**
76
+ * Check if TikTok SDK native module is installed
77
+ */
78
+ isInstalled(): boolean;
79
+ private log;
80
+ private logError;
81
+ }
82
+ export declare const tiktokIntegration: TikTokIntegration;