@snowplow/react-native-tracker 1.4.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 (240) hide show
  1. package/.editorconfig +15 -0
  2. package/.eslintignore +6 -0
  3. package/.gitattributes +3 -0
  4. package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  5. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. package/.github/actions/setup/action.yml +28 -0
  7. package/.github/workflows/build.yml +155 -0
  8. package/.github/workflows/deploy.yml +97 -0
  9. package/.github/workflows/e2e-android.yml +121 -0
  10. package/.github/workflows/e2e-ios.yml +95 -0
  11. package/.github/workflows/snyk.yml +21 -0
  12. package/.gitignore +70 -0
  13. package/.npmignore +60 -0
  14. package/.nvmrc +1 -0
  15. package/.watchmanconfig +1 -0
  16. package/.yarnrc +3 -0
  17. package/CHANGELOG +176 -0
  18. package/CONTRIBUTING.md +80 -0
  19. package/LICENSE +1 -1
  20. package/README.md +24 -111
  21. package/android/build.gradle +93 -37
  22. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  23. package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
  24. package/android/gradle.properties +5 -2
  25. package/android/gradlew +172 -110
  26. package/android/gradlew.bat +24 -19
  27. package/android/src/main/AndroidManifest.xml +1 -3
  28. package/android/src/main/AndroidManifestNew.xml +2 -0
  29. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt +744 -0
  30. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerPackage.kt +17 -0
  31. package/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt +274 -0
  32. package/android/src/main/java/com/snowplow/reactnativetracker/util/EventUtil.kt +233 -0
  33. package/android/src/main/java/com/snowplow/reactnativetracker/util/TrackerVersion.kt +5 -0
  34. package/babel.config.js +3 -0
  35. package/example/.watchmanconfig +1 -0
  36. package/example/Gemfile +6 -0
  37. package/example/android/app/build.gradle +129 -0
  38. package/example/android/app/debug.keystore +0 -0
  39. package/example/android/app/proguard-rules.pro +10 -0
  40. package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTest.java +36 -0
  41. package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTestAppJUnitRunner.java +21 -0
  42. package/example/android/app/src/debug/AndroidManifest.xml +13 -0
  43. package/example/android/app/src/debug/java/com/reactnativetrackerexample/ReactNativeFlipper.java +75 -0
  44. package/example/android/app/src/main/AndroidManifest.xml +26 -0
  45. package/example/android/app/src/main/java/com/reactnativetrackerexample/MainActivity.java +32 -0
  46. package/example/android/app/src/main/java/com/reactnativetrackerexample/MainApplication.java +62 -0
  47. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
  48. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  49. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  50. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  51. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  52. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  53. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  54. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  55. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  56. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  57. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  58. package/example/android/app/src/main/res/values/strings.xml +3 -0
  59. package/example/android/app/src/main/res/values/styles.xml +9 -0
  60. package/example/android/app/src/release/java/com/reactnativetrackerexample/ReactNativeFlipper.java +20 -0
  61. package/example/android/build.gradle +31 -0
  62. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  63. package/example/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  64. package/example/android/gradle.properties +44 -0
  65. package/example/android/gradlew +244 -0
  66. package/example/android/gradlew.bat +92 -0
  67. package/example/android/settings.gradle +4 -0
  68. package/example/app.json +4 -0
  69. package/example/babel.config.js +17 -0
  70. package/example/detox.config.js +92 -0
  71. package/example/e2e/config.json +10 -0
  72. package/example/e2e/emitEvents.e2e.detox.js +95 -0
  73. package/example/e2e/environment.js +23 -0
  74. package/example/e2e/helpers/microCommands.js +140 -0
  75. package/example/e2e/helpers/microHelpers.js +333 -0
  76. package/example/e2e/helpers/microHelpers.test.js +295 -0
  77. package/example/e2e/helpers/schemas.js +49 -0
  78. package/example/e2e/jest.config.js +16 -0
  79. package/example/e2e/setup.js +4 -0
  80. package/example/e2e/testEvents.micro.test.js +287 -0
  81. package/example/index.js +5 -0
  82. package/example/ios/.xcode.env +11 -0
  83. package/example/ios/Podfile +62 -0
  84. package/example/ios/Podfile.lock +730 -0
  85. package/example/ios/ReactNativeTrackerExample/AppDelegate.h +6 -0
  86. package/example/ios/ReactNativeTrackerExample/AppDelegate.mm +26 -0
  87. package/example/ios/ReactNativeTrackerExample/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  88. package/example/ios/ReactNativeTrackerExample/Images.xcassets/Contents.json +6 -0
  89. package/example/ios/ReactNativeTrackerExample/Info.plist +55 -0
  90. package/example/ios/ReactNativeTrackerExample/LaunchScreen.storyboard +47 -0
  91. package/example/ios/ReactNativeTrackerExample/main.m +10 -0
  92. package/example/ios/ReactNativeTrackerExample-Bridging-Header.h +3 -0
  93. package/example/ios/ReactNativeTrackerExample.xcodeproj/project.pbxproj +722 -0
  94. package/{ios/RNSnowplowTracker.xcodeproj/xcshareddata/xcschemes/RNSnowplowTracker.xcscheme → example/ios/ReactNativeTrackerExample.xcodeproj/xcshareddata/xcschemes/ReactNativeTrackerExample.xcscheme} +29 -21
  95. package/example/ios/ReactNativeTrackerExample.xcworkspace/contents.xcworkspacedata +10 -0
  96. package/example/ios/ReactNativeTrackerExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  97. package/example/ios/ReactNativeTrackerExampleTests/Info.plist +24 -0
  98. package/example/ios/ReactNativeTrackerExampleTests/ReactNativeTrackerExampleTests.m +66 -0
  99. package/example/metro.config.js +45 -0
  100. package/example/package.json +54 -0
  101. package/example/react-native.config.js +10 -0
  102. package/example/src/App.js +566 -0
  103. package/example/tsconfig.json +5 -0
  104. package/example/yarn.lock +7379 -0
  105. package/ios/ReactNativeTracker-Bridging-Header.h +2 -0
  106. package/ios/ReactNativeTracker.mm +175 -0
  107. package/ios/ReactNativeTracker.swift +822 -0
  108. package/ios/{RNSnowplowTracker.xcodeproj → ReactNativeTracker.xcodeproj}/project.pbxproj +55 -79
  109. package/ios/Util/ConfigUtils.swift +209 -0
  110. package/ios/Util/TrackerVersion.swift +3 -0
  111. package/ios/Util/Utilities.swift +37 -0
  112. package/lefthook.yml +11 -0
  113. package/lib/commonjs/api.js +490 -0
  114. package/lib/commonjs/api.js.map +1 -0
  115. package/lib/commonjs/configurations.js +196 -0
  116. package/lib/commonjs/configurations.js.map +1 -0
  117. package/lib/commonjs/constants.js +77 -0
  118. package/lib/commonjs/constants.js.map +1 -0
  119. package/lib/commonjs/events.js +277 -0
  120. package/lib/commonjs/events.js.map +1 -0
  121. package/lib/commonjs/index.js +132 -0
  122. package/lib/commonjs/index.js.map +1 -0
  123. package/lib/commonjs/jsCore.js +427 -0
  124. package/lib/commonjs/jsCore.js.map +1 -0
  125. package/lib/commonjs/native.js +16 -0
  126. package/lib/commonjs/native.js.map +1 -0
  127. package/lib/commonjs/subject.js +235 -0
  128. package/lib/commonjs/subject.js.map +1 -0
  129. package/lib/commonjs/tracker.js +248 -0
  130. package/lib/commonjs/tracker.js.map +1 -0
  131. package/lib/commonjs/types.js +2 -0
  132. package/lib/commonjs/types.js.map +1 -0
  133. package/lib/commonjs/utils.js +72 -0
  134. package/lib/commonjs/utils.js.map +1 -0
  135. package/lib/commonjs/webViewInterface.js +66 -0
  136. package/lib/commonjs/webViewInterface.js.map +1 -0
  137. package/lib/module/api.js +452 -0
  138. package/lib/module/api.js.map +1 -0
  139. package/lib/module/configurations.js +184 -0
  140. package/lib/module/configurations.js.map +1 -0
  141. package/lib/module/constants.js +72 -0
  142. package/lib/module/constants.js.map +1 -0
  143. package/lib/module/events.js +259 -0
  144. package/lib/module/events.js.map +1 -0
  145. package/lib/module/index.js +120 -0
  146. package/lib/module/index.js.map +1 -0
  147. package/lib/module/jsCore.js +424 -0
  148. package/lib/module/jsCore.js.map +1 -0
  149. package/lib/module/native.js +12 -0
  150. package/lib/module/native.js.map +1 -0
  151. package/lib/module/subject.js +222 -0
  152. package/lib/module/subject.js.map +1 -0
  153. package/lib/module/tracker.js +234 -0
  154. package/lib/module/tracker.js.map +1 -0
  155. package/lib/module/types.js +2 -0
  156. package/lib/module/types.js.map +1 -0
  157. package/lib/module/utils.js +66 -0
  158. package/lib/module/utils.js.map +1 -0
  159. package/lib/module/webViewInterface.js +62 -0
  160. package/lib/module/webViewInterface.js.map +1 -0
  161. package/lib/typescript/__tests__/api.test.d.ts +2 -0
  162. package/lib/typescript/__tests__/api.test.d.ts.map +1 -0
  163. package/lib/typescript/__tests__/configurations.test.d.ts +2 -0
  164. package/lib/typescript/__tests__/configurations.test.d.ts.map +1 -0
  165. package/lib/typescript/__tests__/events.test.d.ts +2 -0
  166. package/lib/typescript/__tests__/events.test.d.ts.map +1 -0
  167. package/lib/typescript/__tests__/index.test.d.ts +2 -0
  168. package/lib/typescript/__tests__/index.test.d.ts.map +1 -0
  169. package/lib/typescript/__tests__/jsCore.test.d.ts +2 -0
  170. package/lib/typescript/__tests__/jsCore.test.d.ts.map +1 -0
  171. package/lib/typescript/__tests__/utils.test.d.ts +2 -0
  172. package/lib/typescript/__tests__/utils.test.d.ts.map +1 -0
  173. package/lib/typescript/api.d.ts +240 -0
  174. package/lib/typescript/api.d.ts.map +1 -0
  175. package/lib/typescript/configurations.d.ts +73 -0
  176. package/lib/typescript/configurations.d.ts.map +1 -0
  177. package/lib/typescript/constants.d.ts +64 -0
  178. package/lib/typescript/constants.d.ts.map +1 -0
  179. package/lib/typescript/events.d.ts +115 -0
  180. package/lib/typescript/events.d.ts.map +1 -0
  181. package/lib/typescript/index.d.ts +27 -0
  182. package/lib/typescript/index.d.ts.map +1 -0
  183. package/lib/typescript/jsCore.d.ts +152 -0
  184. package/lib/typescript/jsCore.d.ts.map +1 -0
  185. package/lib/typescript/native.d.ts +4 -0
  186. package/lib/typescript/native.d.ts.map +1 -0
  187. package/lib/typescript/subject.d.ts +91 -0
  188. package/lib/typescript/subject.d.ts.map +1 -0
  189. package/lib/typescript/tracker.d.ts +111 -0
  190. package/lib/typescript/tracker.d.ts.map +1 -0
  191. package/{dist/index.d.ts → lib/typescript/types.d.ts} +264 -73
  192. package/lib/typescript/types.d.ts.map +1 -0
  193. package/lib/typescript/utils.d.ts +35 -0
  194. package/lib/typescript/utils.d.ts.map +1 -0
  195. package/lib/typescript/webViewInterface.d.ts +15 -0
  196. package/lib/typescript/webViewInterface.d.ts.map +1 -0
  197. package/package.json +135 -53
  198. package/scripts/bootstrap.js +29 -0
  199. package/snowplow-react-native-tracker.podspec +42 -0
  200. package/src/__mocks__/react-native.js +7 -0
  201. package/src/__tests__/api.test.ts +21 -0
  202. package/src/__tests__/configurations.test.ts +608 -0
  203. package/src/__tests__/events.test.ts +736 -0
  204. package/src/__tests__/index.test.ts +14 -0
  205. package/src/__tests__/jsCore.test.ts +199 -0
  206. package/src/__tests__/utils.test.ts +10 -0
  207. package/src/api.ts +556 -0
  208. package/src/configurations.ts +325 -0
  209. package/src/constants.ts +97 -0
  210. package/src/events.ts +355 -0
  211. package/src/index.ts +184 -0
  212. package/src/jsCore.ts +603 -0
  213. package/src/native.ts +21 -0
  214. package/src/subject.ts +302 -0
  215. package/src/tracker.ts +377 -0
  216. package/src/types.ts +1162 -0
  217. package/src/utils.ts +65 -0
  218. package/src/webViewInterface.ts +92 -0
  219. package/tsconfig.build.json +5 -0
  220. package/tsconfig.json +28 -0
  221. package/turbo.json +34 -0
  222. package/yarn.lock +9333 -0
  223. package/RNSnowplowTracker.podspec +0 -24
  224. package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerModule.java +0 -750
  225. package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerPackage.java +0 -29
  226. package/android/src/main/java/com/snowplowanalytics/react/util/ConfigUtil.java +0 -351
  227. package/android/src/main/java/com/snowplowanalytics/react/util/EventUtil.java +0 -339
  228. package/android/src/main/java/com/snowplowanalytics/react/util/TrackerVersion.java +0 -7
  229. package/dist/index.js +0 -2026
  230. package/dist/index.js.map +0 -1
  231. package/ios/RNSnowplowTracker.h +0 -34
  232. package/ios/RNSnowplowTracker.m +0 -911
  233. package/ios/Util/NSDictionary+RNSP_TypeMethods.h +0 -33
  234. package/ios/Util/NSDictionary+RNSP_TypeMethods.m +0 -40
  235. package/ios/Util/RNConfigUtils.h +0 -44
  236. package/ios/Util/RNConfigUtils.m +0 -209
  237. package/ios/Util/RNTrackerVersion.h +0 -27
  238. package/ios/Util/RNTrackerVersion.m +0 -27
  239. package/ios/Util/RNUtilities.h +0 -32
  240. package/ios/Util/RNUtilities.m +0 -68
@@ -0,0 +1,566 @@
1
+ /**
2
+ * Sample React Native App
3
+ * https://github.com/facebook/react-native
4
+ *
5
+ * @format
6
+ * @flow strict-local
7
+ */
8
+
9
+ import React from 'react';
10
+ import {
11
+ SafeAreaView,
12
+ ScrollView,
13
+ StatusBar,
14
+ StyleSheet,
15
+ Text,
16
+ useColorScheme,
17
+ View,
18
+ Button,
19
+ Dimensions,
20
+ } from 'react-native';
21
+ import { WebView } from 'react-native-webview';
22
+
23
+ import { Colors, Header } from 'react-native/Libraries/NewAppScreen';
24
+
25
+ import {
26
+ createTracker,
27
+ removeTracker,
28
+ getWebViewCallback,
29
+ } from '@snowplow/react-native-tracker';
30
+
31
+ /**
32
+ * URI of the Snowplow collector (e.g., Micro, Mini, or BDP) to send events to
33
+ */
34
+ const collectorEndpoint = 'placeholder';
35
+
36
+ /**
37
+ * URI of a website to load in the webview component
38
+ */
39
+ const webViewEndpoint = '';
40
+
41
+ const Section = ({ children, title }) => {
42
+ const isDarkMode = useColorScheme() === 'dark';
43
+ return (
44
+ <View style={styles.sectionContainer}>
45
+ <Text
46
+ style={[
47
+ styles.sectionTitle,
48
+ {
49
+ color: isDarkMode ? Colors.white : Colors.black,
50
+ },
51
+ ]}
52
+ >
53
+ {title}
54
+ </Text>
55
+ <Text
56
+ style={[
57
+ styles.sectionDescription,
58
+ {
59
+ color: isDarkMode ? Colors.light : Colors.dark,
60
+ },
61
+ ]}
62
+ >
63
+ {children}
64
+ </Text>
65
+ </View>
66
+ );
67
+ };
68
+
69
+ const App = () => {
70
+ const isDarkMode = useColorScheme() === 'dark';
71
+
72
+ const backgroundStyle = {
73
+ backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
74
+ };
75
+
76
+ const tracker = createTracker(
77
+ 'sp1',
78
+ {
79
+ endpoint: collectorEndpoint,
80
+ requestHeaders: {
81
+ test: 'works',
82
+ },
83
+ },
84
+ {
85
+ trackerConfig: {
86
+ appId: 'DemoAppId',
87
+ base64Encoding: false,
88
+ devicePlatform: 'iot',
89
+ installAutotracking: false,
90
+ },
91
+ sessionConfig: {
92
+ foregroundTimeout: 5,
93
+ backgroundTimeout: 10,
94
+ },
95
+ subjectConfig: {
96
+ userId: 'tester',
97
+ screenViewport: [200, 200],
98
+ language: 'fr',
99
+ },
100
+ gdprConfig: {
101
+ basisForProcessing: 'consent',
102
+ documentId: 'docId',
103
+ documentVersion: '0.0.1',
104
+ documentDescription: 'test gdpr document',
105
+ },
106
+ gcConfig: [
107
+ {
108
+ tag: 'testTag',
109
+ globalContexts: [
110
+ {
111
+ schema:
112
+ 'iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0',
113
+ data: { impressionId: 'test_global_contexts_0' },
114
+ },
115
+ {
116
+ schema:
117
+ 'iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0',
118
+ data: { impressionId: 'test_global_contexts_1' },
119
+ },
120
+ ],
121
+ },
122
+ ],
123
+ }
124
+ );
125
+
126
+ const secTracker = createTracker(
127
+ 'sp2',
128
+ {
129
+ endpoint: collectorEndpoint,
130
+ },
131
+ {
132
+ trackerConfig: {
133
+ screenViewAutotracking: false, // for tests predictability
134
+ installAutotracking: false,
135
+ },
136
+ }
137
+ );
138
+
139
+ const anonymousTracker = createTracker(
140
+ 'sp_anon',
141
+ {
142
+ endpoint: collectorEndpoint,
143
+ },
144
+ {
145
+ trackerConfig: {
146
+ screenViewAutotracking: false, // for tests predictability
147
+ installAutotracking: false,
148
+ userAnonymisation: true,
149
+ },
150
+ emitterConfig: {
151
+ serverAnonymisation: true,
152
+ },
153
+ }
154
+ );
155
+
156
+ const onPressTrackScreenViewEvent = () => {
157
+ tracker.trackScreenViewEvent({ name: 'onlyRequired' });
158
+ tracker.trackScrollChangedEvent({
159
+ yOffset: 20,
160
+ contentHeight: 100,
161
+ viewHeight: 50,
162
+ });
163
+ tracker.trackListItemViewEvent({
164
+ index: 1,
165
+ itemsCount: 10,
166
+ });
167
+ tracker.trackScreenViewEvent({
168
+ name: 'allPopulated',
169
+ type: 'allPopulated',
170
+ transitionType: 'test',
171
+ });
172
+ tracker.trackScreenViewEvent({
173
+ name: 'allOptionalsNull',
174
+ type: null,
175
+ transitionType: null,
176
+ });
177
+ tracker.trackScreenViewEvent({
178
+ name: 'allOptionalsUndefined',
179
+ type: undefined,
180
+ transitionType: undefined,
181
+ });
182
+ tracker.trackScreenViewEvent(
183
+ {
184
+ name: 'withContext and screenId',
185
+ id: '5d79770b-015b-4af8-8c91-b2ed6faf4b1e',
186
+ },
187
+ [
188
+ {
189
+ schema:
190
+ 'iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0',
191
+ data: { impressionId: 'test_imp_id' },
192
+ },
193
+ ]
194
+ );
195
+ tracker.trackScreenViewEvent({ name: 'withEmptyArrayContext' }, []);
196
+ };
197
+
198
+ const onPressTrackSelfDescribingEvent = () => {
199
+ tracker.trackSelfDescribingEvent({
200
+ schema: 'iglu:com.snowplowanalytics.snowplow/link_click/jsonschema/1-0-1',
201
+ data: { targetUrl: 'test.test' },
202
+ });
203
+ tracker.trackTimingEvent({
204
+ category: 'testTimingCategory',
205
+ variable: 'testTimingVariable',
206
+ timing: 10,
207
+ });
208
+ tracker.trackConsentGrantedEvent({
209
+ expiry: '2022-01-01T00:00:00Z',
210
+ documentId: '0123',
211
+ version: '0.1.0',
212
+ });
213
+ tracker.trackConsentWithdrawnEvent({
214
+ all: true,
215
+ documentId: '0987',
216
+ version: '0.2.0',
217
+ });
218
+ tracker.trackEcommerceTransactionEvent(
219
+ {
220
+ orderId: '0000',
221
+ totalValue: 10,
222
+ items: [
223
+ {
224
+ sku: '123',
225
+ price: 5,
226
+ quantity: 2,
227
+ },
228
+ ],
229
+ },
230
+ []
231
+ );
232
+ };
233
+
234
+ const onPressTrackStructuredEvent = () => {
235
+ tracker.trackStructuredEvent({
236
+ category: 'SeTest',
237
+ action: 'allPopulated',
238
+ label: 'valueIsFloat',
239
+ property: 'property',
240
+ value: 50.1,
241
+ });
242
+ tracker.trackStructuredEvent({
243
+ category: 'SeTest',
244
+ action: 'allPopulated',
245
+ label: 'valueIsNullAndSoIsProperty',
246
+ property: null,
247
+ value: null,
248
+ });
249
+
250
+ tracker.trackStructuredEvent({
251
+ category: 'SeTest',
252
+ action: 'allPopulated',
253
+ label: 'valueIsUndefined',
254
+ property: 'property',
255
+ value: undefined,
256
+ });
257
+ tracker.trackStructuredEvent({
258
+ category: 'SeTest',
259
+ action: 'onlyRequired',
260
+ });
261
+ };
262
+
263
+ const onPressTrackPageViewEvent = () => {
264
+ tracker.trackPageViewEvent({
265
+ pageUrl: 'https://allpopulated.com',
266
+ pageTitle: 'some title',
267
+ referrer: 'http://refr.com',
268
+ });
269
+ tracker.trackPageViewEvent({ pageUrl: 'https://onlyrequired.com' });
270
+ tracker.trackPageViewEvent({
271
+ pageUrl: 'https://alloptionalsnull.com',
272
+ pageTitle: null,
273
+ referrer: null,
274
+ });
275
+ tracker.trackPageViewEvent({
276
+ pageUrl: 'https://alloptionalsundefined.com',
277
+ pageTitle: undefined,
278
+ referrer: undefined,
279
+ });
280
+ };
281
+
282
+ const onPressTrackDeepLinkReceivedEvent = () => {
283
+ tracker.trackDeepLinkReceivedEvent({
284
+ url: 'https://deeplink.com',
285
+ referrer: 'http://refr.com',
286
+ });
287
+ };
288
+
289
+ const onPressTrackMessageNotificationEvent = () => {
290
+ tracker.trackMessageNotificationEvent({
291
+ title: 'title1',
292
+ body: 'body1',
293
+ trigger: 'push',
294
+ action: 'action1',
295
+ attachments: [
296
+ {
297
+ identifier: 'att_id1',
298
+ type: 'att_type1',
299
+ url: 'http://att.url.1',
300
+ },
301
+ ],
302
+ bodyLocArgs: ['bodyArg1', 'bodyArg2'],
303
+ bodyLocKey: 'bodyKey1',
304
+ category: 'category1',
305
+ contentAvailable: true,
306
+ group: 'group1',
307
+ icon: 'icon1',
308
+ notificationCount: 3,
309
+ notificationTimestamp: '2022-02-02T15:17:42.767Z',
310
+ sound: 'sound1',
311
+ subtitle: 'subtitle1',
312
+ tag: 'tag1',
313
+ threadIdentifier: 'threadIdentifier1',
314
+ titleLocArgs: ['titleArg1', 'titleArg2'],
315
+ titleLocKey: 'titleKey1',
316
+ });
317
+ };
318
+
319
+ const onPressShowMeSomeWarnings = () => {
320
+ tracker.trackSelfDescribingEvent({});
321
+ tracker.trackStructuredEvent({});
322
+ tracker.trackPageViewEvent({});
323
+ tracker.trackScreenViewEvent({});
324
+ };
325
+
326
+ const onPressTestSetSubject = async () => {
327
+ try {
328
+ await tracker.setSubjectData({
329
+ userId: 'nextTester',
330
+ domainUserId: '5d79770b-015b-4af8-8c91-b2ed6faf4b1e',
331
+ language: 'es',
332
+ colorDepth: 50,
333
+ timezone: 'Europe/London',
334
+ screenResolution: [300, 300],
335
+ });
336
+ await tracker.trackScreenViewEvent({ name: 'afterSetSubjectTestSV' });
337
+ } catch (e) {
338
+ console.log(e.message);
339
+ }
340
+ };
341
+
342
+ const onPressTestSecondTracker = () => {
343
+ secTracker.trackScreenViewEvent({ name: 'fromSecondTracker' });
344
+ secTracker.trackStructuredEvent({
345
+ category: 'SecTracker',
346
+ action: 'trackStructured',
347
+ });
348
+ };
349
+
350
+ const onPressTestAnonymousTracker = () => {
351
+ anonymousTracker.trackScreenViewEvent({ name: 'fromAnonymousTracker' });
352
+ anonymousTracker.trackStructuredEvent({
353
+ category: 'AnonymousTracker',
354
+ action: 'trackAnonymous',
355
+ });
356
+ };
357
+
358
+ const onPressPlayGC = async () => {
359
+ try {
360
+ await tracker.removeGlobalContexts('testTag');
361
+ await tracker.addGlobalContexts({
362
+ tag: 'testTagReloaded',
363
+ globalContexts: [
364
+ {
365
+ schema:
366
+ 'iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0',
367
+ data: { impressionId: 'test_global_contexts_Reloaded' },
368
+ },
369
+ ],
370
+ });
371
+ await tracker.trackPageViewEvent({ pageUrl: 'afterGCChange.test' });
372
+ } catch (e) {
373
+ console.log(e.message);
374
+ }
375
+ };
376
+
377
+ const onPressRemoveSecTracker = () => {
378
+ removeTracker('sp2');
379
+ // removeAllTrackers();
380
+ };
381
+
382
+ const onPressLogSessionData = async () => {
383
+ try {
384
+ const sessionUserId = await tracker.getSessionUserId();
385
+ const sessionId = await tracker.getSessionId();
386
+ const sessionIdx = await tracker.getSessionIndex();
387
+ const isInBg = await tracker.getIsInBackground();
388
+ const bgIndex = await tracker.getBackgroundIndex();
389
+ const fgIndex = await tracker.getForegroundIndex();
390
+
391
+ const sessionData = {
392
+ userId: sessionUserId,
393
+ sessionId: sessionId,
394
+ sessionIndex: sessionIdx,
395
+ isInBackground: isInBg,
396
+ backgroundIndex: bgIndex,
397
+ foregroundIndex: fgIndex,
398
+ };
399
+ console.log(
400
+ 'SnowplowTracker: Session Data: ' + JSON.stringify(sessionData)
401
+ );
402
+ } catch (e) {
403
+ console.log(e.message);
404
+ }
405
+ };
406
+
407
+ return (
408
+ <SafeAreaView style={backgroundStyle}>
409
+ <StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
410
+ <ScrollView
411
+ testID="scrollView"
412
+ contentInsetAdjustmentBehavior="automatic"
413
+ style={backgroundStyle}
414
+ >
415
+ <Header />
416
+ <View
417
+ style={{
418
+ backgroundColor: isDarkMode ? Colors.black : Colors.white,
419
+ }}
420
+ >
421
+ <Section title="Screen Views">
422
+ <Button
423
+ onPress={onPressTrackScreenViewEvent}
424
+ title="Track some Screen View Events"
425
+ color="#841584"
426
+ accessibilityLabel="testScreenView"
427
+ />
428
+ </Section>
429
+ <Section title="Self-Describing Events">
430
+ <Button
431
+ onPress={onPressTrackSelfDescribingEvent}
432
+ title="Track some Self-Describing Events"
433
+ color="#841584"
434
+ accessibilityLabel="testSelfDesc"
435
+ />
436
+ </Section>
437
+ <Section title="Structured Events">
438
+ <Button
439
+ onPress={onPressTrackStructuredEvent}
440
+ title="Track some Structured Events"
441
+ color="#841584"
442
+ accessibilityLabel="testStruct"
443
+ />
444
+ </Section>
445
+ <Section title="Page Views">
446
+ <Button
447
+ onPress={onPressTrackPageViewEvent}
448
+ title="Track some Page View Events"
449
+ color="#841584"
450
+ accessibilityLabel="testPageView"
451
+ />
452
+ </Section>
453
+ <Section title="Deep Link">
454
+ <Button
455
+ onPress={onPressTrackDeepLinkReceivedEvent}
456
+ title="Track a Deep Link Received Event"
457
+ color="#841584"
458
+ accessibilityLabel="testDeepLinkReceived"
459
+ />
460
+ </Section>
461
+ <Section title="Message Notification">
462
+ <Button
463
+ onPress={onPressTrackMessageNotificationEvent}
464
+ title="Track a Message Notification Event"
465
+ color="#841584"
466
+ accessibilityLabel="testMessageNotification"
467
+ />
468
+ </Section>
469
+ <Section title="Second tracker">
470
+ <Button
471
+ onPress={onPressTestSecondTracker}
472
+ title="Track events with second tracker"
473
+ color="#841584"
474
+ accessibilityLabel="testSecTracker"
475
+ />
476
+ </Section>
477
+ <Section title="Anonymous tracker">
478
+ <Button
479
+ onPress={onPressTestAnonymousTracker}
480
+ title="Track events with anonymous tracking"
481
+ color="#841584"
482
+ accessibilityLabel="testAnonymousTracker"
483
+ />
484
+ </Section>
485
+ <Section title="Warnings">
486
+ <Button
487
+ onPress={onPressShowMeSomeWarnings}
488
+ title="Show me some warnings"
489
+ color="#f6bd3b"
490
+ accessibilityLabel="testWrongInputs"
491
+ />
492
+ </Section>
493
+ <Section title="Set the Subject">
494
+ <Button
495
+ onPress={onPressTestSetSubject}
496
+ title="Set the Subject again"
497
+ color="#228B22"
498
+ accessibilityLabel="testSetSubject"
499
+ />
500
+ </Section>
501
+ <Section title="SessionData">
502
+ <Button
503
+ onPress={onPressLogSessionData}
504
+ title="Show me session data"
505
+ color="#f6bd3b"
506
+ accessibilityLabel="testSessionData"
507
+ />
508
+ </Section>
509
+
510
+ <Section title="GC">
511
+ <Button
512
+ onPress={onPressPlayGC}
513
+ title="Remove and Add Global Contexts"
514
+ color="#228B22"
515
+ accessibilityLabel="testGC"
516
+ />
517
+ </Section>
518
+ <Section title="Removals">
519
+ <Button
520
+ onPress={onPressRemoveSecTracker}
521
+ title="Remove Tracker"
522
+ color="#AA2222"
523
+ accessibilityLabel="testRemove"
524
+ />
525
+ </Section>
526
+ <Section title="Web view">
527
+ {webViewEndpoint ? (
528
+ <WebView
529
+ onMessage={getWebViewCallback()}
530
+ source={{ uri: webViewEndpoint }}
531
+ style={{
532
+ height: 400,
533
+ width:
534
+ Dimensions.get('window').width -
535
+ styles.sectionContainer.paddingHorizontal,
536
+ }}
537
+ />
538
+ ) : null}
539
+ </Section>
540
+ </View>
541
+ </ScrollView>
542
+ </SafeAreaView>
543
+ );
544
+ };
545
+
546
+ const styles = StyleSheet.create({
547
+ sectionContainer: {
548
+ marginTop: 32,
549
+ marginBottom: 16,
550
+ paddingHorizontal: 24,
551
+ },
552
+ sectionTitle: {
553
+ fontSize: 24,
554
+ fontWeight: '600',
555
+ },
556
+ sectionDescription: {
557
+ marginTop: 8,
558
+ fontSize: 18,
559
+ fontWeight: '400',
560
+ },
561
+ highlight: {
562
+ fontWeight: '700',
563
+ },
564
+ });
565
+
566
+ export default App;
@@ -0,0 +1,5 @@
1
+ {
2
+ "compilerOptions": {
3
+ "verbatimModuleSyntax": false
4
+ }
5
+ }