@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
package/src/types.ts CHANGED
@@ -7,29 +7,13 @@ export interface AutoEventConfig {
7
7
  sessionTimeoutMs?: number;
8
8
  }
9
9
 
10
- // Meta (Facebook) SDK Configuration
11
- export interface MetaConfig {
12
- appId: string; // Facebook App ID
13
- clientToken?: string; // Client Token for advanced features
14
- enableDeferredDeepLink?: boolean; // Default: true
15
- enableAppEvents?: boolean; // Default: true
16
- advertiserTrackingEnabled?: boolean; // iOS ATT status (auto-detected if not set)
17
- }
18
-
19
- // TikTok SDK Configuration
20
- export interface TikTokConfig {
21
- appId: string; // Your App ID (for Datalyr)
22
- tiktokAppId: string; // TikTok App ID
23
- accessToken?: string; // Access Token for Events API
24
- enableAppEvents?: boolean; // Default: true
25
- }
26
-
27
- // Deferred Deep Link Result (from platform SDKs)
10
+ // Deferred Deep Link Result (from Play Install Referrer on Android)
28
11
  export interface DeferredDeepLinkResult {
29
12
  url?: string;
30
13
  source?: string;
31
14
  fbclid?: string;
32
15
  ttclid?: string;
16
+ gclid?: string;
33
17
  utmSource?: string;
34
18
  utmMedium?: string;
35
19
  utmCampaign?: string;
@@ -51,8 +35,6 @@ export interface DeferredDeepLinkResult {
51
35
  * enableAutoEvents: true,
52
36
  * enableAttribution: true,
53
37
  * skadTemplate: 'ecommerce',
54
- * meta: { appId: 'FB_APP_ID' },
55
- * tiktok: { appId: 'APP_ID', tiktokAppId: 'TIKTOK_APP_ID' },
56
38
  * });
57
39
  * ```
58
40
  */
@@ -135,11 +117,6 @@ export interface DatalyrConfig {
135
117
  /** SKAdNetwork template for automatic conversion value encoding (iOS only) */
136
118
  skadTemplate?: 'ecommerce' | 'gaming' | 'subscription';
137
119
 
138
- /** Meta (Facebook) SDK Configuration */
139
- meta?: MetaConfig;
140
-
141
- /** TikTok SDK Configuration */
142
- tiktok?: TikTokConfig;
143
120
  }
144
121
  // Event Types
145
122
  export interface EventData {
package/src/utils-expo.ts CHANGED
@@ -319,8 +319,8 @@ export const validateEventName = (eventName: string): boolean => {
319
319
  return false;
320
320
  }
321
321
 
322
- // Allow letters, numbers, underscores, and hyphens
323
- const validPattern = /^[a-zA-Z0-9_-]+$/;
322
+ // Allow letters, numbers, underscores, hyphens, and $ prefix (for system events like $identify)
323
+ const validPattern = /^\$?[a-zA-Z0-9_-]+$/;
324
324
  return validPattern.test(eventName);
325
325
  };
326
326
 
@@ -1,14 +0,0 @@
1
- #import <Foundation/Foundation.h>
2
-
3
- NS_ASSUME_NONNULL_BEGIN
4
-
5
- /// Catches ObjC NSExceptions (from Meta/TikTok SDKs) and converts them to NSErrors.
6
- /// Swift's do/try/catch cannot catch NSExceptions — they propagate through Hermes
7
- /// and cause EXC_BAD_ACCESS (SIGSEGV) crashes.
8
- @interface DatalyrObjCExceptionCatcher : NSObject
9
-
10
- + (BOOL)tryBlock:(void(NS_NOESCAPE ^)(void))block error:(NSError *_Nullable *_Nullable)error;
11
-
12
- @end
13
-
14
- NS_ASSUME_NONNULL_END
@@ -1,30 +0,0 @@
1
- #import "DatalyrObjCExceptionCatcher.h"
2
-
3
- @implementation DatalyrObjCExceptionCatcher
4
-
5
- + (BOOL)tryBlock:(void(NS_NOESCAPE ^)(void))block error:(NSError **)error {
6
- @try {
7
- block();
8
- return YES;
9
- }
10
- @catch (NSException *exception) {
11
- if (error) {
12
- NSString *description = exception.reason ?: exception.name;
13
- NSDictionary *userInfo = @{
14
- NSLocalizedDescriptionKey: description,
15
- @"ExceptionName": exception.name ?: @"Unknown",
16
- };
17
- if (exception.userInfo) {
18
- NSMutableDictionary *merged = [userInfo mutableCopy];
19
- [merged addEntriesFromDictionary:exception.userInfo];
20
- userInfo = merged;
21
- }
22
- *error = [NSError errorWithDomain:@"com.datalyr.objc-exception"
23
- code:-1
24
- userInfo:userInfo];
25
- }
26
- return NO;
27
- }
28
- }
29
-
30
- @end
@@ -1,77 +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
- 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
- * Supported on both iOS and Android via native modules
19
- */
20
- initialize(config: MetaConfig, debug?: boolean): Promise<void>;
21
- /**
22
- * Update tracking authorization status (call after ATT prompt)
23
- */
24
- updateTrackingAuthorization(enabled: boolean): Promise<void>;
25
- /**
26
- * Fetch deferred deep link from Meta SDK
27
- * This captures fbclid for installs that went through App Store
28
- */
29
- fetchDeferredDeepLink(): Promise<DeferredDeepLinkResult | null>;
30
- /**
31
- * Parse deep link URL to extract attribution parameters
32
- */
33
- private parseDeepLinkUrl;
34
- /**
35
- * Log purchase event to Meta
36
- */
37
- logPurchase(value: number, currency: string, parameters?: Record<string, any>): Promise<void>;
38
- /**
39
- * Log custom event to Meta
40
- */
41
- logEvent(eventName: string, valueToSum?: number, parameters?: Record<string, any>): Promise<void>;
42
- /**
43
- * Set user data for Advanced Matching (improves conversion attribution)
44
- * Note: Meta's Advanced Matching uses these specific fields - externalId is not supported
45
- */
46
- setUserData(userData: {
47
- email?: string;
48
- firstName?: string;
49
- lastName?: string;
50
- phone?: string;
51
- dateOfBirth?: string;
52
- gender?: string;
53
- city?: string;
54
- state?: string;
55
- zip?: string;
56
- country?: string;
57
- }): Promise<void>;
58
- /**
59
- * Clear user data (call on logout)
60
- */
61
- clearUserData(): Promise<void>;
62
- /**
63
- * Get cached deferred deep link data
64
- */
65
- getDeferredDeepLinkData(): DeferredDeepLinkResult | null;
66
- /**
67
- * Check if Meta SDK is available and initialized
68
- */
69
- isAvailable(): boolean;
70
- /**
71
- * Check if Meta SDK native module is installed
72
- */
73
- isInstalled(): boolean;
74
- private log;
75
- private logError;
76
- }
77
- export declare const metaIntegration: MetaIntegration;
@@ -1,219 +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
- 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
- * Supported on both iOS and Android via native modules
22
- */
23
- async initialize(config, debug = false) {
24
- var _a;
25
- this.debug = debug;
26
- this.config = config;
27
- // Only available on iOS and Android via native modules
28
- if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
29
- this.log('Meta SDK only available on iOS and Android');
30
- return;
31
- }
32
- this.available = isNativeModuleAvailable();
33
- if (!this.available) {
34
- this.log('Meta native module not available');
35
- return;
36
- }
37
- try {
38
- const success = await MetaNativeBridge.initialize(config.appId, config.clientToken, (_a = config.advertiserTrackingEnabled) !== null && _a !== void 0 ? _a : false);
39
- if (success) {
40
- this.initialized = true;
41
- this.log(`Meta SDK initialized with App ID: ${config.appId}`);
42
- }
43
- }
44
- catch (error) {
45
- this.logError('Failed to initialize Meta SDK:', error);
46
- }
47
- }
48
- /**
49
- * Update tracking authorization status (call after ATT prompt)
50
- */
51
- async updateTrackingAuthorization(enabled) {
52
- if (!this.available || !this.initialized)
53
- return;
54
- try {
55
- await MetaNativeBridge.updateTrackingAuthorization(enabled);
56
- this.log(`Meta ATT status updated: ${enabled ? 'authorized' : 'not authorized'}`);
57
- }
58
- catch (error) {
59
- this.logError('Failed to update Meta tracking authorization:', error);
60
- }
61
- }
62
- /**
63
- * Fetch deferred deep link from Meta SDK
64
- * This captures fbclid for installs that went through App Store
65
- */
66
- async fetchDeferredDeepLink() {
67
- var _a;
68
- if (!this.available || !this.initialized) {
69
- return null;
70
- }
71
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableDeferredDeepLink) === false) {
72
- return null;
73
- }
74
- try {
75
- const url = await MetaNativeBridge.fetchDeferredAppLink();
76
- if (!url) {
77
- this.log('No deferred deep link available from Meta');
78
- return null;
79
- }
80
- // Parse the URL for attribution parameters
81
- const result = this.parseDeepLinkUrl(url);
82
- this.deferredDeepLinkData = result;
83
- this.log(`Meta deferred deep link fetched: ${url}`);
84
- return result;
85
- }
86
- catch (error) {
87
- // This is expected to fail in some scenarios - log but don't treat as error
88
- this.log('Could not fetch Meta deferred deep link (may not be available)');
89
- return null;
90
- }
91
- }
92
- /**
93
- * Parse deep link URL to extract attribution parameters
94
- */
95
- parseDeepLinkUrl(urlString) {
96
- const result = {
97
- url: urlString,
98
- source: 'meta',
99
- };
100
- try {
101
- const url = new URL(urlString);
102
- const params = url.searchParams;
103
- // Extract known parameters
104
- if (params.get('fbclid'))
105
- result.fbclid = params.get('fbclid');
106
- if (params.get('utm_source'))
107
- result.utmSource = params.get('utm_source');
108
- if (params.get('utm_medium'))
109
- result.utmMedium = params.get('utm_medium');
110
- if (params.get('utm_campaign'))
111
- result.utmCampaign = params.get('utm_campaign');
112
- if (params.get('utm_content'))
113
- result.utmContent = params.get('utm_content');
114
- if (params.get('utm_term'))
115
- result.utmTerm = params.get('utm_term');
116
- if (params.get('campaign_id'))
117
- result.campaignId = params.get('campaign_id');
118
- if (params.get('adset_id'))
119
- result.adsetId = params.get('adset_id');
120
- if (params.get('ad_id'))
121
- result.adId = params.get('ad_id');
122
- }
123
- catch (error) {
124
- this.logError('Failed to parse deep link URL:', error);
125
- }
126
- return result;
127
- }
128
- /**
129
- * Log purchase event to Meta
130
- */
131
- async logPurchase(value, currency, parameters) {
132
- var _a;
133
- if (!this.available || !this.initialized)
134
- return;
135
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
136
- return;
137
- try {
138
- await MetaNativeBridge.logPurchase(value, currency, parameters);
139
- this.log(`Meta purchase event logged: ${value} ${currency}`);
140
- }
141
- catch (error) {
142
- this.logError('Failed to log Meta purchase:', error);
143
- }
144
- }
145
- /**
146
- * Log custom event to Meta
147
- */
148
- async logEvent(eventName, valueToSum, parameters) {
149
- var _a;
150
- if (!this.available || !this.initialized)
151
- return;
152
- if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.enableAppEvents) === false)
153
- return;
154
- try {
155
- await MetaNativeBridge.logEvent(eventName, valueToSum, parameters);
156
- this.log(`Meta event logged: ${eventName}`);
157
- }
158
- catch (error) {
159
- this.logError('Failed to log Meta event:', error);
160
- }
161
- }
162
- /**
163
- * Set user data for Advanced Matching (improves conversion attribution)
164
- * Note: Meta's Advanced Matching uses these specific fields - externalId is not supported
165
- */
166
- async setUserData(userData) {
167
- if (!this.available || !this.initialized)
168
- return;
169
- try {
170
- await MetaNativeBridge.setUserData(userData);
171
- this.log('Meta user data set for Advanced Matching');
172
- }
173
- catch (error) {
174
- this.logError('Failed to set Meta user data:', error);
175
- }
176
- }
177
- /**
178
- * Clear user data (call on logout)
179
- */
180
- async clearUserData() {
181
- if (!this.available || !this.initialized)
182
- return;
183
- try {
184
- await MetaNativeBridge.clearUserData();
185
- this.log('Meta user data cleared');
186
- }
187
- catch (error) {
188
- this.logError('Failed to clear Meta user data:', error);
189
- }
190
- }
191
- /**
192
- * Get cached deferred deep link data
193
- */
194
- getDeferredDeepLinkData() {
195
- return this.deferredDeepLinkData;
196
- }
197
- /**
198
- * Check if Meta SDK is available and initialized
199
- */
200
- isAvailable() {
201
- return this.available && this.initialized;
202
- }
203
- /**
204
- * Check if Meta SDK native module is installed
205
- */
206
- isInstalled() {
207
- return this.available;
208
- }
209
- log(message, data) {
210
- if (this.debug) {
211
- console.log(`[Datalyr/Meta] ${message}`, data || '');
212
- }
213
- }
214
- logError(message, error) {
215
- console.error(`[Datalyr/Meta] ${message}`, error);
216
- }
217
- }
218
- // Export singleton instance
219
- export const metaIntegration = new MetaIntegration();
@@ -1,83 +0,0 @@
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
- * Supported on both iOS and Android via native modules
18
- */
19
- initialize(config: TikTokConfig, debug?: boolean): Promise<void>;
20
- /**
21
- * Update tracking authorization status (call after ATT prompt)
22
- */
23
- updateTrackingAuthorization(enabled: boolean): Promise<void>;
24
- /**
25
- * Log purchase event to TikTok (uses Purchase - TikTok's current standard event)
26
- */
27
- logPurchase(value: number, currency: string, contentId?: string, contentType?: string, parameters?: Record<string, any>): Promise<void>;
28
- /**
29
- * Log subscription event to TikTok
30
- */
31
- logSubscription(value: number, currency: string, plan?: string): Promise<void>;
32
- /**
33
- * Log add to cart event
34
- */
35
- logAddToCart(value: number, currency: string, contentId?: string, contentType?: string): Promise<void>;
36
- /**
37
- * Log view content event
38
- */
39
- logViewContent(contentId?: string, contentName?: string, contentType?: string): Promise<void>;
40
- /**
41
- * Log initiate checkout event
42
- */
43
- logInitiateCheckout(value: number, currency: string, numItems?: number): Promise<void>;
44
- /**
45
- * Log complete registration event
46
- */
47
- logCompleteRegistration(method?: string): Promise<void>;
48
- /**
49
- * Log search event
50
- */
51
- logSearch(query: string): Promise<void>;
52
- /**
53
- * Log lead event (uses Lead - current standard, SubmitForm is legacy)
54
- */
55
- logLead(value?: number, currency?: string): Promise<void>;
56
- /**
57
- * Log add payment info event
58
- */
59
- logAddPaymentInfo(success: boolean): Promise<void>;
60
- /**
61
- * Log custom event to TikTok
62
- */
63
- trackEvent(eventName: string, properties?: Record<string, any>): Promise<void>;
64
- /**
65
- * Identify user for improved attribution matching
66
- */
67
- identify(email?: string, phone?: string, externalId?: string): Promise<void>;
68
- /**
69
- * Clear user session (call on logout)
70
- */
71
- logout(): Promise<void>;
72
- /**
73
- * Check if TikTok SDK is available and initialized
74
- */
75
- isAvailable(): boolean;
76
- /**
77
- * Check if TikTok SDK native module is installed
78
- */
79
- isInstalled(): boolean;
80
- private log;
81
- private logError;
82
- }
83
- export declare const tiktokIntegration: TikTokIntegration;