@datalyr/react-native 1.3.0 → 1.3.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.
@@ -1,9 +1,9 @@
1
1
  import { NativeModules, Platform } from 'react-native';
2
2
 
3
- // SKAN 4.0 coarse value type
3
+ // SKAN 4.0 / AdAttributionKit coarse value type
4
4
  export type SKANCoarseValue = 'low' | 'medium' | 'high';
5
5
 
6
- // SKAN 4.0 conversion result
6
+ // SKAN 4.0 / AdAttributionKit conversion result
7
7
  export interface SKANConversionResult {
8
8
  fineValue: number; // 0-63
9
9
  coarseValue: SKANCoarseValue;
@@ -11,14 +11,80 @@ export interface SKANConversionResult {
11
11
  priority: number;
12
12
  }
13
13
 
14
+ // Response from native postback update
15
+ export interface PostbackUpdateResponse {
16
+ success: boolean;
17
+ framework: 'AdAttributionKit' | 'SKAdNetwork';
18
+ fineValue: number;
19
+ coarseValue: string;
20
+ lockWindow: boolean;
21
+ type?: 'reengagement'; // Only for re-engagement updates
22
+ }
23
+
24
+ // Attribution framework info returned by native module
25
+ export interface AttributionFrameworkInfo {
26
+ framework: 'AdAttributionKit' | 'SKAdNetwork' | 'none';
27
+ version: string;
28
+ reengagement_available: boolean;
29
+ overlapping_windows: boolean;
30
+ fine_value_range: { min: number; max: number };
31
+ coarse_values: string[];
32
+ }
33
+
34
+ // Enhanced attribution info for iOS 18.4+ with geo and dev postback support
35
+ export interface EnhancedAttributionInfo extends AttributionFrameworkInfo {
36
+ geo_postback_available: boolean;
37
+ development_postbacks: boolean;
38
+ features: string[];
39
+ }
40
+
41
+ // Postback environment configuration response
42
+ export interface PostbackEnvironmentResponse {
43
+ environment: 'production' | 'sandbox';
44
+ isSandbox: boolean;
45
+ note: string;
46
+ }
47
+
48
+ // Overlapping window postback response (iOS 18.4+)
49
+ export interface OverlappingWindowPostbackResponse {
50
+ success: boolean;
51
+ framework: string;
52
+ version: string;
53
+ fineValue: number;
54
+ coarseValue: string;
55
+ lockWindow: boolean;
56
+ windowIndex: number;
57
+ overlappingWindows: boolean;
58
+ note?: string;
59
+ }
60
+
14
61
  interface SKAdNetworkModule {
15
62
  updateConversionValue(value: number): Promise<boolean>;
16
63
  updatePostbackConversionValue(
17
64
  fineValue: number,
18
65
  coarseValue: string,
19
66
  lockWindow: boolean
20
- ): Promise<boolean>;
67
+ ): Promise<PostbackUpdateResponse>;
68
+ updateReengagementConversionValue(
69
+ fineValue: number,
70
+ coarseValue: string,
71
+ lockWindow: boolean
72
+ ): Promise<PostbackUpdateResponse>;
21
73
  isSKAN4Available(): Promise<boolean>;
74
+ isAdAttributionKitAvailable(): Promise<boolean>;
75
+ isOverlappingWindowsAvailable(): Promise<boolean>;
76
+ registerForAttribution(): Promise<{ framework: string; registered: boolean }>;
77
+ getAttributionInfo(): Promise<AttributionFrameworkInfo>;
78
+ // iOS 18.4+ methods
79
+ isGeoPostbackAvailable(): Promise<boolean>;
80
+ setPostbackEnvironment(environment: string): Promise<PostbackEnvironmentResponse>;
81
+ getEnhancedAttributionInfo(): Promise<EnhancedAttributionInfo>;
82
+ updatePostbackWithWindow(
83
+ fineValue: number,
84
+ coarseValue: string,
85
+ lockWindow: boolean,
86
+ windowIndex: number
87
+ ): Promise<OverlappingWindowPostbackResponse>;
22
88
  }
23
89
 
24
90
  const { DatalyrSKAdNetwork } = NativeModules as {
@@ -69,7 +135,7 @@ export class SKAdNetworkBridge {
69
135
  }
70
136
 
71
137
  try {
72
- const success = await DatalyrSKAdNetwork.updatePostbackConversionValue(
138
+ const response = await DatalyrSKAdNetwork.updatePostbackConversionValue(
73
139
  result.fineValue,
74
140
  result.coarseValue,
75
141
  result.lockWindow
@@ -82,7 +148,7 @@ export class SKAdNetworkBridge {
82
148
  console.log(`[Datalyr] SKAN 3.0 fallback: conversionValue=${result.fineValue}`);
83
149
  }
84
150
 
85
- return success;
151
+ return response.success;
86
152
  } catch (error) {
87
153
  console.warn('[Datalyr] Failed to update SKAdNetwork postback conversion value:', error);
88
154
  return false;
@@ -116,4 +182,333 @@ export class SKAdNetworkBridge {
116
182
  static isAvailable(): boolean {
117
183
  return Platform.OS === 'ios' && !!DatalyrSKAdNetwork;
118
184
  }
185
+
186
+ /**
187
+ * Check if AdAttributionKit is available (iOS 17.4+)
188
+ * AdAttributionKit is Apple's replacement for SKAdNetwork with enhanced features
189
+ */
190
+ private static _isAdAttributionKitAvailable: boolean | null = null;
191
+
192
+ static async isAdAttributionKitAvailable(): Promise<boolean> {
193
+ if (Platform.OS !== 'ios') {
194
+ return false;
195
+ }
196
+
197
+ if (this._isAdAttributionKitAvailable !== null) {
198
+ return this._isAdAttributionKitAvailable;
199
+ }
200
+
201
+ if (!DatalyrSKAdNetwork?.isAdAttributionKitAvailable) {
202
+ return false;
203
+ }
204
+
205
+ try {
206
+ this._isAdAttributionKitAvailable = await DatalyrSKAdNetwork.isAdAttributionKitAvailable();
207
+ return this._isAdAttributionKitAvailable;
208
+ } catch {
209
+ return false;
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Register for ad network attribution
215
+ * Uses AdAttributionKit on iOS 17.4+, SKAdNetwork on earlier versions
216
+ */
217
+ static async registerForAttribution(): Promise<{ framework: string; registered: boolean } | null> {
218
+ if (Platform.OS !== 'ios') {
219
+ return null;
220
+ }
221
+
222
+ if (!DatalyrSKAdNetwork?.registerForAttribution) {
223
+ console.warn('[Datalyr] Attribution registration not available');
224
+ return null;
225
+ }
226
+
227
+ try {
228
+ const result = await DatalyrSKAdNetwork.registerForAttribution();
229
+ console.log(`[Datalyr] Registered for attribution: ${result.framework}`);
230
+ return result;
231
+ } catch (error) {
232
+ console.warn('[Datalyr] Failed to register for attribution:', error);
233
+ return null;
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Get attribution framework info
239
+ * Returns details about which framework is being used and its capabilities
240
+ */
241
+ static async getAttributionInfo(): Promise<AttributionFrameworkInfo | null> {
242
+ if (Platform.OS !== 'ios') {
243
+ return {
244
+ framework: 'none',
245
+ version: '0',
246
+ reengagement_available: false,
247
+ overlapping_windows: false,
248
+ fine_value_range: { min: 0, max: 0 },
249
+ coarse_values: [],
250
+ };
251
+ }
252
+
253
+ if (!DatalyrSKAdNetwork?.getAttributionInfo) {
254
+ return null;
255
+ }
256
+
257
+ try {
258
+ return await DatalyrSKAdNetwork.getAttributionInfo();
259
+ } catch (error) {
260
+ console.warn('[Datalyr] Failed to get attribution info:', error);
261
+ return null;
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Check if overlapping conversion windows are available (iOS 18.4+)
267
+ * Overlapping windows allow multiple conversion windows to be active simultaneously
268
+ */
269
+ private static _isOverlappingWindowsAvailable: boolean | null = null;
270
+
271
+ static async isOverlappingWindowsAvailable(): Promise<boolean> {
272
+ if (Platform.OS !== 'ios') {
273
+ return false;
274
+ }
275
+
276
+ if (this._isOverlappingWindowsAvailable !== null) {
277
+ return this._isOverlappingWindowsAvailable;
278
+ }
279
+
280
+ if (!DatalyrSKAdNetwork?.isOverlappingWindowsAvailable) {
281
+ return false;
282
+ }
283
+
284
+ try {
285
+ this._isOverlappingWindowsAvailable = await DatalyrSKAdNetwork.isOverlappingWindowsAvailable();
286
+ return this._isOverlappingWindowsAvailable;
287
+ } catch {
288
+ return false;
289
+ }
290
+ }
291
+
292
+ /**
293
+ * Update conversion value for re-engagement attribution (AdAttributionKit iOS 17.4+ only)
294
+ * Re-engagement tracks users who return to the app via an ad after initial install.
295
+ *
296
+ * @param result - Conversion result with fine value (0-63), coarse value, and lock window
297
+ * @returns Response with framework info, or null if not supported
298
+ */
299
+ static async updateReengagementConversionValue(
300
+ result: SKANConversionResult
301
+ ): Promise<PostbackUpdateResponse | null> {
302
+ if (Platform.OS !== 'ios') {
303
+ return null; // Android doesn't support AdAttributionKit
304
+ }
305
+
306
+ // Check if AdAttributionKit is available (required for re-engagement)
307
+ const isAAKAvailable = await this.isAdAttributionKitAvailable();
308
+ if (!isAAKAvailable) {
309
+ console.warn('[Datalyr] Re-engagement attribution requires iOS 17.4+ (AdAttributionKit)');
310
+ return null;
311
+ }
312
+
313
+ if (!DatalyrSKAdNetwork?.updateReengagementConversionValue) {
314
+ console.warn('[Datalyr] Re-engagement native module not available');
315
+ return null;
316
+ }
317
+
318
+ try {
319
+ const response = await DatalyrSKAdNetwork.updateReengagementConversionValue(
320
+ result.fineValue,
321
+ result.coarseValue,
322
+ result.lockWindow
323
+ );
324
+
325
+ console.log(`[Datalyr] AdAttributionKit re-engagement updated: fineValue=${result.fineValue}, coarseValue=${result.coarseValue}, lockWindow=${result.lockWindow}`);
326
+ return response;
327
+ } catch (error) {
328
+ console.warn('[Datalyr] Failed to update re-engagement conversion value:', error);
329
+ return null;
330
+ }
331
+ }
332
+
333
+ /**
334
+ * Get a summary of attribution capabilities for the current device
335
+ */
336
+ static async getCapabilitiesSummary(): Promise<{
337
+ skadnetwork3: boolean;
338
+ skadnetwork4: boolean;
339
+ adAttributionKit: boolean;
340
+ reengagement: boolean;
341
+ overlappingWindows: boolean;
342
+ geoPostback: boolean;
343
+ developmentPostbacks: boolean;
344
+ framework: string;
345
+ }> {
346
+ const info = await this.getAttributionInfo();
347
+ const isSKAN4 = await this.isSKAN4Available();
348
+ const isAAK = await this.isAdAttributionKitAvailable();
349
+ const isOverlapping = await this.isOverlappingWindowsAvailable();
350
+ const isGeo = await this.isGeoPostbackAvailable();
351
+
352
+ return {
353
+ skadnetwork3: Platform.OS === 'ios',
354
+ skadnetwork4: isSKAN4,
355
+ adAttributionKit: isAAK,
356
+ reengagement: info?.reengagement_available ?? false,
357
+ overlappingWindows: isOverlapping,
358
+ geoPostback: isGeo,
359
+ developmentPostbacks: isGeo, // Same iOS version requirement
360
+ framework: info?.framework ?? 'none',
361
+ };
362
+ }
363
+
364
+ // ===== iOS 18.4+ Features =====
365
+
366
+ /**
367
+ * Check if geo-level postback data is available (iOS 18.4+)
368
+ * Geo postbacks include country code information for regional analytics
369
+ */
370
+ private static _isGeoPostbackAvailable: boolean | null = null;
371
+
372
+ static async isGeoPostbackAvailable(): Promise<boolean> {
373
+ if (Platform.OS !== 'ios') {
374
+ return false;
375
+ }
376
+
377
+ if (this._isGeoPostbackAvailable !== null) {
378
+ return this._isGeoPostbackAvailable;
379
+ }
380
+
381
+ if (!DatalyrSKAdNetwork?.isGeoPostbackAvailable) {
382
+ return false;
383
+ }
384
+
385
+ try {
386
+ this._isGeoPostbackAvailable = await DatalyrSKAdNetwork.isGeoPostbackAvailable();
387
+ return this._isGeoPostbackAvailable;
388
+ } catch {
389
+ return false;
390
+ }
391
+ }
392
+
393
+ /**
394
+ * Set postback environment for testing (iOS 18.4+)
395
+ * Note: Actual sandbox mode requires Developer Mode enabled in iOS Settings
396
+ *
397
+ * @param environment - 'production' or 'sandbox'
398
+ */
399
+ static async setPostbackEnvironment(
400
+ environment: 'production' | 'sandbox'
401
+ ): Promise<PostbackEnvironmentResponse | null> {
402
+ if (Platform.OS !== 'ios') {
403
+ return null;
404
+ }
405
+
406
+ if (!DatalyrSKAdNetwork?.setPostbackEnvironment) {
407
+ console.warn('[Datalyr] Development postbacks require iOS 18.4+');
408
+ return null;
409
+ }
410
+
411
+ try {
412
+ const result = await DatalyrSKAdNetwork.setPostbackEnvironment(environment);
413
+ console.log(`[Datalyr] Postback environment: ${result.environment}`);
414
+ return result;
415
+ } catch (error) {
416
+ console.warn('[Datalyr] Failed to set postback environment:', error);
417
+ return null;
418
+ }
419
+ }
420
+
421
+ /**
422
+ * Get enhanced attribution info including iOS 18.4+ features
423
+ * Returns details about geo postbacks, development mode, and all available features
424
+ */
425
+ static async getEnhancedAttributionInfo(): Promise<EnhancedAttributionInfo | null> {
426
+ if (Platform.OS !== 'ios') {
427
+ return {
428
+ framework: 'none',
429
+ version: '0',
430
+ reengagement_available: false,
431
+ overlapping_windows: false,
432
+ geo_postback_available: false,
433
+ development_postbacks: false,
434
+ fine_value_range: { min: 0, max: 0 },
435
+ coarse_values: [],
436
+ features: [],
437
+ };
438
+ }
439
+
440
+ if (!DatalyrSKAdNetwork?.getEnhancedAttributionInfo) {
441
+ // Fallback to basic info if enhanced not available
442
+ const basicInfo = await this.getAttributionInfo();
443
+ if (basicInfo) {
444
+ return {
445
+ ...basicInfo,
446
+ geo_postback_available: false,
447
+ development_postbacks: false,
448
+ features: [],
449
+ };
450
+ }
451
+ return null;
452
+ }
453
+
454
+ try {
455
+ return await DatalyrSKAdNetwork.getEnhancedAttributionInfo();
456
+ } catch (error) {
457
+ console.warn('[Datalyr] Failed to get enhanced attribution info:', error);
458
+ return null;
459
+ }
460
+ }
461
+
462
+ /**
463
+ * Update postback with overlapping window support (iOS 18.4+)
464
+ * Allows tracking conversions across multiple time windows simultaneously
465
+ *
466
+ * @param result - Conversion result with fine value, coarse value, and lock window
467
+ * @param windowIndex - Window index: 0 (0-2 days), 1 (3-7 days), 2 (8-35 days)
468
+ */
469
+ static async updatePostbackWithWindow(
470
+ result: SKANConversionResult,
471
+ windowIndex: 0 | 1 | 2
472
+ ): Promise<OverlappingWindowPostbackResponse | null> {
473
+ if (Platform.OS !== 'ios') {
474
+ return null;
475
+ }
476
+
477
+ if (!DatalyrSKAdNetwork?.updatePostbackWithWindow) {
478
+ console.warn('[Datalyr] Overlapping windows require iOS 16.1+ (full support on iOS 18.4+)');
479
+ return null;
480
+ }
481
+
482
+ try {
483
+ const response = await DatalyrSKAdNetwork.updatePostbackWithWindow(
484
+ result.fineValue,
485
+ result.coarseValue,
486
+ result.lockWindow,
487
+ windowIndex
488
+ );
489
+
490
+ console.log(`[Datalyr] Postback updated for window ${windowIndex}: fineValue=${result.fineValue}, overlapping=${response.overlappingWindows}`);
491
+ return response;
492
+ } catch (error) {
493
+ console.warn('[Datalyr] Failed to update postback with window:', error);
494
+ return null;
495
+ }
496
+ }
497
+
498
+ /**
499
+ * Enable development/sandbox mode for testing attribution
500
+ * Convenience method that sets sandbox environment
501
+ */
502
+ static async enableDevelopmentMode(): Promise<boolean> {
503
+ const result = await this.setPostbackEnvironment('sandbox');
504
+ return result?.isSandbox ?? false;
505
+ }
506
+
507
+ /**
508
+ * Disable development mode (switch to production)
509
+ */
510
+ static async disableDevelopmentMode(): Promise<boolean> {
511
+ const result = await this.setPostbackEnvironment('production');
512
+ return result !== null && !result.isSandbox;
513
+ }
119
514
  }