@snowplow/react-native-tracker 2.0.0 → 2.1.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 (111) hide show
  1. package/.github/workflows/build.yml +10 -5
  2. package/.github/workflows/deploy.yml +9 -10
  3. package/.github/workflows/e2e-android.yml +1 -1
  4. package/.github/workflows/e2e-ios.yml +5 -0
  5. package/.github/workflows/snyk.yml +1 -1
  6. package/CHANGELOG +10 -0
  7. package/CONTRIBUTING.md +2 -2
  8. package/LICENSE +1 -1
  9. package/README.md +1 -1
  10. package/android/build.gradle +1 -1
  11. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt +50 -10
  12. package/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt +5 -2
  13. package/android/src/main/java/com/snowplow/reactnativetracker/util/EventUtil.kt +20 -0
  14. package/android/src/main/java/com/snowplow/reactnativetracker/util/TrackerVersion.kt +1 -1
  15. package/example/Gemfile +1 -1
  16. package/example/e2e/emitEvents.e2e.detox.js +0 -13
  17. package/example/e2e/helpers/microCommands.js +0 -13
  18. package/example/e2e/helpers/microHelpers.js +0 -13
  19. package/example/e2e/helpers/microHelpers.test.js +0 -13
  20. package/example/e2e/helpers/schemas.js +0 -13
  21. package/example/e2e/testEvents.micro.test.js +1 -14
  22. package/example/ios/Podfile +0 -2
  23. package/example/ios/Podfile.lock +7 -14
  24. package/example/src/App.js +9 -0
  25. package/ios/ReactNativeTracker.mm +10 -0
  26. package/ios/ReactNativeTracker.swift +71 -6
  27. package/ios/Util/ConfigUtils.swift +5 -2
  28. package/ios/Util/TrackerVersion.swift +1 -1
  29. package/lib/commonjs/api.js +28 -13
  30. package/lib/commonjs/api.js.map +1 -1
  31. package/lib/commonjs/configurations.js +1 -14
  32. package/lib/commonjs/configurations.js.map +1 -1
  33. package/lib/commonjs/constants.js +6 -14
  34. package/lib/commonjs/constants.js.map +1 -1
  35. package/lib/commonjs/events.js +34 -13
  36. package/lib/commonjs/events.js.map +1 -1
  37. package/lib/commonjs/index.js +4 -13
  38. package/lib/commonjs/index.js.map +1 -1
  39. package/lib/commonjs/jsCore.js +49 -15
  40. package/lib/commonjs/jsCore.js.map +1 -1
  41. package/lib/commonjs/native.js +0 -13
  42. package/lib/commonjs/native.js.map +1 -1
  43. package/lib/commonjs/subject.js +0 -13
  44. package/lib/commonjs/subject.js.map +1 -1
  45. package/lib/commonjs/tracker.js +40 -13
  46. package/lib/commonjs/tracker.js.map +1 -1
  47. package/lib/commonjs/utils.js +0 -13
  48. package/lib/commonjs/utils.js.map +1 -1
  49. package/lib/commonjs/webViewInterface.js +0 -13
  50. package/lib/commonjs/webViewInterface.js.map +1 -1
  51. package/lib/module/api.js +27 -14
  52. package/lib/module/api.js.map +1 -1
  53. package/lib/module/configurations.js +1 -14
  54. package/lib/module/configurations.js.map +1 -1
  55. package/lib/module/constants.js +6 -14
  56. package/lib/module/constants.js.map +1 -1
  57. package/lib/module/events.js +33 -14
  58. package/lib/module/events.js.map +1 -1
  59. package/lib/module/index.js +4 -13
  60. package/lib/module/index.js.map +1 -1
  61. package/lib/module/jsCore.js +49 -15
  62. package/lib/module/jsCore.js.map +1 -1
  63. package/lib/module/native.js +0 -13
  64. package/lib/module/native.js.map +1 -1
  65. package/lib/module/subject.js +0 -13
  66. package/lib/module/subject.js.map +1 -1
  67. package/lib/module/tracker.js +40 -15
  68. package/lib/module/tracker.js.map +1 -1
  69. package/lib/module/utils.js +0 -13
  70. package/lib/module/utils.js.map +1 -1
  71. package/lib/module/webViewInterface.js +0 -13
  72. package/lib/module/webViewInterface.js.map +1 -1
  73. package/lib/typescript/api.d.ts +16 -2
  74. package/lib/typescript/api.d.ts.map +1 -1
  75. package/lib/typescript/configurations.d.ts.map +1 -1
  76. package/lib/typescript/constants.d.ts +5 -0
  77. package/lib/typescript/constants.d.ts.map +1 -1
  78. package/lib/typescript/events.d.ts +16 -2
  79. package/lib/typescript/events.d.ts.map +1 -1
  80. package/lib/typescript/index.d.ts.map +1 -1
  81. package/lib/typescript/jsCore.d.ts +13 -1
  82. package/lib/typescript/jsCore.d.ts.map +1 -1
  83. package/lib/typescript/native.d.ts.map +1 -1
  84. package/lib/typescript/subject.d.ts.map +1 -1
  85. package/lib/typescript/tracker.d.ts +20 -2
  86. package/lib/typescript/tracker.d.ts.map +1 -1
  87. package/lib/typescript/types.d.ts +83 -5
  88. package/lib/typescript/types.d.ts.map +1 -1
  89. package/lib/typescript/utils.d.ts.map +1 -1
  90. package/lib/typescript/webViewInterface.d.ts.map +1 -1
  91. package/package.json +3 -3
  92. package/snowplow-react-native-tracker.podspec +1 -1
  93. package/src/__tests__/api.test.ts +0 -13
  94. package/src/__tests__/configurations.test.ts +3 -15
  95. package/src/__tests__/events.test.ts +0 -13
  96. package/src/__tests__/index.test.ts +0 -13
  97. package/src/__tests__/jsCore.test.ts +43 -13
  98. package/src/__tests__/utils.test.ts +0 -13
  99. package/src/api.ts +34 -13
  100. package/src/configurations.ts +1 -13
  101. package/src/constants.ts +8 -13
  102. package/src/events.ts +38 -13
  103. package/src/index.ts +8 -13
  104. package/src/jsCore.ts +65 -15
  105. package/src/native.ts +0 -13
  106. package/src/subject.ts +0 -13
  107. package/src/tracker.ts +60 -13
  108. package/src/types.ts +93 -18
  109. package/src/utils.ts +0 -13
  110. package/src/webViewInterface.ts +0 -13
  111. package/yarn.lock +4 -4
package/src/tracker.ts CHANGED
@@ -1,16 +1,3 @@
1
- /*
2
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
3
- *
4
- * This program is licensed to you under the Apache License Version 2.0,
5
- * and you may not use this file except in compliance with the Apache License Version 2.0.
6
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
- *
8
- * Unless required by applicable law or agreed to in writing,
9
- * software distributed under the Apache License Version 2.0 is distributed on an
10
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12
- */
13
-
14
1
  'use strict';
15
2
 
16
3
  import { RNSnowplowTracker } from './native';
@@ -19,6 +6,8 @@ import {
19
6
  validateContexts,
20
7
  validateSelfDesc,
21
8
  validateScreenView,
9
+ validateScrollChanged,
10
+ validateListItemView,
22
11
  validateStructured,
23
12
  validatePageView,
24
13
  validateTiming,
@@ -40,6 +29,8 @@ import type {
40
29
  EcommerceTransactionProps,
41
30
  DeepLinkReceivedProps,
42
31
  MessageNotificationProps,
32
+ ScrollChangedProps,
33
+ ListItemViewProps,
43
34
  } from './types';
44
35
 
45
36
  /**
@@ -96,6 +87,60 @@ function trackScreenViewEvent(
96
87
  });
97
88
  }
98
89
 
90
+ /**
91
+ * Tracks a scroll-changed event
92
+ *
93
+ * @param namespace {string} - the tracker namespace
94
+ * @param argmap {Object} - the event data
95
+ * @param contexts {Array}- the event contexts
96
+ * @returns {Promise}
97
+ */
98
+ function trackScrollChangedEvent(
99
+ namespace: string | null,
100
+ argmap: ScrollChangedProps,
101
+ contexts: EventContext[] = []
102
+ ): Promise<void> {
103
+ return <Promise<void>>validateScrollChanged(argmap)
104
+ .then(() => validateContexts(contexts))
105
+ .then(
106
+ () => <Promise<void>>RNSnowplowTracker.trackScrollChangedEvent({
107
+ tracker: namespace,
108
+ eventData: argmap,
109
+ contexts: contexts,
110
+ })
111
+ )
112
+ .catch((error) => {
113
+ throw new Error(`${logMessages.trackScrollChanged} ${error.message}`);
114
+ });
115
+ }
116
+
117
+ /**
118
+ * Tracks a list item view event
119
+ *
120
+ * @param namespace {string} - the tracker namespace
121
+ * @param argmap {Object} - the event data
122
+ * @param contexts {Array}- the event contexts
123
+ * @returns {Promise}
124
+ */
125
+ function trackListItemViewEvent(
126
+ namespace: string | null,
127
+ argmap: ListItemViewProps,
128
+ contexts: EventContext[] = []
129
+ ): Promise<void> {
130
+ return <Promise<void>>validateListItemView(argmap)
131
+ .then(() => validateContexts(contexts))
132
+ .then(
133
+ () => <Promise<void>>RNSnowplowTracker.trackListItemViewEvent({
134
+ tracker: namespace,
135
+ eventData: argmap,
136
+ contexts: contexts,
137
+ })
138
+ )
139
+ .catch((error) => {
140
+ throw new Error(`${logMessages.trackListItemView} ${error.message}`);
141
+ });
142
+ }
143
+
99
144
  /**
100
145
  * Tracks a structured event
101
146
  *
@@ -319,6 +364,8 @@ function trackMessageNotificationEvent(
319
364
  export {
320
365
  trackSelfDescribingEvent,
321
366
  trackScreenViewEvent,
367
+ trackScrollChangedEvent,
368
+ trackListItemViewEvent,
322
369
  trackStructuredEvent,
323
370
  trackPageViewEvent,
324
371
  trackTimingEvent,
package/src/types.ts CHANGED
@@ -1,16 +1,3 @@
1
- /*
2
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
3
- *
4
- * This program is licensed to you under the Apache License Version 2.0,
5
- * and you may not use this file except in compliance with the Apache License Version 2.0.
6
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
- *
8
- * Unless required by applicable law or agreed to in writing,
9
- * software distributed under the Apache License Version 2.0 is distributed on an
10
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12
- */
13
-
14
1
  /**
15
2
  * HttpMethod type
16
3
  */
@@ -48,7 +35,7 @@ export type Basis =
48
35
  /**
49
36
  * BufferOption
50
37
  */
51
- export type BufferOption = 'single' | 'default' | 'large';
38
+ export type BufferOption = 'single' | 'small' | 'large';
52
39
 
53
40
  /**
54
41
  * Trigger for MessageNotification event
@@ -69,7 +56,7 @@ export type ScreenSize = [number, number];
69
56
  * SelfDescribing type
70
57
  */
71
58
  export type SelfDescribing<
72
- T extends Record<keyof T, unknown> = Record<string, unknown>
59
+ T extends Record<string, unknown> = Record<string, unknown>
73
60
  > = {
74
61
  /**
75
62
  * Schema
@@ -176,9 +163,15 @@ export interface TrackerConfiguration {
176
163
  * @defaultValue false
177
164
  */
178
165
  screenViewAutotracking?: boolean;
166
+ /**
167
+ * Whether to enable tracking of the screen end event and the screen summary context entity.
168
+ * Make sure that you have lifecycle autotracking enabled for screen summary to have complete information.
169
+ * @defaultValue true
170
+ */
171
+ screenEngagementAutotracking?: boolean;
179
172
  /**
180
173
  * Whether enable automatic tracking of background and foreground transitions.
181
- * @defaultValue false
174
+ * @defaultValue true
182
175
  */
183
176
  lifecycleAutotracking?: boolean;
184
177
  /**
@@ -404,6 +397,56 @@ export type ScreenViewProps = {
404
397
  transitionType?: string;
405
398
  };
406
399
 
400
+ /**
401
+ * Event tracked when a scroll view's scroll position changes.
402
+ * If screen engagement tracking is enabled, the scroll changed events will be aggregated into a `screen_summary` entity.
403
+ *
404
+ * Schema: `iglu:com.snowplowanalytics.mobile/scroll_changed/jsonschema/1-0-0`
405
+ */
406
+ export type ScrollChangedProps = {
407
+ /**
408
+ * Vertical scroll offset in pixels
409
+ */
410
+ yOffset?: number;
411
+ /**
412
+ * Horizontal scroll offset in pixels.
413
+ */
414
+ xOffset?: number;
415
+ /**
416
+ * The height of the scroll view in pixels
417
+ */
418
+ viewHeight?: number;
419
+ /**
420
+ * The width of the scroll view in pixels
421
+ */
422
+ viewWidth?: number;
423
+ /**
424
+ * The height of the content in the scroll view in pixels
425
+ */
426
+ contentHeight?: number;
427
+ /**
428
+ * The width of the content in the scroll view in pixels
429
+ */
430
+ contentWidth?: number;
431
+ };
432
+
433
+ /**
434
+ * Event tracking the view of an item in a list.
435
+ * If screen engagement tracking is enabled, the list item view events will be aggregated into a `screen_summary` entity.
436
+ *
437
+ * Schema: `iglu:com.snowplowanalytics.mobile/list_item_view/jsonschema/1-0-0`
438
+ */
439
+ export type ListItemViewProps = {
440
+ /**
441
+ * Index of the item in the list
442
+ */
443
+ index: number;
444
+ /**
445
+ * Total number of items in the list
446
+ */
447
+ itemsCount?: number;
448
+ };
449
+
407
450
  /**
408
451
  * Structured event properties
409
452
  */
@@ -700,14 +743,14 @@ export type MessageNotificationProps = {
700
743
  */
701
744
  export type ReactNativeTracker = {
702
745
  /**
703
- * Tracks a self-descibing event
746
+ * Tracks a self-describing event
704
747
  *
705
748
  * @param argmap - The self-describing event properties
706
749
  * @param contexts - The array of event contexts
707
750
  * @typeParam TData - The type of the data object within the SelfDescribing object
708
751
  */
709
752
  readonly trackSelfDescribingEvent: <
710
- TData extends Record<keyof TData, unknown> = Record<string, unknown>
753
+ TData extends Record<string, unknown> = Record<string, unknown>
711
754
  >(
712
755
  argmap: SelfDescribing<TData>,
713
756
  contexts?: EventContext[]
@@ -724,6 +767,28 @@ export type ReactNativeTracker = {
724
767
  contexts?: EventContext[]
725
768
  ) => Promise<void>;
726
769
 
770
+ /**
771
+ * Tracks a scroll changed event
772
+ *
773
+ * @param argmap - The scroll changed event's properties
774
+ * @param contexts - The array of event contexts
775
+ */
776
+ readonly trackScrollChangedEvent: (
777
+ argmap: ScrollChangedProps,
778
+ contexts?: EventContext[]
779
+ ) => Promise<void>;
780
+
781
+ /**
782
+ * Tracks a list item view event
783
+ *
784
+ * @param argmap - The list item view event's properties
785
+ * @param contexts - The array of event contexts
786
+ */
787
+ readonly trackListItemViewEvent: (
788
+ argmap: ListItemViewProps,
789
+ contexts?: EventContext[]
790
+ ) => Promise<void>;
791
+
727
792
  /**
728
793
  * Tracks a structured event
729
794
  *
@@ -995,6 +1060,16 @@ export interface Native {
995
1060
  eventData: ScreenViewProps;
996
1061
  contexts: EventContext[];
997
1062
  }) => Promise<void>;
1063
+ trackScrollChangedEvent: (details: {
1064
+ tracker: string | null;
1065
+ eventData: ScrollChangedProps;
1066
+ contexts: EventContext[];
1067
+ }) => Promise<void>;
1068
+ trackListItemViewEvent: (details: {
1069
+ tracker: string | null;
1070
+ eventData: ListItemViewProps;
1071
+ contexts: EventContext[];
1072
+ }) => Promise<void>;
998
1073
  trackPageViewEvent: (details: {
999
1074
  tracker: string | null;
1000
1075
  eventData: PageViewProps;
package/src/utils.ts CHANGED
@@ -1,16 +1,3 @@
1
- /*
2
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
3
- *
4
- * This program is licensed to you under the Apache License Version 2.0,
5
- * and you may not use this file except in compliance with the Apache License Version 2.0.
6
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
- *
8
- * Unless required by applicable law or agreed to in writing,
9
- * software distributed under the Apache License Version 2.0 is distributed on an
10
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12
- */
13
-
14
1
  'use strict';
15
2
 
16
3
  /**
@@ -1,16 +1,3 @@
1
- /*
2
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
3
- *
4
- * This program is licensed to you under the Apache License Version 2.0,
5
- * and you may not use this file except in compliance with the Apache License Version 2.0.
6
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
- *
8
- * Unless required by applicable law or agreed to in writing,
9
- * software distributed under the Apache License Version 2.0 is distributed on an
10
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12
- */
13
-
14
1
  'use strict';
15
2
 
16
3
  import {
package/yarn.lock CHANGED
@@ -2036,10 +2036,10 @@
2036
2036
  dependencies:
2037
2037
  "@sinonjs/commons" "^1.7.0"
2038
2038
 
2039
- "@snowplow/tracker-core@3.8.0":
2040
- version "3.8.0"
2041
- resolved "https://registry.yarnpkg.com/@snowplow/tracker-core/-/tracker-core-3.8.0.tgz#bedcd84cdede8df4b8275f6031d57342e0d87769"
2042
- integrity sha512-fBQhHetV5c5s+Ea5bqaWrAcwG7C7Fdo0ztHKxvoVECwxMocWuTuiau0oM+dzkcjNyMoCa7bvX8BUNySvwwSrZA==
2039
+ "@snowplow/tracker-core@3.21.0":
2040
+ version "3.21.0"
2041
+ resolved "https://registry.yarnpkg.com/@snowplow/tracker-core/-/tracker-core-3.21.0.tgz#c1241ff06d59550e4a97aeb12a023d22baa3a316"
2042
+ integrity sha512-zNxEZgibTofk29vklbasPv0GP2R7URPyhB+Vd3q5d5gPPTwjZXQ6X/EDHHCK9YFC9u0I+NAcgDm7GEGMm6ib4A==
2043
2043
  dependencies:
2044
2044
  tslib "^2.3.1"
2045
2045
  uuid "^3.4.0"