@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
package/src/types.ts CHANGED
@@ -7,6 +7,39 @@ 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)
28
+ export interface DeferredDeepLinkResult {
29
+ url?: string;
30
+ source?: string;
31
+ fbclid?: string;
32
+ ttclid?: string;
33
+ utmSource?: string;
34
+ utmMedium?: string;
35
+ utmCampaign?: string;
36
+ utmContent?: string;
37
+ utmTerm?: string;
38
+ campaignId?: string;
39
+ adsetId?: string;
40
+ adId?: string;
41
+ }
42
+
10
43
  // Core SDK Configuration
11
44
  export interface DatalyrConfig {
12
45
  apiKey: string; // Required for server-side tracking
@@ -33,6 +66,12 @@ export interface DatalyrConfig {
33
66
  retryDelay: number;
34
67
  };
35
68
  skadTemplate?: 'ecommerce' | 'gaming' | 'subscription';
69
+
70
+ // Meta (Facebook) SDK Configuration
71
+ meta?: MetaConfig;
72
+
73
+ // TikTok SDK Configuration
74
+ tiktok?: TikTokConfig;
36
75
  }
37
76
  // Event Types
38
77
  export interface EventData {
package/src/utils-expo.ts CHANGED
@@ -9,13 +9,16 @@ import { v4 as uuidv4 } from 'uuid';
9
9
  // Storage keys
10
10
  export const STORAGE_KEYS = {
11
11
  VISITOR_ID: '@datalyr/visitor_id',
12
+ ANONYMOUS_ID: '@datalyr/anonymous_id', // Persistent anonymous identifier
12
13
  SESSION_ID: '@datalyr/session_id',
13
14
  SESSION_START: '@datalyr/session_start',
14
15
  USER_ID: '@datalyr/user_id',
15
16
  USER_PROPERTIES: '@datalyr/user_properties',
17
+ EVENT_QUEUE: '@datalyr/event_queue',
16
18
  ATTRIBUTION_DATA: '@datalyr/attribution_data',
17
19
  INSTALL_TIME: '@datalyr/install_time',
18
20
  LAST_APP_VERSION: '@datalyr/last_app_version',
21
+ LAST_SESSION_TIME: '@datalyr/last_session_time',
19
22
  DEVICE_ID: '@datalyr/device_id',
20
23
  } as const;
21
24
 
@@ -136,17 +139,17 @@ const getOrCreateDeviceId = async (): Promise<string> => {
136
139
  }
137
140
  };
138
141
 
139
- // Visitor ID management
142
+ // Visitor ID management
140
143
  export const getOrCreateVisitorId = async (): Promise<string> => {
141
144
  try {
142
145
  let visitorId = await Storage.getItem<string>(STORAGE_KEYS.VISITOR_ID);
143
-
146
+
144
147
  if (!visitorId) {
145
148
  visitorId = generateUUID();
146
149
  await Storage.setItem(STORAGE_KEYS.VISITOR_ID, visitorId);
147
150
  debugLog('Created new visitor ID:', visitorId);
148
151
  }
149
-
152
+
150
153
  return visitorId;
151
154
  } catch (error) {
152
155
  errorLog('Error managing visitor ID:', error as Error);
@@ -154,6 +157,25 @@ export const getOrCreateVisitorId = async (): Promise<string> => {
154
157
  }
155
158
  };
156
159
 
160
+ // Anonymous ID management - persistent across app reinstalls
161
+ export const getOrCreateAnonymousId = async (): Promise<string> => {
162
+ try {
163
+ let anonymousId = await Storage.getItem<string>(STORAGE_KEYS.ANONYMOUS_ID);
164
+
165
+ if (!anonymousId) {
166
+ // Generate anonymous_id with anon_ prefix to match web SDK
167
+ anonymousId = `anon_${generateUUID()}`;
168
+ await Storage.setItem(STORAGE_KEYS.ANONYMOUS_ID, anonymousId);
169
+ debugLog('Created new anonymous ID:', anonymousId);
170
+ }
171
+
172
+ return anonymousId;
173
+ } catch (error) {
174
+ errorLog('Error managing anonymous ID:', error as Error);
175
+ return `anon_${generateUUID()}`;
176
+ }
177
+ };
178
+
157
179
  // Session management
158
180
  export const getOrCreateSessionId = async (): Promise<string> => {
159
181
  try {
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Interface for SDK utilities
3
+ * Both utils.ts and utils-expo.ts implement this interface
4
+ */
5
+
6
+ import { DeviceInfo, FingerprintData } from './types';
7
+
8
+ export interface SDKUtils {
9
+ STORAGE_KEYS: {
10
+ VISITOR_ID: string;
11
+ ANONYMOUS_ID: string;
12
+ SESSION_ID: string;
13
+ USER_ID: string;
14
+ USER_PROPERTIES: string;
15
+ EVENT_QUEUE: string;
16
+ ATTRIBUTION_DATA: string;
17
+ LAST_SESSION_TIME: string;
18
+ };
19
+
20
+ generateUUID: () => string;
21
+ getOrCreateVisitorId: () => Promise<string>;
22
+ getOrCreateAnonymousId: () => Promise<string>;
23
+ getOrCreateSessionId: () => Promise<string>;
24
+ getDeviceInfo: () => Promise<DeviceInfo>;
25
+ createFingerprintData: () => Promise<FingerprintData>;
26
+ getNetworkType: () => string | Promise<string>;
27
+ validateEventName: (eventName: string) => boolean;
28
+ validateEventData: (eventData: any) => boolean;
29
+ debugLog: (message: string, ...args: any[]) => void;
30
+ errorLog: (message: string, error?: Error) => void;
31
+
32
+ Storage: {
33
+ setItem: (key: string, value: any) => Promise<void>;
34
+ getItem: <T>(key: string) => Promise<T | null>;
35
+ removeItem: (key: string) => Promise<void>;
36
+ clear?: () => Promise<void>;
37
+ };
38
+ }
package/EXPO_INSTALL.md DELETED
@@ -1,297 +0,0 @@
1
- # Datalyr Expo SDK - Installation Guide
2
-
3
- ## Expo Compatibility
4
-
5
- The Datalyr SDK works with all Expo workflows:
6
-
7
- - **Expo Bare Workflow** - Full compatibility (use regular React Native SDK)
8
- - **Expo Managed Workflow** - Requires Expo-specific setup (this guide)
9
- - **Expo Go** - Limited compatibility due to native dependencies
10
-
11
- ## Quick Setup for Expo Managed Workflow
12
-
13
- ### 1. Install Expo Dependencies
14
-
15
- ```bash
16
- # Navigate to your Expo project
17
- cd your-expo-app
18
-
19
- # Install Expo-compatible dependencies
20
- npx expo install @react-native-async-storage/async-storage
21
- npx expo install expo-application
22
- npx expo install expo-constants
23
- npx expo install expo-device
24
- npx expo install expo-network
25
- npx expo install expo-tracking-transparency
26
- npx expo install react-native-get-random-values
27
-
28
- # Install additional dependencies
29
- npm install uuid
30
- npm install --save-dev @types/uuid
31
- ```
32
-
33
- ### 2. Update app.json/app.config.js
34
-
35
- Add required permissions and configuration:
36
-
37
- ```json
38
- {
39
- "expo": {
40
- "name": "Your App",
41
- "version": "1.0.0",
42
- "permissions": [
43
- "INTERNET",
44
- "ACCESS_NETWORK_STATE"
45
- ],
46
- "ios": {
47
- "infoPlist": {
48
- "NSUserTrackingUsageDescription": "This app uses tracking to provide personalized ads and analytics.",
49
- "CFBundleURLTypes": [
50
- {
51
- "CFBundleURLName": "your.app.identifier",
52
- "CFBundleURLSchemes": ["yourappscheme"]
53
- }
54
- ]
55
- }
56
- },
57
- "android": {
58
- "permissions": [
59
- "INTERNET",
60
- "ACCESS_NETWORK_STATE"
61
- ],
62
- "intentFilters": [
63
- {
64
- "action": "VIEW",
65
- "autoVerify": true,
66
- "data": [
67
- {
68
- "scheme": "yourappscheme"
69
- }
70
- ],
71
- "category": [
72
- "BROWSABLE",
73
- "DEFAULT"
74
- ]
75
- }
76
- ]
77
- }
78
- }
79
- }
80
- ```
81
-
82
- ### 3. Copy Expo-Compatible SDK Files
83
-
84
- ```bash
85
- # Create SDK directory
86
- mkdir -p src/datalyr-sdk
87
-
88
- # Copy the Expo-compatible files
89
- # You'll need to create these based on the original SDK but using Expo APIs
90
- ```
91
-
92
- ### 4. Initialize in Your Expo App
93
-
94
- ```typescript
95
- // App.tsx
96
- import React, { useEffect } from 'react';
97
- import 'react-native-get-random-values'; // Important: Must be imported first
98
- import { datalyr } from '@datalyr/react-native-sdk';
99
-
100
- const App: React.FC = () => {
101
- useEffect(() => {
102
- initializeDatalyr();
103
- }, []);
104
-
105
- const initializeDatalyr = async () => {
106
- try {
107
- await datalyr.initialize({
108
- workspaceId: 'ozLZblQ8hN', // Your workspace ID
109
- apiKey: 'dk_your_api_key', // Required for authentication
110
- debug: true,
111
- enableAttribution: true, // ✅ Deep link attribution tracking
112
- autoEvents: {
113
- trackSessions: true, // ✅ Automatic session tracking
114
- trackScreenViews: true, // ✅ Automatic screen tracking
115
- trackAppUpdates: true, // ✅ App version changes
116
- trackPerformance: true, // ✅ App launch time, performance
117
- sessionTimeoutMs: 30 * 60 * 1000, // 30 minutes
118
- },
119
- });
120
-
121
- console.log('Datalyr Expo SDK initialized with auto-events!');
122
- } catch (error) {
123
- console.error('SDK init failed:', error);
124
- }
125
- };
126
-
127
- // ... rest of your app
128
- };
129
-
130
- export default App;
131
- ```
132
-
133
- ## Expo vs React Native CLI Differences
134
-
135
- | Feature | React Native CLI | Expo Managed | Expo Bare |
136
- |---------|------------------|--------------|-----------|
137
- | Device Info | `react-native-device-info` | `expo-device` + `expo-application` | `react-native-device-info` |
138
- | IDFA/GAID | `react-native-idfa` | `expo-tracking-transparency` + setup | `react-native-idfa` |
139
- | Network Detection | `@react-native-community/netinfo` | `expo-network` | `@react-native-community/netinfo` |
140
- | Storage | `@react-native-async-storage/async-storage` | Same ✅ | Same ✅ |
141
- | Attribution | Full support ✅ | Full support ✅ | Full support ✅ |
142
- | Auto Events | Full support ✅ | Full support ✅ | Full support ✅ |
143
-
144
- ## Expo-Specific Features
145
-
146
- ### 1. Device Information
147
- ```typescript
148
- // Uses expo-device and expo-application instead of react-native-device-info
149
- import * as Device from 'expo-device';
150
- import * as Application from 'expo-application';
151
-
152
- const deviceInfo = {
153
- model: Device.modelName,
154
- manufacturer: Device.manufacturer,
155
- osVersion: Device.osVersion,
156
- appVersion: Application.nativeApplicationVersion,
157
- buildNumber: Application.nativeBuildVersion,
158
- bundleId: Application.applicationId,
159
- isEmulator: !Device.isDevice,
160
- };
161
- ```
162
-
163
- ### 2. IDFA Permission (iOS)
164
- ```typescript
165
- // Uses expo-tracking-transparency for iOS IDFA permission
166
- import * as TrackingTransparency from 'expo-tracking-transparency';
167
-
168
- const requestIDFAPermission = async () => {
169
- if (Platform.OS === 'ios') {
170
- const { status } = await TrackingTransparency.requestTrackingPermissionsAsync();
171
- return status === TrackingTransparency.PermissionStatus.GRANTED;
172
- }
173
- return false;
174
- };
175
- ```
176
-
177
- ### 3. Network Detection
178
- ```typescript
179
- // Uses expo-network instead of @react-native-community/netinfo
180
- import * as Network from 'expo-network';
181
-
182
- const getNetworkType = async () => {
183
- const networkState = await Network.getNetworkStateAsync();
184
- return networkState.type; // 'WIFI', 'CELLULAR', etc.
185
- };
186
- ```
187
-
188
- ## Attribution Setup for Expo
189
-
190
- Deep links work the same way, but configuration is in `app.json`:
191
-
192
- ### Test URLs (Same as React Native)
193
- ```typescript
194
- // Test with Datalyr LYR tags
195
- const lyrUrl = 'yourappscheme://open?lyr=expo_campaign&utm_source=facebook&fbclid=abc123';
196
-
197
- // Test Facebook attribution
198
- const facebookUrl = 'yourappscheme://open?utm_source=facebook&utm_campaign=summer_sale&fbclid=IwAR123abc';
199
-
200
- // Test TikTok attribution
201
- const tiktokUrl = 'yourappscheme://open?utm_source=tiktok&utm_campaign=viral_video&ttclid=tiktok123xyz';
202
-
203
- // Test Google attribution
204
- const googleUrl = 'yourappscheme://open?utm_source=google&utm_campaign=brand_search&gclid=google456def';
205
- ```
206
-
207
- ## Testing with Expo
208
-
209
- ### Development
210
- ```bash
211
- # Start Expo development server
212
- npx expo start
213
-
214
- # Test on device/simulator
215
- npx expo start --ios
216
- npx expo start --android
217
- ```
218
-
219
- ### Production Testing
220
- ```bash
221
- # Build for testing
222
- eas build --platform ios --profile preview
223
- eas build --platform android --profile preview
224
-
225
- # Submit to stores
226
- eas submit --platform ios
227
- eas submit --platform android
228
- ```
229
-
230
- ## Expo Limitations
231
-
232
- ### What Works:
233
- - Event tracking and attribution
234
- - Session management
235
- - Screen view tracking
236
- - App lifecycle events
237
- - Deep link attribution
238
- - Basic device fingerprinting
239
-
240
- ### Limitations:
241
- - **IDFA/GAID Collection** - Requires additional setup
242
- - **Advanced Device Info** - Some properties not available in managed workflow
243
- - **Carrier Information** - Not available in managed workflow
244
- - **Custom Native Modules** - Not available in managed workflow
245
-
246
- ## Recommended Setup
247
-
248
- ### For Maximum Compatibility:
249
- 1. **Use Expo Bare Workflow** - Get full React Native CLI features
250
- 2. **Or use regular React Native CLI** - Best for attribution tracking
251
-
252
- ### For Managed Workflow:
253
- 1. **Accept some limitations** - IDFA/GAID might need additional setup
254
- 2. **Core attribution still works** - LYR tags, UTM params, click IDs
255
- 3. **Automatic events work fully** - Sessions, screen views, app lifecycle
256
-
257
- ## Expected Events in Dashboard
258
-
259
- Events will appear in your Datalyr dashboard with `source: 'mobile_app'`:
260
-
261
- **Automatic Events:**
262
- - `session_start` - New user session
263
- - `session_end` - Session ended with stats
264
- - `pageviews` - Screen navigation
265
- - `app_install` - First app launch with attribution
266
- - `app_update` - App version changes
267
- - `app_foreground`/`app_background` - App lifecycle
268
- - `sdk_initialized` - SDK setup complete
269
-
270
- **Manual Events:**
271
- - Custom events from `datalyr.track()`
272
- - User identification from `datalyr.identify()`
273
-
274
- ## Choosing Between Expo and React Native CLI
275
-
276
- ### Choose **React Native CLI** if:
277
- - You need full IDFA/GAID support
278
- - You want maximum attribution accuracy
279
- - You're comfortable with native development
280
- - You need custom native modules
281
-
282
- ### Choose **Expo Managed** if:
283
- - You want easier development and deployment
284
- - Core attribution (LYR tags, UTM, click IDs) is sufficient
285
- - You're okay with some device fingerprinting limitations
286
- - You prioritize development speed over maximum tracking
287
-
288
- ### Choose **Expo Bare** if:
289
- - You want the best of both worlds
290
- - You can use the full React Native CLI SDK
291
- - You like Expo's build and deployment tools
292
-
293
- ---
294
-
295
- **Ready to test?** Your Expo app with automatic attribution is ready!
296
-
297
- The SDK provides 90% of the attribution value even with Expo's managed workflow limitations.