@datalyr/react-native 1.5.0 → 1.6.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +3 -131
  3. package/android/build.gradle +0 -7
  4. package/android/src/main/java/com/datalyr/reactnative/DatalyrNativeModule.java +2 -380
  5. package/android/src/main/java/com/datalyr/reactnative/DatalyrPackage.java +1 -1
  6. package/datalyr-react-native.podspec +3 -7
  7. package/expo-module.config.json +4 -1
  8. package/ios/DatalyrNativeModule.swift +0 -266
  9. package/lib/datalyr-sdk.d.ts +1 -4
  10. package/lib/datalyr-sdk.js +7 -143
  11. package/lib/http-client.js +2 -2
  12. package/lib/index.d.ts +1 -1
  13. package/lib/index.js +1 -1
  14. package/lib/integrations/index.d.ts +3 -4
  15. package/lib/integrations/index.js +3 -4
  16. package/lib/native/DatalyrNativeBridge.d.ts +6 -22
  17. package/lib/native/DatalyrNativeBridge.js +6 -147
  18. package/lib/native/index.d.ts +1 -1
  19. package/lib/native/index.js +1 -1
  20. package/lib/types.d.ts +1 -19
  21. package/package.json +3 -5
  22. package/src/datalyr-sdk-expo.ts +6 -141
  23. package/src/datalyr-sdk.ts +8 -173
  24. package/src/http-client.ts +2 -2
  25. package/src/index.ts +1 -1
  26. package/src/integrations/index.ts +3 -4
  27. package/src/native/DatalyrNativeBridge.ts +6 -241
  28. package/src/native/index.ts +0 -2
  29. package/src/types.ts +2 -25
  30. package/src/utils-expo.ts +2 -2
  31. package/ios/DatalyrObjCExceptionCatcher.h +0 -14
  32. package/ios/DatalyrObjCExceptionCatcher.m +0 -30
  33. package/lib/integrations/meta-integration.d.ts +0 -77
  34. package/lib/integrations/meta-integration.js +0 -219
  35. package/lib/integrations/tiktok-integration.d.ts +0 -83
  36. package/lib/integrations/tiktok-integration.js +0 -360
  37. package/src/integrations/meta-integration.ts +0 -239
  38. package/src/integrations/tiktok-integration.ts +0 -363
@@ -1,360 +0,0 @@
1
- /**
2
- * TikTok Business SDK Integration
3
- * Uses bundled native iOS SDK for event forwarding and user identification
4
- */
5
- import { Platform } from 'react-native';
6
- import { TikTokNativeBridge, isNativeModuleAvailable } from '../native/DatalyrNativeBridge';
7
- /**
8
- * TikTok standard event names (current as of 2025)
9
- * Note: CompletePayment and SubmitForm are legacy, use Purchase and Lead instead
10
- */
11
- const TikTokEvents = {
12
- // Commerce events
13
- PURCHASE: 'Purchase',
14
- ADD_TO_CART: 'AddToCart',
15
- ADD_TO_WISHLIST: 'AddToWishlist',
16
- INITIATE_CHECKOUT: 'InitiateCheckout',
17
- ADD_PAYMENT_INFO: 'AddPaymentInfo',
18
- VIEW_CONTENT: 'ViewContent',
19
- SEARCH: 'Search',
20
- // User events
21
- COMPLETE_REGISTRATION: 'CompleteRegistration',
22
- SUBSCRIBE: 'Subscribe',
23
- START_TRIAL: 'StartTrial',
24
- LEAD: 'Lead',
25
- CONTACT: 'Contact',
26
- // App events
27
- DOWNLOAD: 'Download',
28
- SCHEDULE: 'Schedule',
29
- SUBMIT_APPLICATION: 'SubmitApplication',
30
- };
31
- /**
32
- * TikTok Integration class for handling TikTok Business SDK operations
33
- * Uses native iOS SDK bundled via CocoaPods (no additional npm packages required)
34
- */
35
- export class TikTokIntegration {
36
- constructor() {
37
- this.config = null;
38
- this.initialized = false;
39
- this.available = false;
40
- this.debug = false;
41
- }
42
- /**
43
- * Initialize TikTok SDK with configuration
44
- * Supported on both iOS and Android via native modules
45
- */
46
- async initialize(config, debug = false) {
47
- this.debug = debug;
48
- this.config = config;
49
- // Only available on iOS and Android via native modules
50
- if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
51
- this.log('TikTok SDK only available on iOS and Android');
52
- return;
53
- }
54
- this.available = isNativeModuleAvailable();
55
- if (!this.available) {
56
- this.log('TikTok native module not available');
57
- return;
58
- }
59
- try {
60
- const success = await TikTokNativeBridge.initialize(config.appId, config.tiktokAppId, config.accessToken, debug);
61
- if (success) {
62
- this.initialized = true;
63
- this.log(`TikTok SDK initialized with App ID: ${config.tiktokAppId}`);
64
- }
65
- else {
66
- console.warn('[Datalyr/TikTok] TikTok SDK not initialized (accessToken may be missing). Events will still be sent server-side via Datalyr postbacks.');
67
- }
68
- }
69
- catch (error) {
70
- console.warn('[Datalyr/TikTok] TikTok SDK init failed. Events will still be sent server-side via Datalyr postbacks.', error);
71
- }
72
- }
73
- /**
74
- * Update tracking authorization status (call after ATT prompt)
75
- */
76
- async updateTrackingAuthorization(enabled) {
77
- if (!this.available || !this.initialized)
78
- return;
79
- try {
80
- // TikTok SDK auto-handles ATT, but we track the event
81
- if (enabled) {
82
- await this.trackEvent('ATTAuthorized');
83
- }
84
- await TikTokNativeBridge.updateTrackingAuthorization(enabled);
85
- this.log(`TikTok ATT status: ${enabled ? 'authorized' : 'not authorized'}`);
86
- }
87
- catch (error) {
88
- this.logError('Failed to update TikTok tracking authorization:', error);
89
- }
90
- }
91
- /**
92
- * Log purchase event to TikTok (uses Purchase - TikTok's current standard event)
93
- */
94
- async logPurchase(value, currency, contentId, contentType, parameters) {
95
- var _a;
96
- if (!this.available || !this.initialized)
97
- return;
98
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
99
- return;
100
- try {
101
- const properties = {
102
- value,
103
- currency,
104
- ...parameters,
105
- };
106
- if (contentId)
107
- properties.content_id = contentId;
108
- if (contentType)
109
- properties.content_type = contentType;
110
- await TikTokNativeBridge.trackEvent(TikTokEvents.PURCHASE, undefined, properties);
111
- this.log(`TikTok Purchase event logged: ${value} ${currency}`);
112
- }
113
- catch (error) {
114
- this.logError('Failed to log TikTok purchase:', error);
115
- }
116
- }
117
- /**
118
- * Log subscription event to TikTok
119
- */
120
- async logSubscription(value, currency, plan) {
121
- var _a;
122
- if (!this.available || !this.initialized)
123
- return;
124
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
125
- return;
126
- try {
127
- const properties = {
128
- value,
129
- currency,
130
- };
131
- if (plan) {
132
- properties.content_id = plan;
133
- properties.content_type = 'subscription';
134
- }
135
- await TikTokNativeBridge.trackEvent(TikTokEvents.SUBSCRIBE, undefined, properties);
136
- this.log(`TikTok subscription event logged: ${value} ${currency}`);
137
- }
138
- catch (error) {
139
- this.logError('Failed to log TikTok subscription:', error);
140
- }
141
- }
142
- /**
143
- * Log add to cart event
144
- */
145
- async logAddToCart(value, currency, contentId, contentType) {
146
- var _a;
147
- if (!this.available || !this.initialized)
148
- return;
149
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
150
- return;
151
- try {
152
- const properties = {
153
- value,
154
- currency,
155
- };
156
- if (contentId)
157
- properties.content_id = contentId;
158
- if (contentType)
159
- properties.content_type = contentType;
160
- await TikTokNativeBridge.trackEvent(TikTokEvents.ADD_TO_CART, undefined, properties);
161
- this.log('TikTok add to cart event logged');
162
- }
163
- catch (error) {
164
- this.logError('Failed to log TikTok add to cart:', error);
165
- }
166
- }
167
- /**
168
- * Log view content event
169
- */
170
- async logViewContent(contentId, contentName, contentType) {
171
- var _a;
172
- if (!this.available || !this.initialized)
173
- return;
174
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
175
- return;
176
- try {
177
- const properties = {};
178
- if (contentId)
179
- properties.content_id = contentId;
180
- if (contentName)
181
- properties.content_name = contentName;
182
- if (contentType)
183
- properties.content_type = contentType;
184
- await TikTokNativeBridge.trackEvent(TikTokEvents.VIEW_CONTENT, undefined, properties);
185
- this.log('TikTok view content event logged');
186
- }
187
- catch (error) {
188
- this.logError('Failed to log TikTok view content:', error);
189
- }
190
- }
191
- /**
192
- * Log initiate checkout event
193
- */
194
- async logInitiateCheckout(value, currency, numItems) {
195
- var _a;
196
- if (!this.available || !this.initialized)
197
- return;
198
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
199
- return;
200
- try {
201
- const properties = {
202
- value,
203
- currency,
204
- };
205
- if (numItems)
206
- properties.quantity = numItems;
207
- await TikTokNativeBridge.trackEvent(TikTokEvents.INITIATE_CHECKOUT, undefined, properties);
208
- this.log('TikTok initiate checkout event logged');
209
- }
210
- catch (error) {
211
- this.logError('Failed to log TikTok initiate checkout:', error);
212
- }
213
- }
214
- /**
215
- * Log complete registration event
216
- */
217
- async logCompleteRegistration(method) {
218
- var _a;
219
- if (!this.available || !this.initialized)
220
- return;
221
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
222
- return;
223
- try {
224
- const properties = {};
225
- if (method)
226
- properties.registration_method = method;
227
- await TikTokNativeBridge.trackEvent(TikTokEvents.COMPLETE_REGISTRATION, undefined, properties);
228
- this.log('TikTok complete registration event logged');
229
- }
230
- catch (error) {
231
- this.logError('Failed to log TikTok complete registration:', error);
232
- }
233
- }
234
- /**
235
- * Log search event
236
- */
237
- async logSearch(query) {
238
- var _a;
239
- if (!this.available || !this.initialized)
240
- return;
241
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
242
- return;
243
- try {
244
- await TikTokNativeBridge.trackEvent(TikTokEvents.SEARCH, undefined, { query });
245
- this.log('TikTok search event logged');
246
- }
247
- catch (error) {
248
- this.logError('Failed to log TikTok search:', error);
249
- }
250
- }
251
- /**
252
- * Log lead event (uses Lead - current standard, SubmitForm is legacy)
253
- */
254
- async logLead(value, currency) {
255
- var _a;
256
- if (!this.available || !this.initialized)
257
- return;
258
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
259
- return;
260
- try {
261
- const properties = {};
262
- if (value !== undefined)
263
- properties.value = value;
264
- if (currency)
265
- properties.currency = currency;
266
- await TikTokNativeBridge.trackEvent(TikTokEvents.LEAD, undefined, properties);
267
- this.log('TikTok lead event logged');
268
- }
269
- catch (error) {
270
- this.logError('Failed to log TikTok lead:', error);
271
- }
272
- }
273
- /**
274
- * Log add payment info event
275
- */
276
- async logAddPaymentInfo(success) {
277
- var _a;
278
- if (!this.available || !this.initialized)
279
- return;
280
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
281
- return;
282
- try {
283
- await TikTokNativeBridge.trackEvent(TikTokEvents.ADD_PAYMENT_INFO, undefined, { success });
284
- this.log('TikTok add payment info event logged');
285
- }
286
- catch (error) {
287
- this.logError('Failed to log TikTok add payment info:', error);
288
- }
289
- }
290
- /**
291
- * Log custom event to TikTok
292
- */
293
- async trackEvent(eventName, properties) {
294
- var _a;
295
- if (!this.available || !this.initialized)
296
- return;
297
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
298
- return;
299
- try {
300
- await TikTokNativeBridge.trackEvent(eventName, undefined, properties || {});
301
- this.log(`TikTok event logged: ${eventName}`);
302
- }
303
- catch (error) {
304
- this.logError('Failed to log TikTok event:', error);
305
- }
306
- }
307
- /**
308
- * Identify user for improved attribution matching
309
- */
310
- async identify(email, phone, externalId) {
311
- if (!this.available || !this.initialized)
312
- return;
313
- // Only call identify if we have at least one value
314
- if (!email && !phone && !externalId)
315
- return;
316
- try {
317
- await TikTokNativeBridge.identify(externalId, email, phone);
318
- this.log('TikTok user identification set');
319
- }
320
- catch (error) {
321
- this.logError('Failed to identify TikTok user:', error);
322
- }
323
- }
324
- /**
325
- * Clear user session (call on logout)
326
- */
327
- async logout() {
328
- if (!this.available || !this.initialized)
329
- return;
330
- try {
331
- await TikTokNativeBridge.logout();
332
- this.log('TikTok user logged out');
333
- }
334
- catch (error) {
335
- this.logError('Failed to logout TikTok user:', error);
336
- }
337
- }
338
- /**
339
- * Check if TikTok SDK is available and initialized
340
- */
341
- isAvailable() {
342
- return this.available && this.initialized;
343
- }
344
- /**
345
- * Check if TikTok SDK native module is installed
346
- */
347
- isInstalled() {
348
- return this.available;
349
- }
350
- log(message, data) {
351
- if (this.debug) {
352
- console.log(`[Datalyr/TikTok] ${message}`, data || '');
353
- }
354
- }
355
- logError(message, error) {
356
- console.error(`[Datalyr/TikTok] ${message}`, error);
357
- }
358
- }
359
- // Export singleton instance
360
- export const tiktokIntegration = new TikTokIntegration();
@@ -1,239 +0,0 @@
1
- /**
2
- * Meta (Facebook) SDK Integration
3
- * Uses bundled native iOS SDK for deferred deep linking, event forwarding, and Advanced Matching
4
- */
5
-
6
- import { Platform } from 'react-native';
7
- import { MetaConfig, DeferredDeepLinkResult } from '../types';
8
- import { MetaNativeBridge, isNativeModuleAvailable } from '../native/DatalyrNativeBridge';
9
-
10
- /**
11
- * Meta Integration class for handling Facebook SDK operations
12
- * Uses native iOS SDK bundled via CocoaPods (no additional npm packages required)
13
- */
14
- export class MetaIntegration {
15
- private config: MetaConfig | null = null;
16
- private initialized: boolean = false;
17
- private available: boolean = false;
18
- private debug: boolean = false;
19
- private deferredDeepLinkData: DeferredDeepLinkResult | null = null;
20
-
21
- /**
22
- * Initialize Meta SDK with configuration
23
- * Supported on both iOS and Android via native modules
24
- */
25
- async initialize(config: MetaConfig, debug: boolean = false): Promise<void> {
26
- this.debug = debug;
27
- this.config = config;
28
-
29
- // Only available on iOS and Android via native modules
30
- if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
31
- this.log('Meta SDK only available on iOS and Android');
32
- return;
33
- }
34
-
35
- this.available = isNativeModuleAvailable();
36
-
37
- if (!this.available) {
38
- this.log('Meta native module not available');
39
- return;
40
- }
41
-
42
- try {
43
- const success = await MetaNativeBridge.initialize(
44
- config.appId,
45
- config.clientToken,
46
- config.advertiserTrackingEnabled ?? false
47
- );
48
-
49
- if (success) {
50
- this.initialized = true;
51
- this.log(`Meta SDK initialized with App ID: ${config.appId}`);
52
- }
53
- } catch (error) {
54
- this.logError('Failed to initialize Meta SDK:', error);
55
- }
56
- }
57
-
58
- /**
59
- * Update tracking authorization status (call after ATT prompt)
60
- */
61
- async updateTrackingAuthorization(enabled: boolean): Promise<void> {
62
- if (!this.available || !this.initialized) return;
63
-
64
- try {
65
- await MetaNativeBridge.updateTrackingAuthorization(enabled);
66
- this.log(`Meta ATT status updated: ${enabled ? 'authorized' : 'not authorized'}`);
67
- } catch (error) {
68
- this.logError('Failed to update Meta tracking authorization:', error);
69
- }
70
- }
71
-
72
- /**
73
- * Fetch deferred deep link from Meta SDK
74
- * This captures fbclid for installs that went through App Store
75
- */
76
- async fetchDeferredDeepLink(): Promise<DeferredDeepLinkResult | null> {
77
- if (!this.available || !this.initialized) {
78
- return null;
79
- }
80
-
81
- if (this.config?.enableDeferredDeepLink === false) {
82
- return null;
83
- }
84
-
85
- try {
86
- const url = await MetaNativeBridge.fetchDeferredAppLink();
87
-
88
- if (!url) {
89
- this.log('No deferred deep link available from Meta');
90
- return null;
91
- }
92
-
93
- // Parse the URL for attribution parameters
94
- const result = this.parseDeepLinkUrl(url);
95
- this.deferredDeepLinkData = result;
96
-
97
- this.log(`Meta deferred deep link fetched: ${url}`);
98
- return result;
99
- } catch (error) {
100
- // This is expected to fail in some scenarios - log but don't treat as error
101
- this.log('Could not fetch Meta deferred deep link (may not be available)');
102
- return null;
103
- }
104
- }
105
-
106
- /**
107
- * Parse deep link URL to extract attribution parameters
108
- */
109
- private parseDeepLinkUrl(urlString: string): DeferredDeepLinkResult {
110
- const result: DeferredDeepLinkResult = {
111
- url: urlString,
112
- source: 'meta',
113
- };
114
-
115
- try {
116
- const url = new URL(urlString);
117
- const params = url.searchParams;
118
-
119
- // Extract known parameters
120
- if (params.get('fbclid')) result.fbclid = params.get('fbclid')!;
121
- if (params.get('utm_source')) result.utmSource = params.get('utm_source')!;
122
- if (params.get('utm_medium')) result.utmMedium = params.get('utm_medium')!;
123
- if (params.get('utm_campaign')) result.utmCampaign = params.get('utm_campaign')!;
124
- if (params.get('utm_content')) result.utmContent = params.get('utm_content')!;
125
- if (params.get('utm_term')) result.utmTerm = params.get('utm_term')!;
126
- if (params.get('campaign_id')) result.campaignId = params.get('campaign_id')!;
127
- if (params.get('adset_id')) result.adsetId = params.get('adset_id')!;
128
- if (params.get('ad_id')) result.adId = params.get('ad_id')!;
129
- } catch (error) {
130
- this.logError('Failed to parse deep link URL:', error);
131
- }
132
-
133
- return result;
134
- }
135
-
136
- /**
137
- * Log purchase event to Meta
138
- */
139
- async logPurchase(value: number, currency: string, parameters?: Record<string, any>): Promise<void> {
140
- if (!this.available || !this.initialized) return;
141
- if (this.config?.enableAppEvents === false) return;
142
-
143
- try {
144
- await MetaNativeBridge.logPurchase(value, currency, parameters);
145
- this.log(`Meta purchase event logged: ${value} ${currency}`);
146
- } catch (error) {
147
- this.logError('Failed to log Meta purchase:', error);
148
- }
149
- }
150
-
151
- /**
152
- * Log custom event to Meta
153
- */
154
- async logEvent(eventName: string, valueToSum?: number, parameters?: Record<string, any>): Promise<void> {
155
- if (!this.available || !this.initialized) return;
156
- if (this.config?.enableAppEvents === false) return;
157
-
158
- try {
159
- await MetaNativeBridge.logEvent(eventName, valueToSum, parameters);
160
- this.log(`Meta event logged: ${eventName}`);
161
- } catch (error) {
162
- this.logError('Failed to log Meta event:', error);
163
- }
164
- }
165
-
166
- /**
167
- * Set user data for Advanced Matching (improves conversion attribution)
168
- * Note: Meta's Advanced Matching uses these specific fields - externalId is not supported
169
- */
170
- async setUserData(userData: {
171
- email?: string;
172
- firstName?: string;
173
- lastName?: string;
174
- phone?: string;
175
- dateOfBirth?: string;
176
- gender?: string;
177
- city?: string;
178
- state?: string;
179
- zip?: string;
180
- country?: string;
181
- }): Promise<void> {
182
- if (!this.available || !this.initialized) return;
183
-
184
- try {
185
- await MetaNativeBridge.setUserData(userData);
186
- this.log('Meta user data set for Advanced Matching');
187
- } catch (error) {
188
- this.logError('Failed to set Meta user data:', error);
189
- }
190
- }
191
-
192
- /**
193
- * Clear user data (call on logout)
194
- */
195
- async clearUserData(): Promise<void> {
196
- if (!this.available || !this.initialized) return;
197
-
198
- try {
199
- await MetaNativeBridge.clearUserData();
200
- this.log('Meta user data cleared');
201
- } catch (error) {
202
- this.logError('Failed to clear Meta user data:', error);
203
- }
204
- }
205
-
206
- /**
207
- * Get cached deferred deep link data
208
- */
209
- getDeferredDeepLinkData(): DeferredDeepLinkResult | null {
210
- return this.deferredDeepLinkData;
211
- }
212
-
213
- /**
214
- * Check if Meta SDK is available and initialized
215
- */
216
- isAvailable(): boolean {
217
- return this.available && this.initialized;
218
- }
219
-
220
- /**
221
- * Check if Meta SDK native module is installed
222
- */
223
- isInstalled(): boolean {
224
- return this.available;
225
- }
226
-
227
- private log(message: string, data?: any): void {
228
- if (this.debug) {
229
- console.log(`[Datalyr/Meta] ${message}`, data || '');
230
- }
231
- }
232
-
233
- private logError(message: string, error: any): void {
234
- console.error(`[Datalyr/Meta] ${message}`, error);
235
- }
236
- }
237
-
238
- // Export singleton instance
239
- export const metaIntegration = new MetaIntegration();