@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.
- package/CHANGELOG.md +31 -140
- package/LICENSE +21 -0
- package/README.md +434 -217
- package/datalyr-react-native.podspec +31 -0
- package/ios/DatalyrNative.m +74 -0
- package/ios/DatalyrNative.swift +332 -0
- package/ios/DatalyrSKAdNetwork.m +26 -0
- package/lib/datalyr-sdk.d.ts +73 -3
- package/lib/datalyr-sdk.js +353 -3
- package/lib/index.d.ts +2 -0
- package/lib/index.js +4 -2
- package/lib/integrations/apple-search-ads-integration.d.ts +43 -0
- package/lib/integrations/apple-search-ads-integration.js +106 -0
- package/lib/integrations/index.d.ts +7 -0
- package/lib/integrations/index.js +7 -0
- package/lib/integrations/meta-integration.d.ts +76 -0
- package/lib/integrations/meta-integration.js +218 -0
- package/lib/integrations/tiktok-integration.d.ts +82 -0
- package/lib/integrations/tiktok-integration.js +356 -0
- package/lib/native/DatalyrNativeBridge.d.ts +57 -0
- package/lib/native/DatalyrNativeBridge.js +187 -0
- package/lib/native/index.d.ts +5 -0
- package/lib/native/index.js +5 -0
- package/lib/types.d.ts +29 -0
- package/package.json +11 -5
- package/src/datalyr-sdk-expo.ts +997 -0
- package/src/datalyr-sdk.ts +455 -19
- package/src/expo.ts +42 -18
- package/src/index.ts +8 -2
- package/src/integrations/apple-search-ads-integration.ts +119 -0
- package/src/integrations/index.ts +8 -0
- package/src/integrations/meta-integration.ts +238 -0
- package/src/integrations/tiktok-integration.ts +360 -0
- package/src/native/DatalyrNativeBridge.ts +313 -0
- package/src/native/index.ts +11 -0
- package/src/types.ts +39 -0
- package/src/utils-expo.ts +25 -3
- package/src/utils-interface.ts +38 -0
- package/EXPO_INSTALL.md +0 -297
- package/INSTALL.md +0 -402
- package/examples/attribution-example.tsx +0 -377
- package/examples/auto-events-example.tsx +0 -403
- package/examples/example.tsx +0 -250
- package/examples/skadnetwork-example.tsx +0 -380
- package/examples/test-implementation.tsx +0 -163
|
@@ -0,0 +1,356 @@
|
|
|
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
|
+
*/
|
|
45
|
+
async initialize(config, debug = false) {
|
|
46
|
+
this.debug = debug;
|
|
47
|
+
this.config = config;
|
|
48
|
+
// Only available on iOS via native module
|
|
49
|
+
if (Platform.OS !== 'ios') {
|
|
50
|
+
this.log('TikTok SDK only available on iOS');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.available = isNativeModuleAvailable();
|
|
54
|
+
if (!this.available) {
|
|
55
|
+
this.log('TikTok native module not available');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const success = await TikTokNativeBridge.initialize(config.appId, config.tiktokAppId, config.accessToken, debug);
|
|
60
|
+
if (success) {
|
|
61
|
+
this.initialized = true;
|
|
62
|
+
this.log(`TikTok SDK initialized with App ID: ${config.tiktokAppId}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
this.logError('Failed to initialize TikTok SDK:', error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Update tracking authorization status (call after ATT prompt)
|
|
71
|
+
*/
|
|
72
|
+
async updateTrackingAuthorization(enabled) {
|
|
73
|
+
if (!this.available || !this.initialized)
|
|
74
|
+
return;
|
|
75
|
+
try {
|
|
76
|
+
// TikTok SDK auto-handles ATT, but we track the event
|
|
77
|
+
if (enabled) {
|
|
78
|
+
await this.trackEvent('ATTAuthorized');
|
|
79
|
+
}
|
|
80
|
+
await TikTokNativeBridge.updateTrackingAuthorization(enabled);
|
|
81
|
+
this.log(`TikTok ATT status: ${enabled ? 'authorized' : 'not authorized'}`);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
this.logError('Failed to update TikTok tracking authorization:', error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Log purchase event to TikTok (uses Purchase - TikTok's current standard event)
|
|
89
|
+
*/
|
|
90
|
+
async logPurchase(value, currency, contentId, contentType, parameters) {
|
|
91
|
+
var _a;
|
|
92
|
+
if (!this.available || !this.initialized)
|
|
93
|
+
return;
|
|
94
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
|
|
95
|
+
return;
|
|
96
|
+
try {
|
|
97
|
+
const properties = {
|
|
98
|
+
value,
|
|
99
|
+
currency,
|
|
100
|
+
...parameters,
|
|
101
|
+
};
|
|
102
|
+
if (contentId)
|
|
103
|
+
properties.content_id = contentId;
|
|
104
|
+
if (contentType)
|
|
105
|
+
properties.content_type = contentType;
|
|
106
|
+
await TikTokNativeBridge.trackEvent(TikTokEvents.PURCHASE, undefined, properties);
|
|
107
|
+
this.log(`TikTok Purchase event logged: ${value} ${currency}`);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
this.logError('Failed to log TikTok purchase:', error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Log subscription event to TikTok
|
|
115
|
+
*/
|
|
116
|
+
async logSubscription(value, currency, plan) {
|
|
117
|
+
var _a;
|
|
118
|
+
if (!this.available || !this.initialized)
|
|
119
|
+
return;
|
|
120
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
|
|
121
|
+
return;
|
|
122
|
+
try {
|
|
123
|
+
const properties = {
|
|
124
|
+
value,
|
|
125
|
+
currency,
|
|
126
|
+
};
|
|
127
|
+
if (plan) {
|
|
128
|
+
properties.content_id = plan;
|
|
129
|
+
properties.content_type = 'subscription';
|
|
130
|
+
}
|
|
131
|
+
await TikTokNativeBridge.trackEvent(TikTokEvents.SUBSCRIBE, undefined, properties);
|
|
132
|
+
this.log(`TikTok subscription event logged: ${value} ${currency}`);
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
this.logError('Failed to log TikTok subscription:', error);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Log add to cart event
|
|
140
|
+
*/
|
|
141
|
+
async logAddToCart(value, currency, contentId, contentType) {
|
|
142
|
+
var _a;
|
|
143
|
+
if (!this.available || !this.initialized)
|
|
144
|
+
return;
|
|
145
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
|
|
146
|
+
return;
|
|
147
|
+
try {
|
|
148
|
+
const properties = {
|
|
149
|
+
value,
|
|
150
|
+
currency,
|
|
151
|
+
};
|
|
152
|
+
if (contentId)
|
|
153
|
+
properties.content_id = contentId;
|
|
154
|
+
if (contentType)
|
|
155
|
+
properties.content_type = contentType;
|
|
156
|
+
await TikTokNativeBridge.trackEvent(TikTokEvents.ADD_TO_CART, undefined, properties);
|
|
157
|
+
this.log('TikTok add to cart event logged');
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
this.logError('Failed to log TikTok add to cart:', error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Log view content event
|
|
165
|
+
*/
|
|
166
|
+
async logViewContent(contentId, contentName, contentType) {
|
|
167
|
+
var _a;
|
|
168
|
+
if (!this.available || !this.initialized)
|
|
169
|
+
return;
|
|
170
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
|
|
171
|
+
return;
|
|
172
|
+
try {
|
|
173
|
+
const properties = {};
|
|
174
|
+
if (contentId)
|
|
175
|
+
properties.content_id = contentId;
|
|
176
|
+
if (contentName)
|
|
177
|
+
properties.content_name = contentName;
|
|
178
|
+
if (contentType)
|
|
179
|
+
properties.content_type = contentType;
|
|
180
|
+
await TikTokNativeBridge.trackEvent(TikTokEvents.VIEW_CONTENT, undefined, properties);
|
|
181
|
+
this.log('TikTok view content event logged');
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
this.logError('Failed to log TikTok view content:', error);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Log initiate checkout event
|
|
189
|
+
*/
|
|
190
|
+
async logInitiateCheckout(value, currency, numItems) {
|
|
191
|
+
var _a;
|
|
192
|
+
if (!this.available || !this.initialized)
|
|
193
|
+
return;
|
|
194
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
|
|
195
|
+
return;
|
|
196
|
+
try {
|
|
197
|
+
const properties = {
|
|
198
|
+
value,
|
|
199
|
+
currency,
|
|
200
|
+
};
|
|
201
|
+
if (numItems)
|
|
202
|
+
properties.quantity = numItems;
|
|
203
|
+
await TikTokNativeBridge.trackEvent(TikTokEvents.INITIATE_CHECKOUT, undefined, properties);
|
|
204
|
+
this.log('TikTok initiate checkout event logged');
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
this.logError('Failed to log TikTok initiate checkout:', error);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Log complete registration event
|
|
212
|
+
*/
|
|
213
|
+
async logCompleteRegistration(method) {
|
|
214
|
+
var _a;
|
|
215
|
+
if (!this.available || !this.initialized)
|
|
216
|
+
return;
|
|
217
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
|
|
218
|
+
return;
|
|
219
|
+
try {
|
|
220
|
+
const properties = {};
|
|
221
|
+
if (method)
|
|
222
|
+
properties.registration_method = method;
|
|
223
|
+
await TikTokNativeBridge.trackEvent(TikTokEvents.COMPLETE_REGISTRATION, undefined, properties);
|
|
224
|
+
this.log('TikTok complete registration event logged');
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
this.logError('Failed to log TikTok complete registration:', error);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Log search event
|
|
232
|
+
*/
|
|
233
|
+
async logSearch(query) {
|
|
234
|
+
var _a;
|
|
235
|
+
if (!this.available || !this.initialized)
|
|
236
|
+
return;
|
|
237
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
|
|
238
|
+
return;
|
|
239
|
+
try {
|
|
240
|
+
await TikTokNativeBridge.trackEvent(TikTokEvents.SEARCH, undefined, { query });
|
|
241
|
+
this.log('TikTok search event logged');
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
this.logError('Failed to log TikTok search:', error);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Log lead event (uses Lead - current standard, SubmitForm is legacy)
|
|
249
|
+
*/
|
|
250
|
+
async logLead(value, currency) {
|
|
251
|
+
var _a;
|
|
252
|
+
if (!this.available || !this.initialized)
|
|
253
|
+
return;
|
|
254
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
|
|
255
|
+
return;
|
|
256
|
+
try {
|
|
257
|
+
const properties = {};
|
|
258
|
+
if (value !== undefined)
|
|
259
|
+
properties.value = value;
|
|
260
|
+
if (currency)
|
|
261
|
+
properties.currency = currency;
|
|
262
|
+
await TikTokNativeBridge.trackEvent(TikTokEvents.LEAD, undefined, properties);
|
|
263
|
+
this.log('TikTok lead event logged');
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
this.logError('Failed to log TikTok lead:', error);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Log add payment info event
|
|
271
|
+
*/
|
|
272
|
+
async logAddPaymentInfo(success) {
|
|
273
|
+
var _a;
|
|
274
|
+
if (!this.available || !this.initialized)
|
|
275
|
+
return;
|
|
276
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
|
|
277
|
+
return;
|
|
278
|
+
try {
|
|
279
|
+
await TikTokNativeBridge.trackEvent(TikTokEvents.ADD_PAYMENT_INFO, undefined, { success });
|
|
280
|
+
this.log('TikTok add payment info event logged');
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
this.logError('Failed to log TikTok add payment info:', error);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Log custom event to TikTok
|
|
288
|
+
*/
|
|
289
|
+
async trackEvent(eventName, properties) {
|
|
290
|
+
var _a;
|
|
291
|
+
if (!this.available || !this.initialized)
|
|
292
|
+
return;
|
|
293
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
|
|
294
|
+
return;
|
|
295
|
+
try {
|
|
296
|
+
await TikTokNativeBridge.trackEvent(eventName, undefined, properties || {});
|
|
297
|
+
this.log(`TikTok event logged: ${eventName}`);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
this.logError('Failed to log TikTok event:', error);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Identify user for improved attribution matching
|
|
305
|
+
*/
|
|
306
|
+
async identify(email, phone, externalId) {
|
|
307
|
+
if (!this.available || !this.initialized)
|
|
308
|
+
return;
|
|
309
|
+
// Only call identify if we have at least one value
|
|
310
|
+
if (!email && !phone && !externalId)
|
|
311
|
+
return;
|
|
312
|
+
try {
|
|
313
|
+
await TikTokNativeBridge.identify(externalId, email, phone);
|
|
314
|
+
this.log('TikTok user identification set');
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
this.logError('Failed to identify TikTok user:', error);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Clear user session (call on logout)
|
|
322
|
+
*/
|
|
323
|
+
async logout() {
|
|
324
|
+
if (!this.available || !this.initialized)
|
|
325
|
+
return;
|
|
326
|
+
try {
|
|
327
|
+
await TikTokNativeBridge.logout();
|
|
328
|
+
this.log('TikTok user logged out');
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
this.logError('Failed to logout TikTok user:', error);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Check if TikTok SDK is available and initialized
|
|
336
|
+
*/
|
|
337
|
+
isAvailable() {
|
|
338
|
+
return this.available && this.initialized;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Check if TikTok SDK native module is installed
|
|
342
|
+
*/
|
|
343
|
+
isInstalled() {
|
|
344
|
+
return this.available;
|
|
345
|
+
}
|
|
346
|
+
log(message, data) {
|
|
347
|
+
if (this.debug) {
|
|
348
|
+
console.log(`[Datalyr/TikTok] ${message}`, data || '');
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
logError(message, error) {
|
|
352
|
+
console.error(`[Datalyr/TikTok] ${message}`, error);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// Export singleton instance
|
|
356
|
+
export const tiktokIntegration = new TikTokIntegration();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native Bridge for Meta, TikTok, and Apple Search Ads
|
|
3
|
+
* Uses bundled native modules instead of separate npm packages
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Apple Search Ads attribution data returned from AdServices API
|
|
7
|
+
*/
|
|
8
|
+
export interface AppleSearchAdsAttribution {
|
|
9
|
+
attribution: boolean;
|
|
10
|
+
orgId?: number;
|
|
11
|
+
orgName?: string;
|
|
12
|
+
campaignId?: number;
|
|
13
|
+
campaignName?: string;
|
|
14
|
+
adGroupId?: number;
|
|
15
|
+
adGroupName?: string;
|
|
16
|
+
keywordId?: number;
|
|
17
|
+
keyword?: string;
|
|
18
|
+
clickDate?: string;
|
|
19
|
+
conversionType?: string;
|
|
20
|
+
countryOrRegion?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if native module is available
|
|
24
|
+
*/
|
|
25
|
+
export declare const isNativeModuleAvailable: () => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Get SDK availability status
|
|
28
|
+
*/
|
|
29
|
+
export declare const getSDKAvailability: () => Promise<{
|
|
30
|
+
meta: boolean;
|
|
31
|
+
tiktok: boolean;
|
|
32
|
+
appleSearchAds: boolean;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const MetaNativeBridge: {
|
|
35
|
+
initialize(appId: string, clientToken?: string, advertiserTrackingEnabled?: boolean): Promise<boolean>;
|
|
36
|
+
fetchDeferredAppLink(): Promise<string | null>;
|
|
37
|
+
logEvent(eventName: string, valueToSum?: number, parameters?: Record<string, any>): Promise<boolean>;
|
|
38
|
+
logPurchase(amount: number, currency: string, parameters?: Record<string, any>): Promise<boolean>;
|
|
39
|
+
setUserData(userData: Record<string, string | undefined>): Promise<boolean>;
|
|
40
|
+
clearUserData(): Promise<boolean>;
|
|
41
|
+
updateTrackingAuthorization(enabled: boolean): Promise<boolean>;
|
|
42
|
+
};
|
|
43
|
+
export declare const TikTokNativeBridge: {
|
|
44
|
+
initialize(appId: string, tiktokAppId: string, accessToken?: string, debug?: boolean): Promise<boolean>;
|
|
45
|
+
trackEvent(eventName: string, eventId?: string, properties?: Record<string, any>): Promise<boolean>;
|
|
46
|
+
identify(externalId?: string, email?: string, phone?: string): Promise<boolean>;
|
|
47
|
+
logout(): Promise<boolean>;
|
|
48
|
+
updateTrackingAuthorization(enabled: boolean): Promise<boolean>;
|
|
49
|
+
};
|
|
50
|
+
export declare const AppleSearchAdsNativeBridge: {
|
|
51
|
+
/**
|
|
52
|
+
* Get Apple Search Ads attribution data
|
|
53
|
+
* Uses AdServices framework (iOS 14.3+)
|
|
54
|
+
* Returns null if user didn't come from Apple Search Ads or on older iOS
|
|
55
|
+
*/
|
|
56
|
+
getAttribution(): Promise<AppleSearchAdsAttribution | null>;
|
|
57
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native Bridge for Meta, TikTok, and Apple Search Ads
|
|
3
|
+
* Uses bundled native modules instead of separate npm packages
|
|
4
|
+
*/
|
|
5
|
+
import { NativeModules, Platform } from 'react-native';
|
|
6
|
+
// Native module is only available on iOS
|
|
7
|
+
const DatalyrNative = Platform.OS === 'ios' ? NativeModules.DatalyrNative : null;
|
|
8
|
+
/**
|
|
9
|
+
* Check if native module is available
|
|
10
|
+
*/
|
|
11
|
+
export const isNativeModuleAvailable = () => {
|
|
12
|
+
return DatalyrNative !== null;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Get SDK availability status
|
|
16
|
+
*/
|
|
17
|
+
export const getSDKAvailability = async () => {
|
|
18
|
+
if (!DatalyrNative) {
|
|
19
|
+
return { meta: false, tiktok: false, appleSearchAds: false };
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
return await DatalyrNative.getSDKAvailability();
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return { meta: false, tiktok: false, appleSearchAds: false };
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
// MARK: - Meta SDK Bridge
|
|
29
|
+
export const MetaNativeBridge = {
|
|
30
|
+
async initialize(appId, clientToken, advertiserTrackingEnabled = false) {
|
|
31
|
+
if (!DatalyrNative)
|
|
32
|
+
return false;
|
|
33
|
+
try {
|
|
34
|
+
return await DatalyrNative.initializeMetaSDK(appId, clientToken || null, advertiserTrackingEnabled);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error('[Datalyr/MetaNative] Initialize failed:', error);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
async fetchDeferredAppLink() {
|
|
42
|
+
if (!DatalyrNative)
|
|
43
|
+
return null;
|
|
44
|
+
try {
|
|
45
|
+
return await DatalyrNative.fetchDeferredAppLink();
|
|
46
|
+
}
|
|
47
|
+
catch (_a) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
async logEvent(eventName, valueToSum, parameters) {
|
|
52
|
+
if (!DatalyrNative)
|
|
53
|
+
return false;
|
|
54
|
+
try {
|
|
55
|
+
return await DatalyrNative.logMetaEvent(eventName, valueToSum !== null && valueToSum !== void 0 ? valueToSum : null, parameters || null);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error('[Datalyr/MetaNative] Log event failed:', error);
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
async logPurchase(amount, currency, parameters) {
|
|
63
|
+
if (!DatalyrNative)
|
|
64
|
+
return false;
|
|
65
|
+
try {
|
|
66
|
+
return await DatalyrNative.logMetaPurchase(amount, currency, parameters || null);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.error('[Datalyr/MetaNative] Log purchase failed:', error);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
async setUserData(userData) {
|
|
74
|
+
if (!DatalyrNative)
|
|
75
|
+
return false;
|
|
76
|
+
try {
|
|
77
|
+
return await DatalyrNative.setMetaUserData(userData);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error('[Datalyr/MetaNative] Set user data failed:', error);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
async clearUserData() {
|
|
85
|
+
if (!DatalyrNative)
|
|
86
|
+
return false;
|
|
87
|
+
try {
|
|
88
|
+
return await DatalyrNative.clearMetaUserData();
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error('[Datalyr/MetaNative] Clear user data failed:', error);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async updateTrackingAuthorization(enabled) {
|
|
96
|
+
if (!DatalyrNative)
|
|
97
|
+
return false;
|
|
98
|
+
try {
|
|
99
|
+
return await DatalyrNative.updateMetaTrackingAuthorization(enabled);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.error('[Datalyr/MetaNative] Update tracking failed:', error);
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
// MARK: - TikTok SDK Bridge
|
|
108
|
+
export const TikTokNativeBridge = {
|
|
109
|
+
async initialize(appId, tiktokAppId, accessToken, debug = false) {
|
|
110
|
+
if (!DatalyrNative)
|
|
111
|
+
return false;
|
|
112
|
+
try {
|
|
113
|
+
return await DatalyrNative.initializeTikTokSDK(appId, tiktokAppId, accessToken || null, debug);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error('[Datalyr/TikTokNative] Initialize failed:', error);
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
async trackEvent(eventName, eventId, properties) {
|
|
121
|
+
if (!DatalyrNative)
|
|
122
|
+
return false;
|
|
123
|
+
try {
|
|
124
|
+
return await DatalyrNative.trackTikTokEvent(eventName, eventId || null, properties || null);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error('[Datalyr/TikTokNative] Track event failed:', error);
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
async identify(externalId, email, phone) {
|
|
132
|
+
if (!DatalyrNative)
|
|
133
|
+
return false;
|
|
134
|
+
// Only call if we have at least one value
|
|
135
|
+
if (!externalId && !email && !phone)
|
|
136
|
+
return false;
|
|
137
|
+
try {
|
|
138
|
+
return await DatalyrNative.identifyTikTokUser(externalId || '', '', // externalUserName - not typically available
|
|
139
|
+
phone || '', email || '');
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error('[Datalyr/TikTokNative] Identify failed:', error);
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
async logout() {
|
|
147
|
+
if (!DatalyrNative)
|
|
148
|
+
return false;
|
|
149
|
+
try {
|
|
150
|
+
return await DatalyrNative.logoutTikTok();
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
console.error('[Datalyr/TikTokNative] Logout failed:', error);
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
async updateTrackingAuthorization(enabled) {
|
|
158
|
+
if (!DatalyrNative)
|
|
159
|
+
return false;
|
|
160
|
+
try {
|
|
161
|
+
return await DatalyrNative.updateTikTokTrackingAuthorization(enabled);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error('[Datalyr/TikTokNative] Update tracking failed:', error);
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
// MARK: - Apple Search Ads Bridge
|
|
170
|
+
export const AppleSearchAdsNativeBridge = {
|
|
171
|
+
/**
|
|
172
|
+
* Get Apple Search Ads attribution data
|
|
173
|
+
* Uses AdServices framework (iOS 14.3+)
|
|
174
|
+
* Returns null if user didn't come from Apple Search Ads or on older iOS
|
|
175
|
+
*/
|
|
176
|
+
async getAttribution() {
|
|
177
|
+
if (!DatalyrNative)
|
|
178
|
+
return null;
|
|
179
|
+
try {
|
|
180
|
+
return await DatalyrNative.getAppleSearchAdsAttribution();
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.error('[Datalyr/AppleSearchAds] Get attribution failed:', error);
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
};
|
package/lib/types.d.ts
CHANGED
|
@@ -5,6 +5,33 @@ export interface AutoEventConfig {
|
|
|
5
5
|
trackPerformance?: boolean;
|
|
6
6
|
sessionTimeoutMs?: number;
|
|
7
7
|
}
|
|
8
|
+
export interface MetaConfig {
|
|
9
|
+
appId: string;
|
|
10
|
+
clientToken?: string;
|
|
11
|
+
enableDeferredDeepLink?: boolean;
|
|
12
|
+
enableAppEvents?: boolean;
|
|
13
|
+
advertiserTrackingEnabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface TikTokConfig {
|
|
16
|
+
appId: string;
|
|
17
|
+
tiktokAppId: string;
|
|
18
|
+
accessToken?: string;
|
|
19
|
+
enableAppEvents?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface DeferredDeepLinkResult {
|
|
22
|
+
url?: string;
|
|
23
|
+
source?: string;
|
|
24
|
+
fbclid?: string;
|
|
25
|
+
ttclid?: string;
|
|
26
|
+
utmSource?: string;
|
|
27
|
+
utmMedium?: string;
|
|
28
|
+
utmCampaign?: string;
|
|
29
|
+
utmContent?: string;
|
|
30
|
+
utmTerm?: string;
|
|
31
|
+
campaignId?: string;
|
|
32
|
+
adsetId?: string;
|
|
33
|
+
adId?: string;
|
|
34
|
+
}
|
|
8
35
|
export interface DatalyrConfig {
|
|
9
36
|
apiKey: string;
|
|
10
37
|
workspaceId?: string;
|
|
@@ -30,6 +57,8 @@ export interface DatalyrConfig {
|
|
|
30
57
|
retryDelay: number;
|
|
31
58
|
};
|
|
32
59
|
skadTemplate?: 'ecommerce' | 'gaming' | 'subscription';
|
|
60
|
+
meta?: MetaConfig;
|
|
61
|
+
tiktok?: TikTokConfig;
|
|
33
62
|
}
|
|
34
63
|
export interface EventData {
|
|
35
64
|
[key: string]: any;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datalyr/react-native",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Datalyr SDK for React Native & Expo - Server-side attribution tracking",
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"description": "Datalyr SDK for React Native & Expo - Server-side attribution tracking with bundled Meta and TikTok SDKs",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -14,8 +14,11 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"lib/",
|
|
16
16
|
"src/",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"ios/",
|
|
18
|
+
"README.md",
|
|
19
|
+
"CHANGELOG.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"*.podspec"
|
|
19
22
|
],
|
|
20
23
|
"keywords": [
|
|
21
24
|
"react-native",
|
|
@@ -35,8 +38,11 @@
|
|
|
35
38
|
"tiktok-attribution",
|
|
36
39
|
"google-attribution",
|
|
37
40
|
"ios-attribution",
|
|
41
|
+
"apple-search-ads",
|
|
38
42
|
"conversion-tracking",
|
|
39
|
-
"revenue-optimization"
|
|
43
|
+
"revenue-optimization",
|
|
44
|
+
"deferred-deep-linking",
|
|
45
|
+
"fbclid"
|
|
40
46
|
],
|
|
41
47
|
"author": "Datalyr",
|
|
42
48
|
"license": "MIT",
|