@snowplow/react-native-tracker 1.0.0-beta.1 → 1.2.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.
package/dist/index.d.ts CHANGED
@@ -18,6 +18,10 @@ declare type Basis = 'consent' | 'contract' | 'legal_obligation' | 'legitimate_i
18
18
  * BufferOption
19
19
  */
20
20
  declare type BufferOption = 'single' | 'default' | 'large';
21
+ /**
22
+ * Trigger for MessageNotification event
23
+ */
24
+ declare type Trigger = 'push' | 'location' | 'calendar' | 'timeInterval' | 'other';
21
25
  /**
22
26
  * ScreenSize
23
27
  */
@@ -25,7 +29,7 @@ declare type ScreenSize = [number, number];
25
29
  /**
26
30
  * SelfDescribing type
27
31
  */
28
- declare type SelfDescribing = {
32
+ declare type SelfDescribing<T extends Record<keyof T, unknown> = Record<string, unknown>> = {
29
33
  /**
30
34
  * Schema
31
35
  */
@@ -33,7 +37,7 @@ declare type SelfDescribing = {
33
37
  /**
34
38
  * Data
35
39
  */
36
- data: Record<string, unknown>;
40
+ data: T;
37
41
  };
38
42
  /**
39
43
  * EventContext type
@@ -97,6 +101,11 @@ interface TrackerConfiguration {
97
101
  * @defaultValue true
98
102
  */
99
103
  sessionContext?: boolean;
104
+ /**
105
+ * Whether to attach a Deep Link entity to the first ScreenView tracked in the tracker after DeepLinkReceived event.
106
+ * @defaultValue true
107
+ */
108
+ deepLinkContext?: boolean;
100
109
  /**
101
110
  * Whether screen context is attached to tracked events.
102
111
  * @defaultValue true
@@ -430,6 +439,104 @@ declare type EcommerceTransactionProps = {
430
439
  country?: string;
431
440
  currency?: string;
432
441
  };
442
+ /**
443
+ * DeepLinkReceived event properties
444
+ * schema: iglu:com.snowplowanalytics.mobile/deep_link_received/jsonschema/1-0-0
445
+ */
446
+ declare type DeepLinkReceivedProps = {
447
+ /**
448
+ * URL in the received deep-link.
449
+ */
450
+ url: string;
451
+ /**
452
+ * Referrer URL, source of this deep-link.
453
+ */
454
+ referrer?: string;
455
+ };
456
+ /**
457
+ * Attachment object that identify an attachment in the MessageNotification.
458
+ */
459
+ declare type MessageNotificationAttachmentProps = {
460
+ identifier: string;
461
+ type: string;
462
+ url: string;
463
+ };
464
+ /**
465
+ * MessageNotification event properties
466
+ * schema: iglu:com.snowplowanalytics.mobile/message_notification/jsonschema/1-0-0
467
+ */
468
+ declare type MessageNotificationProps = {
469
+ /**
470
+ * The action associated with the notification.
471
+ */
472
+ action?: string;
473
+ attachments?: MessageNotificationAttachmentProps[];
474
+ /**
475
+ * The notification's body.
476
+ */
477
+ body: string;
478
+ bodyLocArgs?: string[];
479
+ /**
480
+ * The key to the body string in the app's string resources to use to localize the body text to the user's current localization.
481
+ */
482
+ bodyLocKey?: string;
483
+ /**
484
+ * The category associated to the notification.
485
+ */
486
+ category?: string;
487
+ /**
488
+ * The application is notified of the delivery of the notification if it's in the foreground or background, the app will be woken up (iOS only).
489
+ */
490
+ contentAvailable?: boolean;
491
+ /**
492
+ * The group which this notification is part of.
493
+ */
494
+ group?: string;
495
+ /**
496
+ * The icon associated to the notification (Android only).
497
+ */
498
+ icon?: string;
499
+ /**
500
+ * The number of items this notification represent.
501
+ */
502
+ notificationCount?: number;
503
+ /**
504
+ * The time when the event of the notification occurred.
505
+ */
506
+ notificationTimestamp?: string;
507
+ /**
508
+ * The sound played when the device receives the notification.
509
+ */
510
+ sound?: string;
511
+ /**
512
+ * The notification's subtitle. (iOS only)
513
+ */
514
+ subtitle?: string;
515
+ /**
516
+ * An identifier similar to 'group' but usable for different purposes (Android only).
517
+ */
518
+ tag?: string;
519
+ /**
520
+ * An identifier similar to 'group' but usable for different purposes (iOS only).
521
+ */
522
+ threadIdentifier?: string;
523
+ /**
524
+ * The notification's title.
525
+ */
526
+ title: string;
527
+ /**
528
+ * Variable string values to be used in place of the format specifiers in titleLocArgs to use to localize the title text to the user's current localization.
529
+ */
530
+ titleLocArgs?: string[];
531
+ /**
532
+ * The key to the title string in the app's string resources to use to localize the title text to the user's current localization.
533
+ */
534
+ titleLocKey?: string;
535
+ /**
536
+ * The trigger that raised the notification message. Must be one of: push, location, calendar, timeInterval, other
537
+ */
538
+ trigger: Trigger;
539
+ };
433
540
  /**
434
541
  * The ReactNativeTracker type
435
542
  */
@@ -439,8 +546,9 @@ declare type ReactNativeTracker = {
439
546
  *
440
547
  * @param argmap - The self-describing event properties
441
548
  * @param contexts - The array of event contexts
549
+ * @typeParam TData - The type of the data object within the SelfDescribing object
442
550
  */
443
- readonly trackSelfDescribingEvent: (argmap: SelfDescribing, contexts?: EventContext[]) => Promise<void>;
551
+ readonly trackSelfDescribingEvent: <TData extends Record<keyof TData, unknown> = Record<string, unknown>>(argmap: SelfDescribing<TData>, contexts?: EventContext[]) => Promise<void>;
444
552
  /**
445
553
  * Tracks a screen-view event
446
554
  *
@@ -490,6 +598,20 @@ declare type ReactNativeTracker = {
490
598
  * @param contexts - The array of event contexts
491
599
  */
492
600
  readonly trackEcommerceTransactionEvent: (argmap: EcommerceTransactionProps, contexts?: EventContext[]) => Promise<void>;
601
+ /**
602
+ * Tracks a deep link received event
603
+ *
604
+ * @param argmap - The deep link received event properties
605
+ * @param contexts - The array of event contexts
606
+ */
607
+ readonly trackDeepLinkReceivedEvent: (argmap: DeepLinkReceivedProps, contexts?: EventContext[]) => Promise<void>;
608
+ /**
609
+ * Tracks a message notification event
610
+ *
611
+ * @param argmap - The message notification event properties
612
+ * @param contexts - The array of event contexts
613
+ */
614
+ readonly trackMessageNotificationEvent: (argmap: MessageNotificationProps, contexts?: EventContext[]) => Promise<void>;
493
615
  /**
494
616
  * Removes global contexts
495
617
  *
@@ -629,4 +751,4 @@ declare function removeTracker(trackerNamespace: string): Promise<boolean>;
629
751
  */
630
752
  declare function removeAllTrackers(): Promise<boolean>;
631
753
 
632
- export { Basis, BufferOption, ConsentDocument, ConsentGrantedProps, ConsentWithdrawnProps, DevicePlatform, EcommerceItem, EcommerceTransactionProps, EmitterConfiguration, EventContext, GCConfiguration, GdprConfiguration, GlobalContext, HttpMethod, LogLevel, NetworkConfiguration, PageViewProps, ReactNativeTracker, ScreenSize, ScreenViewProps, SelfDescribing, SessionConfiguration, StructuredProps, SubjectConfiguration, TimingProps, TrackerConfiguration, TrackerControllerConfiguration, createTracker, removeAllTrackers, removeTracker };
754
+ export { Basis, BufferOption, ConsentDocument, ConsentGrantedProps, ConsentWithdrawnProps, DeepLinkReceivedProps, DevicePlatform, EcommerceItem, EcommerceTransactionProps, EmitterConfiguration, EventContext, GCConfiguration, GdprConfiguration, GlobalContext, HttpMethod, LogLevel, MessageNotificationProps, NetworkConfiguration, PageViewProps, ReactNativeTracker, ScreenSize, ScreenViewProps, SelfDescribing, SessionConfiguration, StructuredProps, SubjectConfiguration, TimingProps, TrackerConfiguration, TrackerControllerConfiguration, Trigger, createTracker, removeAllTrackers, removeTracker };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NativeModules } from 'react-native';
2
2
 
3
3
  /*
4
- * Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
4
+ * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
5
5
  *
6
6
  * This program is licensed to you under the Apache License Version 2.0,
7
7
  * and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -15,7 +15,7 @@ import { NativeModules } from 'react-native';
15
15
  const { RNSnowplowTracker } = NativeModules;
16
16
 
17
17
  /*
18
- * Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
18
+ * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
19
19
  *
20
20
  * This program is licensed to you under the Apache License Version 2.0,
21
21
  * and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -81,7 +81,7 @@ function isObject(x) {
81
81
  }
82
82
 
83
83
  /*
84
- * Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
84
+ * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
85
85
  *
86
86
  * This program is licensed to you under the Apache License Version 2.0,
87
87
  * and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -114,6 +114,8 @@ const logMessages = {
114
114
  consentGReq: 'consentGranted event requires expiry, documentId and version parameters to be set',
115
115
  consentWReq: 'consentWithdrawn event requires all, documentId and version parameters to be set',
116
116
  ecomReq: 'ecommerceTransaction event requires orderId, totalValue to be set and items to be an array of valid ecommerceItems',
117
+ deepLinkReq: 'deepLinkReceived event requires the url parameter to be set',
118
+ messageNotificationReq: 'messageNotification event requires title, body, and trigger parameters to be set',
117
119
  // global contexts errors
118
120
  gcTagType: 'tag argument is required to be a string',
119
121
  gcType: 'global context argument is invalid',
@@ -129,6 +131,8 @@ const logMessages = {
129
131
  trackConsentGranted: 'trackConsentGranted:',
130
132
  trackConsentWithdrawn: 'trackConsentWithdrawn:',
131
133
  trackEcommerceTransaction: 'trackEcommerceTransaction:',
134
+ trackDeepLinkReceived: 'trackDeepLinkReceivedEvent:',
135
+ trackMessageNotification: 'trackMessageNotificationEvent:',
132
136
  removeGlobalContexts: 'removeGlobalContexts:',
133
137
  addGlobalContexts: 'addGlobalContexts:',
134
138
  // setters
@@ -146,7 +150,7 @@ const logMessages = {
146
150
  };
147
151
 
148
152
  /*
149
- * Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
153
+ * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
150
154
  *
151
155
  * This program is licensed to you under the Apache License Version 2.0,
152
156
  * and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -305,6 +309,43 @@ function validateConsentWithdrawn(argmap) {
305
309
  }
306
310
  return Promise.resolve(true);
307
311
  }
312
+ /**
313
+ * Validates a deep link received event
314
+ *
315
+ * @param argmap {Object} - the object to validate
316
+ * @returns - boolean promise
317
+ */
318
+ function validateDeepLinkReceived(argmap) {
319
+ // validate type
320
+ if (!isObject(argmap)) {
321
+ return Promise.reject(new Error(logMessages.evType));
322
+ }
323
+ // validate required props
324
+ if (typeof argmap.url !== 'string') {
325
+ return Promise.reject(new Error(logMessages.deepLinkReq));
326
+ }
327
+ return Promise.resolve(true);
328
+ }
329
+ /**
330
+ * Validates a message notification event
331
+ *
332
+ * @param argmap {Object} - the object to validate
333
+ * @returns - boolean promise
334
+ */
335
+ function validateMessageNotification(argmap) {
336
+ // validate type
337
+ if (!isObject(argmap)) {
338
+ return Promise.reject(new Error(logMessages.evType));
339
+ }
340
+ // validate required props
341
+ if (typeof argmap.title !== 'string'
342
+ || typeof argmap.body !== 'string'
343
+ || typeof argmap.trigger !== 'string'
344
+ || !['push', 'location', 'calendar', 'timeInterval', 'other'].includes(argmap.trigger)) {
345
+ return Promise.reject(new Error(logMessages.messageNotificationReq));
346
+ }
347
+ return Promise.resolve(true);
348
+ }
308
349
  /**
309
350
  * Validates whether an object is valid ecommerce-item
310
351
  *
@@ -353,7 +394,7 @@ function validateEcommerceTransaction(argmap) {
353
394
  }
354
395
 
355
396
  /*
356
- * Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
397
+ * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
357
398
  *
358
399
  * This program is licensed to you under the Apache License Version 2.0,
359
400
  * and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -377,6 +418,7 @@ const trackerProps = [
377
418
  'platformContext',
378
419
  'geoLocationContext',
379
420
  'sessionContext',
421
+ 'deepLinkContext',
380
422
  'screenContext',
381
423
  'screenViewAutotracking',
382
424
  'lifecycleAutotracking',
@@ -599,7 +641,7 @@ function initValidate(init) {
599
641
  }
600
642
 
601
643
  /*
602
- * Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
644
+ * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
603
645
  *
604
646
  * This program is licensed to you under the Apache License Version 2.0,
605
647
  * and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -770,9 +812,49 @@ function trackEcommerceTransactionEvent$1(namespace, argmap, contexts = []) {
770
812
  throw new Error(`${logMessages.trackEcommerceTransaction} ${error.message}`);
771
813
  });
772
814
  }
815
+ /**
816
+ * Tracks a deep link received event
817
+ *
818
+ * @param namespace {string} - the tracker namespace
819
+ * @param argmap {Object} - the event data
820
+ * @param contexts {Array}- the event contexts
821
+ * @returns {Promise}
822
+ */
823
+ function trackDeepLinkReceivedEvent$1(namespace, argmap, contexts = []) {
824
+ return validateDeepLinkReceived(argmap)
825
+ .then(() => validateContexts(contexts))
826
+ .then(() => RNSnowplowTracker.trackDeepLinkReceivedEvent({
827
+ tracker: namespace,
828
+ eventData: argmap,
829
+ contexts: contexts
830
+ }))
831
+ .catch((error) => {
832
+ throw new Error(`${logMessages.trackDeepLinkReceived} ${error.message}`);
833
+ });
834
+ }
835
+ /**
836
+ * Tracks a message notification event
837
+ *
838
+ * @param namespace {string} - the tracker namespace
839
+ * @param argmap {Object} - the event data
840
+ * @param contexts {Array}- the event contexts
841
+ * @returns {Promise}
842
+ */
843
+ function trackMessageNotificationEvent$1(namespace, argmap, contexts = []) {
844
+ return validateMessageNotification(argmap)
845
+ .then(() => validateContexts(contexts))
846
+ .then(() => RNSnowplowTracker.trackMessageNotificationEvent({
847
+ tracker: namespace,
848
+ eventData: argmap,
849
+ contexts: contexts
850
+ }))
851
+ .catch((error) => {
852
+ throw new Error(`${logMessages.trackMessageNotification} ${error.message}`);
853
+ });
854
+ }
773
855
 
774
856
  /*
775
- * Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
857
+ * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
776
858
  *
777
859
  * This program is licensed to you under the Apache License Version 2.0,
778
860
  * and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -995,7 +1077,7 @@ function setSubjectData$1(namespace, config) {
995
1077
  }
996
1078
 
997
1079
  /*
998
- * Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
1080
+ * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
999
1081
  *
1000
1082
  * This program is licensed to you under the Apache License Version 2.0,
1001
1083
  * and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -1127,6 +1209,28 @@ function trackEcommerceTransactionEvent(namespace) {
1127
1209
  return trackEcommerceTransactionEvent$1(namespace, argmap, contexts);
1128
1210
  };
1129
1211
  }
1212
+ /**
1213
+ * Returns a function to track an DeepLinkReceived event by a tracker
1214
+ *
1215
+ * @param namespace {string} - The tracker namespace
1216
+ * @returns - A function to track an DeepLinkReceived event
1217
+ */
1218
+ function trackDeepLinkReceivedEvent(namespace) {
1219
+ return function (argmap, contexts = []) {
1220
+ return trackDeepLinkReceivedEvent$1(namespace, argmap, contexts);
1221
+ };
1222
+ }
1223
+ /**
1224
+ * Returns a function to track an MessageNotification event by a tracker
1225
+ *
1226
+ * @param namespace {string} - The tracker namespace
1227
+ * @returns - A function to track an MessageNotification event
1228
+ */
1229
+ function trackMessageNotificationEvent(namespace) {
1230
+ return function (argmap, contexts = []) {
1231
+ return trackMessageNotificationEvent$1(namespace, argmap, contexts);
1232
+ };
1233
+ }
1130
1234
  /**
1131
1235
  * Returns a function to remove global contexts by a tracker
1132
1236
  *
@@ -1350,7 +1454,7 @@ function getForegroundIndex(namespace) {
1350
1454
  }
1351
1455
 
1352
1456
  /*
1353
- * Copyright (c) 2020-2021 Snowplow Analytics Ltd. All rights reserved.
1457
+ * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
1354
1458
  *
1355
1459
  * This program is licensed to you under the Apache License Version 2.0,
1356
1460
  * and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -1389,6 +1493,8 @@ function createTracker(namespace, networkConfig, controllerConfig = {}) {
1389
1493
  const trackConsentGrantedEvent$1 = mkMethod(trackConsentGrantedEvent(namespace));
1390
1494
  const trackConsentWithdrawnEvent$1 = mkMethod(trackConsentWithdrawnEvent(namespace));
1391
1495
  const trackEcommerceTransactionEvent$1 = mkMethod(trackEcommerceTransactionEvent(namespace));
1496
+ const trackDeepLinkReceivedEvent$1 = mkMethod(trackDeepLinkReceivedEvent(namespace));
1497
+ const trackMessageNotificationEvent$1 = mkMethod(trackMessageNotificationEvent(namespace));
1392
1498
  // Global Contexts
1393
1499
  const removeGlobalContexts$1 = mkMethod(removeGlobalContexts(namespace));
1394
1500
  const addGlobalContexts$1 = mkMethod(addGlobalContexts(namespace));
@@ -1420,6 +1526,8 @@ function createTracker(namespace, networkConfig, controllerConfig = {}) {
1420
1526
  trackConsentGrantedEvent: trackConsentGrantedEvent$1,
1421
1527
  trackConsentWithdrawnEvent: trackConsentWithdrawnEvent$1,
1422
1528
  trackEcommerceTransactionEvent: trackEcommerceTransactionEvent$1,
1529
+ trackDeepLinkReceivedEvent: trackDeepLinkReceivedEvent$1,
1530
+ trackMessageNotificationEvent: trackMessageNotificationEvent$1,
1423
1531
  removeGlobalContexts: removeGlobalContexts$1,
1424
1532
  addGlobalContexts: addGlobalContexts$1,
1425
1533
  setUserId: setUserId$1,