@datalyr/react-native 1.2.1 → 1.3.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 (40) hide show
  1. package/android/build.gradle +54 -0
  2. package/android/src/main/AndroidManifest.xml +14 -0
  3. package/android/src/main/java/com/datalyr/reactnative/DatalyrNativeModule.java +423 -0
  4. package/android/src/main/java/com/datalyr/reactnative/DatalyrPackage.java +30 -0
  5. package/android/src/main/java/com/datalyr/reactnative/DatalyrPlayInstallReferrerModule.java +229 -0
  6. package/datalyr-react-native.podspec +2 -2
  7. package/ios/DatalyrSKAdNetwork.m +52 -1
  8. package/lib/ConversionValueEncoder.d.ts +13 -1
  9. package/lib/ConversionValueEncoder.js +57 -23
  10. package/lib/datalyr-sdk.d.ts +25 -2
  11. package/lib/datalyr-sdk.js +59 -8
  12. package/lib/index.d.ts +2 -0
  13. package/lib/index.js +1 -0
  14. package/lib/integrations/index.d.ts +3 -1
  15. package/lib/integrations/index.js +2 -1
  16. package/lib/integrations/meta-integration.d.ts +1 -0
  17. package/lib/integrations/meta-integration.js +4 -3
  18. package/lib/integrations/play-install-referrer.d.ts +74 -0
  19. package/lib/integrations/play-install-referrer.js +156 -0
  20. package/lib/integrations/tiktok-integration.d.ts +1 -0
  21. package/lib/integrations/tiktok-integration.js +4 -3
  22. package/lib/journey.d.ts +106 -0
  23. package/lib/journey.js +258 -0
  24. package/lib/native/DatalyrNativeBridge.d.ts +42 -3
  25. package/lib/native/DatalyrNativeBridge.js +63 -9
  26. package/lib/native/SKAdNetworkBridge.d.ts +21 -0
  27. package/lib/native/SKAdNetworkBridge.js +54 -0
  28. package/package.json +8 -3
  29. package/src/ConversionValueEncoder.ts +67 -26
  30. package/src/datalyr-sdk-expo.ts +55 -6
  31. package/src/datalyr-sdk.ts +72 -13
  32. package/src/expo.ts +4 -0
  33. package/src/index.ts +2 -0
  34. package/src/integrations/index.ts +3 -1
  35. package/src/integrations/meta-integration.ts +4 -3
  36. package/src/integrations/play-install-referrer.ts +203 -0
  37. package/src/integrations/tiktok-integration.ts +4 -3
  38. package/src/journey.ts +338 -0
  39. package/src/native/DatalyrNativeBridge.ts +99 -13
  40. package/src/native/SKAdNetworkBridge.ts +86 -2
package/lib/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export declare const datalyr: DatalyrSDK;
3
3
  export { Datalyr };
4
4
  export * from './types';
5
5
  export { attributionManager } from './attribution';
6
+ export { journeyManager } from './journey';
7
+ export type { TouchAttribution, TouchPoint } from './journey';
6
8
  export { createAutoEventsManager, AutoEventsManager } from './auto-events';
7
9
  export * from './utils';
8
10
  export * from './http-client';
package/lib/index.js CHANGED
@@ -8,6 +8,7 @@ export { Datalyr };
8
8
  // Export types and utilities
9
9
  export * from './types';
10
10
  export { attributionManager } from './attribution';
11
+ export { journeyManager } from './journey';
11
12
  export { createAutoEventsManager, AutoEventsManager } from './auto-events';
12
13
  // Re-export utilities for advanced usage
13
14
  export * from './utils';
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Platform SDK Integrations
3
- * Meta (Facebook), TikTok, and Apple Search Ads SDK wrappers
3
+ * Meta (Facebook), TikTok, Apple Search Ads, and Google Play Install Referrer SDK wrappers
4
4
  */
5
5
  export { MetaIntegration, metaIntegration } from './meta-integration';
6
6
  export { TikTokIntegration, tiktokIntegration } from './tiktok-integration';
7
7
  export { AppleSearchAdsIntegration, appleSearchAdsIntegration } from './apple-search-ads-integration';
8
+ export { playInstallReferrerIntegration } from './play-install-referrer';
9
+ export type { PlayInstallReferrer } from './play-install-referrer';
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Platform SDK Integrations
3
- * Meta (Facebook), TikTok, and Apple Search Ads SDK wrappers
3
+ * Meta (Facebook), TikTok, Apple Search Ads, and Google Play Install Referrer SDK wrappers
4
4
  */
5
5
  export { MetaIntegration, metaIntegration } from './meta-integration';
6
6
  export { TikTokIntegration, tiktokIntegration } from './tiktok-integration';
7
7
  export { AppleSearchAdsIntegration, appleSearchAdsIntegration } from './apple-search-ads-integration';
8
+ export { playInstallReferrerIntegration } from './play-install-referrer';
@@ -15,6 +15,7 @@ export declare class MetaIntegration {
15
15
  private deferredDeepLinkData;
16
16
  /**
17
17
  * Initialize Meta SDK with configuration
18
+ * Supported on both iOS and Android via native modules
18
19
  */
19
20
  initialize(config: MetaConfig, debug?: boolean): Promise<void>;
20
21
  /**
@@ -18,14 +18,15 @@ export class MetaIntegration {
18
18
  }
19
19
  /**
20
20
  * Initialize Meta SDK with configuration
21
+ * Supported on both iOS and Android via native modules
21
22
  */
22
23
  async initialize(config, debug = false) {
23
24
  var _a;
24
25
  this.debug = debug;
25
26
  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');
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');
29
30
  return;
30
31
  }
31
32
  this.available = isNativeModuleAvailable();
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Google Play Install Referrer Integration
3
+ *
4
+ * Provides Android install attribution via the Google Play Install Referrer API.
5
+ * This captures UTM parameters and click IDs passed through Google Play Store.
6
+ *
7
+ * How it works:
8
+ * 1. User clicks ad/link with UTM parameters
9
+ * 2. Google Play Store stores the referrer URL
10
+ * 3. On first app launch, SDK retrieves the referrer
11
+ * 4. Attribution data (utm_source, utm_medium, gclid, etc.) is extracted
12
+ *
13
+ * Requirements:
14
+ * - Android only (returns null on iOS)
15
+ * - Requires Google Play Install Referrer Library in build.gradle:
16
+ * implementation 'com.android.installreferrer:installreferrer:2.2'
17
+ *
18
+ * Attribution data captured:
19
+ * - referrer_url: Full referrer URL from Play Store
20
+ * - referrer_click_timestamp: When the referrer link was clicked
21
+ * - install_begin_timestamp: When the install began
22
+ * - gclid: Google Ads click ID (if present)
23
+ * - utm_source, utm_medium, utm_campaign, etc.
24
+ */
25
+ export interface PlayInstallReferrer {
26
+ referrerUrl: string;
27
+ referrerClickTimestamp: number;
28
+ installBeginTimestamp: number;
29
+ installCompleteTimestamp?: number;
30
+ gclid?: string;
31
+ utmSource?: string;
32
+ utmMedium?: string;
33
+ utmCampaign?: string;
34
+ utmTerm?: string;
35
+ utmContent?: string;
36
+ [key: string]: any;
37
+ }
38
+ /**
39
+ * Google Play Install Referrer Integration
40
+ *
41
+ * Retrieves install attribution data from Google Play Store.
42
+ * Only available on Android.
43
+ */
44
+ declare class PlayInstallReferrerIntegration {
45
+ private referrerData;
46
+ private initialized;
47
+ /**
48
+ * Check if Play Install Referrer is available
49
+ */
50
+ isAvailable(): boolean;
51
+ /**
52
+ * Initialize and fetch install referrer data
53
+ * Should be called once on first app launch
54
+ */
55
+ initialize(): Promise<void>;
56
+ /**
57
+ * Fetch install referrer from Play Store
58
+ */
59
+ fetchInstallReferrer(): Promise<PlayInstallReferrer | null>;
60
+ /**
61
+ * Parse referrer URL to extract UTM parameters and click IDs
62
+ */
63
+ private parseReferrerUrl;
64
+ /**
65
+ * Get cached install referrer data
66
+ */
67
+ getReferrerData(): PlayInstallReferrer | null;
68
+ /**
69
+ * Get attribution data in standard format
70
+ */
71
+ getAttributionData(): Record<string, any>;
72
+ }
73
+ export declare const playInstallReferrerIntegration: PlayInstallReferrerIntegration;
74
+ export {};
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Google Play Install Referrer Integration
3
+ *
4
+ * Provides Android install attribution via the Google Play Install Referrer API.
5
+ * This captures UTM parameters and click IDs passed through Google Play Store.
6
+ *
7
+ * How it works:
8
+ * 1. User clicks ad/link with UTM parameters
9
+ * 2. Google Play Store stores the referrer URL
10
+ * 3. On first app launch, SDK retrieves the referrer
11
+ * 4. Attribution data (utm_source, utm_medium, gclid, etc.) is extracted
12
+ *
13
+ * Requirements:
14
+ * - Android only (returns null on iOS)
15
+ * - Requires Google Play Install Referrer Library in build.gradle:
16
+ * implementation 'com.android.installreferrer:installreferrer:2.2'
17
+ *
18
+ * Attribution data captured:
19
+ * - referrer_url: Full referrer URL from Play Store
20
+ * - referrer_click_timestamp: When the referrer link was clicked
21
+ * - install_begin_timestamp: When the install began
22
+ * - gclid: Google Ads click ID (if present)
23
+ * - utm_source, utm_medium, utm_campaign, etc.
24
+ */
25
+ import { Platform, NativeModules } from 'react-native';
26
+ import { debugLog, errorLog } from '../utils';
27
+ const { DatalyrPlayInstallReferrer } = NativeModules;
28
+ /**
29
+ * Google Play Install Referrer Integration
30
+ *
31
+ * Retrieves install attribution data from Google Play Store.
32
+ * Only available on Android.
33
+ */
34
+ class PlayInstallReferrerIntegration {
35
+ constructor() {
36
+ this.referrerData = null;
37
+ this.initialized = false;
38
+ }
39
+ /**
40
+ * Check if Play Install Referrer is available
41
+ */
42
+ isAvailable() {
43
+ return Platform.OS === 'android' && !!DatalyrPlayInstallReferrer;
44
+ }
45
+ /**
46
+ * Initialize and fetch install referrer data
47
+ * Should be called once on first app launch
48
+ */
49
+ async initialize() {
50
+ if (this.initialized)
51
+ return;
52
+ if (!this.isAvailable()) {
53
+ debugLog('[PlayInstallReferrer] Not available (iOS or native module missing)');
54
+ return;
55
+ }
56
+ try {
57
+ this.referrerData = await this.fetchInstallReferrer();
58
+ this.initialized = true;
59
+ if (this.referrerData) {
60
+ debugLog('[PlayInstallReferrer] Install referrer fetched:', {
61
+ utmSource: this.referrerData.utmSource,
62
+ utmMedium: this.referrerData.utmMedium,
63
+ hasGclid: !!this.referrerData.gclid,
64
+ });
65
+ }
66
+ }
67
+ catch (error) {
68
+ errorLog('[PlayInstallReferrer] Failed to initialize:', error);
69
+ }
70
+ }
71
+ /**
72
+ * Fetch install referrer from Play Store
73
+ */
74
+ async fetchInstallReferrer() {
75
+ if (!this.isAvailable()) {
76
+ return null;
77
+ }
78
+ try {
79
+ const referrer = await DatalyrPlayInstallReferrer.getInstallReferrer();
80
+ if (!referrer) {
81
+ return null;
82
+ }
83
+ // Parse UTM parameters from referrer URL
84
+ const parsed = this.parseReferrerUrl(referrer.referrerUrl);
85
+ return {
86
+ ...referrer,
87
+ ...parsed,
88
+ };
89
+ }
90
+ catch (error) {
91
+ errorLog('[PlayInstallReferrer] Error fetching referrer:', error);
92
+ return null;
93
+ }
94
+ }
95
+ /**
96
+ * Parse referrer URL to extract UTM parameters and click IDs
97
+ */
98
+ parseReferrerUrl(referrerUrl) {
99
+ const params = {};
100
+ if (!referrerUrl)
101
+ return params;
102
+ try {
103
+ // Referrer URL is URL-encoded, decode it first
104
+ const decoded = decodeURIComponent(referrerUrl);
105
+ const searchParams = new URLSearchParams(decoded);
106
+ // Extract UTM parameters
107
+ params.utmSource = searchParams.get('utm_source') || undefined;
108
+ params.utmMedium = searchParams.get('utm_medium') || undefined;
109
+ params.utmCampaign = searchParams.get('utm_campaign') || undefined;
110
+ params.utmTerm = searchParams.get('utm_term') || undefined;
111
+ params.utmContent = searchParams.get('utm_content') || undefined;
112
+ // Extract click IDs
113
+ params.gclid = searchParams.get('gclid') || undefined;
114
+ // Store any additional parameters
115
+ searchParams.forEach((value, key) => {
116
+ if (!key.startsWith('utm_') && key !== 'gclid') {
117
+ params[key] = value;
118
+ }
119
+ });
120
+ debugLog('[PlayInstallReferrer] Parsed referrer URL:', params);
121
+ }
122
+ catch (error) {
123
+ errorLog('[PlayInstallReferrer] Error parsing referrer URL:', error);
124
+ }
125
+ return params;
126
+ }
127
+ /**
128
+ * Get cached install referrer data
129
+ */
130
+ getReferrerData() {
131
+ return this.referrerData;
132
+ }
133
+ /**
134
+ * Get attribution data in standard format
135
+ */
136
+ getAttributionData() {
137
+ if (!this.referrerData)
138
+ return {};
139
+ return {
140
+ // Install referrer specific
141
+ install_referrer_url: this.referrerData.referrerUrl,
142
+ referrer_click_timestamp: this.referrerData.referrerClickTimestamp,
143
+ install_begin_timestamp: this.referrerData.installBeginTimestamp,
144
+ // Standard attribution fields
145
+ gclid: this.referrerData.gclid,
146
+ utm_source: this.referrerData.utmSource,
147
+ utm_medium: this.referrerData.utmMedium,
148
+ utm_campaign: this.referrerData.utmCampaign,
149
+ utm_term: this.referrerData.utmTerm,
150
+ utm_content: this.referrerData.utmContent,
151
+ // Source indicators
152
+ attribution_source: 'play_install_referrer',
153
+ };
154
+ }
155
+ }
156
+ export const playInstallReferrerIntegration = new PlayInstallReferrerIntegration();
@@ -14,6 +14,7 @@ export declare class TikTokIntegration {
14
14
  private debug;
15
15
  /**
16
16
  * Initialize TikTok SDK with configuration
17
+ * Supported on both iOS and Android via native modules
17
18
  */
18
19
  initialize(config: TikTokConfig, debug?: boolean): Promise<void>;
19
20
  /**
@@ -41,13 +41,14 @@ export class TikTokIntegration {
41
41
  }
42
42
  /**
43
43
  * Initialize TikTok SDK with configuration
44
+ * Supported on both iOS and Android via native modules
44
45
  */
45
46
  async initialize(config, debug = false) {
46
47
  this.debug = debug;
47
48
  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');
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');
51
52
  return;
52
53
  }
53
54
  this.available = isNativeModuleAvailable();
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Journey Tracking Module for React Native
3
+ * Mirrors the Web SDK's journey tracking capabilities:
4
+ * - First-touch attribution with 90-day expiration
5
+ * - Last-touch attribution with 90-day expiration
6
+ * - Up to 30 touchpoints stored
7
+ */
8
+ /**
9
+ * Attribution data for a touch
10
+ */
11
+ export interface TouchAttribution {
12
+ timestamp: number;
13
+ expires_at: number;
14
+ captured_at: number;
15
+ source?: string;
16
+ medium?: string;
17
+ campaign?: string;
18
+ term?: string;
19
+ content?: string;
20
+ clickId?: string;
21
+ clickIdType?: string;
22
+ fbclid?: string;
23
+ gclid?: string;
24
+ ttclid?: string;
25
+ gbraid?: string;
26
+ wbraid?: string;
27
+ lyr?: string;
28
+ landingPage?: string;
29
+ referrer?: string;
30
+ }
31
+ /**
32
+ * A single touchpoint in the customer journey
33
+ */
34
+ export interface TouchPoint {
35
+ timestamp: number;
36
+ sessionId: string;
37
+ source?: string;
38
+ medium?: string;
39
+ campaign?: string;
40
+ clickIdType?: string;
41
+ }
42
+ /**
43
+ * Journey manager for tracking customer touchpoints
44
+ */
45
+ export declare class JourneyManager {
46
+ private firstTouch;
47
+ private lastTouch;
48
+ private journey;
49
+ private initialized;
50
+ /**
51
+ * Initialize journey tracking by loading persisted data
52
+ */
53
+ initialize(): Promise<void>;
54
+ /**
55
+ * Check if attribution has expired
56
+ */
57
+ private isExpired;
58
+ /**
59
+ * Store first touch attribution (only if not already set or expired)
60
+ */
61
+ storeFirstTouch(attribution: Partial<TouchAttribution>): Promise<void>;
62
+ /**
63
+ * Get first touch attribution (null if expired)
64
+ */
65
+ getFirstTouch(): TouchAttribution | null;
66
+ /**
67
+ * Store last touch attribution (always updates)
68
+ */
69
+ storeLastTouch(attribution: Partial<TouchAttribution>): Promise<void>;
70
+ /**
71
+ * Get last touch attribution (null if expired)
72
+ */
73
+ getLastTouch(): TouchAttribution | null;
74
+ /**
75
+ * Add a touchpoint to the customer journey
76
+ */
77
+ addTouchpoint(sessionId: string, attribution: Partial<TouchAttribution>): Promise<void>;
78
+ /**
79
+ * Get customer journey (all touchpoints)
80
+ */
81
+ getJourney(): TouchPoint[];
82
+ /**
83
+ * Record attribution from a deep link or install
84
+ * Updates first-touch (if not set), last-touch, and adds touchpoint
85
+ */
86
+ recordAttribution(sessionId: string, attribution: Partial<TouchAttribution>): Promise<void>;
87
+ /**
88
+ * Get attribution data for events (mirrors Web SDK format)
89
+ */
90
+ getAttributionData(): Record<string, any>;
91
+ /**
92
+ * Clear all journey data (for testing/reset)
93
+ */
94
+ clearJourney(): Promise<void>;
95
+ /**
96
+ * Get journey summary for debugging
97
+ */
98
+ getJourneySummary(): {
99
+ hasFirstTouch: boolean;
100
+ hasLastTouch: boolean;
101
+ touchpointCount: number;
102
+ daysSinceFirstTouch: number;
103
+ sources: string[];
104
+ };
105
+ }
106
+ export declare const journeyManager: JourneyManager;