@snowplow/react-native-tracker 1.4.0 → 2.0.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 (239) 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 +150 -0
  8. package/.github/workflows/deploy.yml +98 -0
  9. package/.github/workflows/e2e-android.yml +121 -0
  10. package/.github/workflows/e2e-ios.yml +90 -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 +166 -0
  18. package/CONTRIBUTING.md +80 -0
  19. package/README.md +23 -110
  20. package/android/build.gradle +93 -37
  21. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  22. package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
  23. package/android/gradle.properties +5 -2
  24. package/android/gradlew +172 -110
  25. package/android/gradlew.bat +24 -19
  26. package/android/src/main/AndroidManifest.xml +1 -3
  27. package/android/src/main/AndroidManifestNew.xml +2 -0
  28. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt +704 -0
  29. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerPackage.kt +17 -0
  30. package/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt +271 -0
  31. package/android/src/main/java/com/snowplow/reactnativetracker/util/EventUtil.kt +213 -0
  32. package/android/src/main/java/com/snowplow/reactnativetracker/util/TrackerVersion.kt +5 -0
  33. package/babel.config.js +3 -0
  34. package/example/.watchmanconfig +1 -0
  35. package/example/Gemfile +6 -0
  36. package/example/android/app/build.gradle +129 -0
  37. package/example/android/app/debug.keystore +0 -0
  38. package/example/android/app/proguard-rules.pro +10 -0
  39. package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTest.java +36 -0
  40. package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTestAppJUnitRunner.java +21 -0
  41. package/example/android/app/src/debug/AndroidManifest.xml +13 -0
  42. package/example/android/app/src/debug/java/com/reactnativetrackerexample/ReactNativeFlipper.java +75 -0
  43. package/example/android/app/src/main/AndroidManifest.xml +26 -0
  44. package/example/android/app/src/main/java/com/reactnativetrackerexample/MainActivity.java +32 -0
  45. package/example/android/app/src/main/java/com/reactnativetrackerexample/MainApplication.java +62 -0
  46. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
  47. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  48. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  49. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  50. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  51. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  52. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  53. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  54. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  55. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  56. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  57. package/example/android/app/src/main/res/values/strings.xml +3 -0
  58. package/example/android/app/src/main/res/values/styles.xml +9 -0
  59. package/example/android/app/src/release/java/com/reactnativetrackerexample/ReactNativeFlipper.java +20 -0
  60. package/example/android/build.gradle +31 -0
  61. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  62. package/example/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  63. package/example/android/gradle.properties +44 -0
  64. package/example/android/gradlew +244 -0
  65. package/example/android/gradlew.bat +92 -0
  66. package/example/android/settings.gradle +4 -0
  67. package/example/app.json +4 -0
  68. package/example/babel.config.js +17 -0
  69. package/example/detox.config.js +92 -0
  70. package/example/e2e/config.json +10 -0
  71. package/example/e2e/emitEvents.e2e.detox.js +108 -0
  72. package/example/e2e/environment.js +23 -0
  73. package/example/e2e/helpers/microCommands.js +153 -0
  74. package/example/e2e/helpers/microHelpers.js +346 -0
  75. package/example/e2e/helpers/microHelpers.test.js +308 -0
  76. package/example/e2e/helpers/schemas.js +62 -0
  77. package/example/e2e/jest.config.js +16 -0
  78. package/example/e2e/setup.js +4 -0
  79. package/example/e2e/testEvents.micro.test.js +300 -0
  80. package/example/index.js +5 -0
  81. package/example/ios/.xcode.env +11 -0
  82. package/example/ios/Podfile +64 -0
  83. package/example/ios/Podfile.lock +737 -0
  84. package/example/ios/ReactNativeTrackerExample/AppDelegate.h +6 -0
  85. package/example/ios/ReactNativeTrackerExample/AppDelegate.mm +26 -0
  86. package/example/ios/ReactNativeTrackerExample/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  87. package/example/ios/ReactNativeTrackerExample/Images.xcassets/Contents.json +6 -0
  88. package/example/ios/ReactNativeTrackerExample/Info.plist +55 -0
  89. package/example/ios/ReactNativeTrackerExample/LaunchScreen.storyboard +47 -0
  90. package/example/ios/ReactNativeTrackerExample/main.m +10 -0
  91. package/example/ios/ReactNativeTrackerExample-Bridging-Header.h +3 -0
  92. package/example/ios/ReactNativeTrackerExample.xcodeproj/project.pbxproj +722 -0
  93. package/{ios/RNSnowplowTracker.xcodeproj/xcshareddata/xcschemes/RNSnowplowTracker.xcscheme → example/ios/ReactNativeTrackerExample.xcodeproj/xcshareddata/xcschemes/ReactNativeTrackerExample.xcscheme} +29 -21
  94. package/example/ios/ReactNativeTrackerExample.xcworkspace/contents.xcworkspacedata +10 -0
  95. package/example/ios/ReactNativeTrackerExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  96. package/example/ios/ReactNativeTrackerExampleTests/Info.plist +24 -0
  97. package/example/ios/ReactNativeTrackerExampleTests/ReactNativeTrackerExampleTests.m +66 -0
  98. package/example/metro.config.js +45 -0
  99. package/example/package.json +54 -0
  100. package/example/react-native.config.js +10 -0
  101. package/example/src/App.js +557 -0
  102. package/example/tsconfig.json +5 -0
  103. package/example/yarn.lock +7379 -0
  104. package/ios/ReactNativeTracker-Bridging-Header.h +2 -0
  105. package/ios/ReactNativeTracker.mm +165 -0
  106. package/ios/ReactNativeTracker.swift +757 -0
  107. package/ios/{RNSnowplowTracker.xcodeproj → ReactNativeTracker.xcodeproj}/project.pbxproj +55 -79
  108. package/ios/Util/ConfigUtils.swift +206 -0
  109. package/ios/Util/TrackerVersion.swift +3 -0
  110. package/ios/Util/Utilities.swift +37 -0
  111. package/lefthook.yml +11 -0
  112. package/lib/commonjs/api.js +475 -0
  113. package/lib/commonjs/api.js.map +1 -0
  114. package/lib/commonjs/configurations.js +209 -0
  115. package/lib/commonjs/configurations.js.map +1 -0
  116. package/lib/commonjs/constants.js +85 -0
  117. package/lib/commonjs/constants.js.map +1 -0
  118. package/lib/commonjs/events.js +256 -0
  119. package/lib/commonjs/events.js.map +1 -0
  120. package/lib/commonjs/index.js +141 -0
  121. package/lib/commonjs/index.js.map +1 -0
  122. package/lib/commonjs/jsCore.js +393 -0
  123. package/lib/commonjs/jsCore.js.map +1 -0
  124. package/lib/commonjs/native.js +29 -0
  125. package/lib/commonjs/native.js.map +1 -0
  126. package/lib/commonjs/subject.js +248 -0
  127. package/lib/commonjs/subject.js.map +1 -0
  128. package/lib/commonjs/tracker.js +221 -0
  129. package/lib/commonjs/tracker.js.map +1 -0
  130. package/lib/commonjs/types.js +2 -0
  131. package/lib/commonjs/types.js.map +1 -0
  132. package/lib/commonjs/utils.js +85 -0
  133. package/lib/commonjs/utils.js.map +1 -0
  134. package/lib/commonjs/webViewInterface.js +79 -0
  135. package/lib/commonjs/webViewInterface.js.map +1 -0
  136. package/lib/module/api.js +439 -0
  137. package/lib/module/api.js.map +1 -0
  138. package/lib/module/configurations.js +197 -0
  139. package/lib/module/configurations.js.map +1 -0
  140. package/lib/module/constants.js +80 -0
  141. package/lib/module/constants.js.map +1 -0
  142. package/lib/module/events.js +240 -0
  143. package/lib/module/events.js.map +1 -0
  144. package/lib/module/index.js +129 -0
  145. package/lib/module/index.js.map +1 -0
  146. package/lib/module/jsCore.js +390 -0
  147. package/lib/module/jsCore.js.map +1 -0
  148. package/lib/module/native.js +25 -0
  149. package/lib/module/native.js.map +1 -0
  150. package/lib/module/subject.js +235 -0
  151. package/lib/module/subject.js.map +1 -0
  152. package/lib/module/tracker.js +209 -0
  153. package/lib/module/tracker.js.map +1 -0
  154. package/lib/module/types.js +2 -0
  155. package/lib/module/types.js.map +1 -0
  156. package/lib/module/utils.js +79 -0
  157. package/lib/module/utils.js.map +1 -0
  158. package/lib/module/webViewInterface.js +75 -0
  159. package/lib/module/webViewInterface.js.map +1 -0
  160. package/lib/typescript/__tests__/api.test.d.ts +2 -0
  161. package/lib/typescript/__tests__/api.test.d.ts.map +1 -0
  162. package/lib/typescript/__tests__/configurations.test.d.ts +2 -0
  163. package/lib/typescript/__tests__/configurations.test.d.ts.map +1 -0
  164. package/lib/typescript/__tests__/events.test.d.ts +2 -0
  165. package/lib/typescript/__tests__/events.test.d.ts.map +1 -0
  166. package/lib/typescript/__tests__/index.test.d.ts +2 -0
  167. package/lib/typescript/__tests__/index.test.d.ts.map +1 -0
  168. package/lib/typescript/__tests__/jsCore.test.d.ts +2 -0
  169. package/lib/typescript/__tests__/jsCore.test.d.ts.map +1 -0
  170. package/lib/typescript/__tests__/utils.test.d.ts +2 -0
  171. package/lib/typescript/__tests__/utils.test.d.ts.map +1 -0
  172. package/lib/typescript/api.d.ts +226 -0
  173. package/lib/typescript/api.d.ts.map +1 -0
  174. package/lib/typescript/configurations.d.ts +73 -0
  175. package/lib/typescript/configurations.d.ts.map +1 -0
  176. package/lib/typescript/constants.d.ts +59 -0
  177. package/lib/typescript/constants.d.ts.map +1 -0
  178. package/lib/typescript/events.d.ts +101 -0
  179. package/lib/typescript/events.d.ts.map +1 -0
  180. package/lib/typescript/index.d.ts +27 -0
  181. package/lib/typescript/index.d.ts.map +1 -0
  182. package/lib/typescript/jsCore.d.ts +140 -0
  183. package/lib/typescript/jsCore.d.ts.map +1 -0
  184. package/lib/typescript/native.d.ts +4 -0
  185. package/lib/typescript/native.d.ts.map +1 -0
  186. package/lib/typescript/subject.d.ts +91 -0
  187. package/lib/typescript/subject.d.ts.map +1 -0
  188. package/lib/typescript/tracker.d.ts +93 -0
  189. package/lib/typescript/tracker.d.ts.map +1 -0
  190. package/{dist/index.d.ts → lib/typescript/types.d.ts} +188 -75
  191. package/lib/typescript/types.d.ts.map +1 -0
  192. package/lib/typescript/utils.d.ts +35 -0
  193. package/lib/typescript/utils.d.ts.map +1 -0
  194. package/lib/typescript/webViewInterface.d.ts +15 -0
  195. package/lib/typescript/webViewInterface.d.ts.map +1 -0
  196. package/package.json +134 -52
  197. package/scripts/bootstrap.js +29 -0
  198. package/snowplow-react-native-tracker.podspec +42 -0
  199. package/src/__mocks__/react-native.js +7 -0
  200. package/src/__tests__/api.test.ts +34 -0
  201. package/src/__tests__/configurations.test.ts +620 -0
  202. package/src/__tests__/events.test.ts +749 -0
  203. package/src/__tests__/index.test.ts +27 -0
  204. package/src/__tests__/jsCore.test.ts +169 -0
  205. package/src/__tests__/utils.test.ts +23 -0
  206. package/src/api.ts +535 -0
  207. package/src/configurations.ts +337 -0
  208. package/src/constants.ts +102 -0
  209. package/src/events.ts +330 -0
  210. package/src/index.ts +189 -0
  211. package/src/jsCore.ts +553 -0
  212. package/src/native.ts +34 -0
  213. package/src/subject.ts +315 -0
  214. package/src/tracker.ts +330 -0
  215. package/src/types.ts +1087 -0
  216. package/src/utils.ts +78 -0
  217. package/src/webViewInterface.ts +105 -0
  218. package/tsconfig.build.json +5 -0
  219. package/tsconfig.json +28 -0
  220. package/turbo.json +34 -0
  221. package/yarn.lock +9333 -0
  222. package/RNSnowplowTracker.podspec +0 -24
  223. package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerModule.java +0 -750
  224. package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerPackage.java +0 -29
  225. package/android/src/main/java/com/snowplowanalytics/react/util/ConfigUtil.java +0 -351
  226. package/android/src/main/java/com/snowplowanalytics/react/util/EventUtil.java +0 -339
  227. package/android/src/main/java/com/snowplowanalytics/react/util/TrackerVersion.java +0 -7
  228. package/dist/index.js +0 -2026
  229. package/dist/index.js.map +0 -1
  230. package/ios/RNSnowplowTracker.h +0 -34
  231. package/ios/RNSnowplowTracker.m +0 -911
  232. package/ios/Util/NSDictionary+RNSP_TypeMethods.h +0 -33
  233. package/ios/Util/NSDictionary+RNSP_TypeMethods.m +0 -40
  234. package/ios/Util/RNConfigUtils.h +0 -44
  235. package/ios/Util/RNConfigUtils.m +0 -209
  236. package/ios/Util/RNTrackerVersion.h +0 -27
  237. package/ios/Util/RNTrackerVersion.m +0 -27
  238. package/ios/Util/RNUtilities.h +0 -32
  239. package/ios/Util/RNUtilities.m +0 -68
package/dist/index.js DELETED
@@ -1,2026 +0,0 @@
1
- import { NativeModules } from 'react-native';
2
- import { trackerCore, buildSelfDescribingEvent, buildStructEvent, buildPageView, buildConsentGranted, buildConsentWithdrawn, buildEcommerceTransactionItem, buildEcommerceTransaction } from '@snowplow/tracker-core';
3
- import { v4 } from 'uuid';
4
-
5
- /*
6
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
7
- *
8
- * This program is licensed to you under the Apache License Version 2.0,
9
- * and you may not use this file except in compliance with the Apache License Version 2.0.
10
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the Apache License Version 2.0 is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
16
- */
17
- /**
18
- * Returns a function that accepts a side-effect function as its argument and subscribes
19
- * that function to aPromise's fullfillment,
20
- * and errHandle to aPromise's rejection.
21
- *
22
- * @param aPromise - A void Promise
23
- * @param errHandle - A function to handle the promise being rejected
24
- * @returns - A function subscribed to the Promise's fullfillment
25
- */
26
- function safeWait(aPromise, errHandle) {
27
- return ((func) => {
28
- return (...args) => {
29
- return aPromise.then(() => func(...args)).catch((err) => errHandle(err));
30
- };
31
- });
32
- }
33
- /**
34
- * Returns a function that accepts a callback function as its argument and subscribes
35
- * that function to aPromise's fullfillment,
36
- * and errHandle to aPromise's rejection.
37
- *
38
- * @param aPromise - A void Promise
39
- * @param errHandle - A function to handle the promise being rejected
40
- * @returns - A function subscribed to the Promise's fullfillment
41
- */
42
- function safeWaitCallback(callPromise, errHandle) {
43
- return ((func) => {
44
- return (...args) => {
45
- return callPromise.then(() => func(...args)).catch((err) => errHandle(err));
46
- };
47
- });
48
- }
49
- /**
50
- * Handles an error.
51
- *
52
- * @param err - The error to be handled.
53
- */
54
- function errorHandler(err) {
55
- if (__DEV__) {
56
- console.warn('SnowplowTracker:' + err.message);
57
- return undefined;
58
- }
59
- return undefined;
60
- }
61
- /**
62
- * Helper to check whether its argument is of object type
63
- *
64
- * @param x - The argument to check.
65
- * @returns - A boolean
66
- */
67
- function isObject(x) {
68
- return Object.prototype.toString.call(x) === '[object Object]';
69
- }
70
-
71
- /*
72
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
73
- *
74
- * This program is licensed to you under the Apache License Version 2.0,
75
- * and you may not use this file except in compliance with the Apache License Version 2.0.
76
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
77
- *
78
- * Unless required by applicable law or agreed to in writing,
79
- * software distributed under the Apache License Version 2.0 is distributed on an
80
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
81
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
82
- */
83
- const logMessages = {
84
- // configuration errors
85
- namespace: 'namespace parameter is required to be set',
86
- endpoint: 'endpoint parameter is required to be set',
87
- network: 'networkConfig is invalid',
88
- tracker: 'trackerConfig is invalid',
89
- session: 'sessionConfig is invalid',
90
- emitter: 'emitterConfig is invalid',
91
- subject: 'subjectConfig is invalid',
92
- gdpr: 'gdprConfig is invalid',
93
- gc: 'gcConfig is invalid',
94
- // event errors
95
- context: 'invalid contexts parameter',
96
- selfDesc: 'selfDescribing event requires schema and data parameters to be set',
97
- evType: 'event argument can only be an object',
98
- screenViewReq: 'screenView event requires name as string parameter to be set',
99
- structuredReq: 'structured event requires category and action parameters to be set',
100
- pageviewReq: 'pageView event requires pageUrl parameter to be set',
101
- timingReq: 'timing event requires category, variable and timing parameters to be set',
102
- consentGReq: 'consentGranted event requires expiry, documentId and version parameters to be set',
103
- consentWReq: 'consentWithdrawn event requires all, documentId and version parameters to be set',
104
- ecomReq: 'ecommerceTransaction event requires orderId, totalValue to be set and items to be an array of valid ecommerceItems',
105
- deepLinkReq: 'deepLinkReceived event requires the url parameter to be set',
106
- messageNotificationReq: 'messageNotification event requires title, body, and trigger parameters to be set',
107
- // global contexts errors
108
- gcTagType: 'tag argument is required to be a string',
109
- gcType: 'global context argument is invalid',
110
- // api error prefix
111
- createTracker: 'createTracker:',
112
- removeTracker: 'removeTracker: trackerNamespace can only be a string',
113
- // methods
114
- trackSelfDesc: 'trackSelfDescribingEvent:',
115
- trackScreenView: 'trackScreenViewEvent:',
116
- trackStructured: 'trackStructuredEvent:',
117
- trackPageView: 'trackPageViewEvent:',
118
- trackTiming: 'trackTimingEvent:',
119
- trackConsentGranted: 'trackConsentGranted:',
120
- trackConsentWithdrawn: 'trackConsentWithdrawn:',
121
- trackEcommerceTransaction: 'trackEcommerceTransaction:',
122
- trackDeepLinkReceived: 'trackDeepLinkReceivedEvent:',
123
- trackMessageNotification: 'trackMessageNotificationEvent:',
124
- removeGlobalContexts: 'removeGlobalContexts:',
125
- addGlobalContexts: 'addGlobalContexts:',
126
- // setters
127
- setUserId: 'setUserId: userId can only be a string or null',
128
- setNetworkUserId: 'setNetworkUserId: networkUserId can only be a string(UUID) or null',
129
- setDomainUserId: 'setDomainUserId: domainUserId can only be a string(UUID) or null',
130
- setIpAddress: 'setIpAddress: ipAddress can only be a string or null',
131
- setUseragent: 'setUseragent: useragent can only be a string or null',
132
- setTimezone: 'setTimezone: timezone can only be a string or null',
133
- setLanguage: 'setLanguage: language can only be a string or null',
134
- setScreenResolution: 'setScreenResolution: screenResolution can only be of ScreenSize type or null',
135
- setScreenViewport: 'setScreenViewport: screenViewport can only be of ScreenSize type or null',
136
- setColorDepth: 'setColorDepth: colorDepth can only be a number(integer) or null',
137
- setSubjectData: 'setSubjectData:',
138
- };
139
- const schemas = {
140
- payloadData: 'iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4',
141
- timingSchema: 'iglu:com.snowplowanalytics.snowplow/timing/jsonschema/1-0-0',
142
- deepLinkReceivedSchema: 'iglu:com.snowplowanalytics.mobile/deep_link_received/jsonschema/1-0-0',
143
- messageNotificationSchema: 'iglu:com.snowplowanalytics.mobile/message_notification/jsonschema/1-0-0',
144
- screenViewSchema: 'iglu:com.snowplowanalytics.mobile/screen_view/jsonschema/1-0-0',
145
- };
146
-
147
- /*
148
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
149
- *
150
- * This program is licensed to you under the Apache License Version 2.0,
151
- * and you may not use this file except in compliance with the Apache License Version 2.0.
152
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
153
- *
154
- * Unless required by applicable law or agreed to in writing,
155
- * software distributed under the Apache License Version 2.0 is distributed on an
156
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
157
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
158
- */
159
- // Tracker version added to the events
160
- const trackerVersion = 'rn-1.4.0';
161
- let trackers = {};
162
- function preparePayload(payload) {
163
- const stringifiedPayload = {};
164
- payload['stm'] = new Date().getTime().toString();
165
- for (const key in payload) {
166
- if (Object.prototype.hasOwnProperty.call(payload, key)) {
167
- stringifiedPayload[key] = String(payload[key]);
168
- }
169
- }
170
- return stringifiedPayload;
171
- }
172
- function createEmitCallback(networkConfig) {
173
- return (e) => {
174
- const postJson = {
175
- schema: schemas.payloadData,
176
- data: [preparePayload(e)],
177
- };
178
- const endpoint = networkConfig.endpoint;
179
- const postPath = networkConfig.customPostPath ?? '/com.snowplowanalytics.snowplow/tp2';
180
- const headers = networkConfig.requestHeaders ?? {};
181
- fetch(endpoint + postPath, {
182
- method: 'POST',
183
- body: JSON.stringify(postJson),
184
- headers: {
185
- 'Content-Type': 'application/json',
186
- ...headers,
187
- },
188
- }).catch(errorHandler);
189
- };
190
- }
191
- function updateTrackerProperties(tracker, configuration) {
192
- tracker.setPlatform(configuration.trackerConfig?.devicePlatform ?? 'mob');
193
- tracker.setTrackerVersion(trackerVersion);
194
- tracker.setTrackerNamespace(configuration.namespace);
195
- if (configuration.trackerConfig?.appId != null) {
196
- tracker.setAppId(configuration.trackerConfig.appId);
197
- }
198
- if (configuration.subjectConfig?.colorDepth != null) {
199
- tracker.setColorDepth(String(configuration.subjectConfig.colorDepth));
200
- }
201
- if (configuration.subjectConfig?.domainUserId != null) {
202
- tracker.setDomainUserId(configuration.subjectConfig.domainUserId);
203
- }
204
- if (configuration.subjectConfig?.ipAddress != null) {
205
- tracker.setIpAddress(configuration.subjectConfig.ipAddress);
206
- }
207
- if (configuration.subjectConfig?.language != null) {
208
- tracker.setLang(configuration.subjectConfig.language);
209
- }
210
- if (configuration.subjectConfig?.screenResolution != null) {
211
- tracker.setScreenResolution(String(configuration.subjectConfig.screenResolution[0]), String(configuration.subjectConfig.screenResolution[1]));
212
- }
213
- if (configuration.subjectConfig?.screenViewport != null) {
214
- tracker.setViewport(String(configuration.subjectConfig.screenViewport[0]), String(configuration.subjectConfig.screenViewport[1]));
215
- }
216
- if (configuration.subjectConfig?.timezone != null) {
217
- tracker.setTimezone(configuration.subjectConfig.timezone);
218
- }
219
- if (configuration.subjectConfig?.userId != null) {
220
- tracker.setUserId(configuration.subjectConfig.userId);
221
- }
222
- if (configuration.subjectConfig?.useragent != null) {
223
- tracker.setUseragent(configuration.subjectConfig.useragent);
224
- }
225
- }
226
- function createTracker$2(configuration, emitCallback) {
227
- // create an emit callback if not given
228
- const emitter = emitCallback ?? createEmitCallback(configuration.networkConfig);
229
- // the tracker core does not provide an option to set the duid, so we need to add custom
230
- let domainUserId;
231
- const setDomainUserId = (userId) => {
232
- domainUserId = userId;
233
- };
234
- let networkUserId;
235
- const setNetworkUserId = (userId) => {
236
- networkUserId = userId;
237
- };
238
- // initialize the tracker core
239
- const core = trackerCore({
240
- base64: configuration.trackerConfig?.base64Encoding ?? true,
241
- callback: (payload) => {
242
- if (domainUserId != null) {
243
- payload.add('duid', domainUserId);
244
- }
245
- if (networkUserId != null) {
246
- payload.add('tnuid', networkUserId);
247
- }
248
- const builtPayload = payload.build();
249
- emitter(builtPayload);
250
- },
251
- });
252
- const tracker = { ...core, setDomainUserId, setNetworkUserId };
253
- trackers[configuration.namespace] = tracker;
254
- // update tracker properties to reflect subject and tracker info
255
- updateTrackerProperties(tracker, configuration);
256
- return Promise.resolve();
257
- }
258
- function removeTracker$2(details) {
259
- delete trackers[details.tracker];
260
- return Promise.resolve(true);
261
- }
262
- function removeAllTrackers$2() {
263
- trackers = {};
264
- return Promise.resolve(true);
265
- }
266
- function forTracker(namespace, callback) {
267
- const tracker = namespace != null ? trackers[namespace] : Object.values(trackers)[0];
268
- if (tracker) {
269
- callback(tracker);
270
- }
271
- else {
272
- errorHandler(new Error('No such tracker found.'));
273
- }
274
- }
275
- function trackSelfDescribingEvent$2(details) {
276
- forTracker(details.tracker, (tracker) => {
277
- tracker.track(buildSelfDescribingEvent({
278
- event: details.eventData,
279
- }), details.contexts);
280
- });
281
- return Promise.resolve();
282
- }
283
- function trackStructuredEvent$2(details) {
284
- forTracker(details.tracker, (tracker) => {
285
- tracker.track(buildStructEvent(details.eventData), details.contexts);
286
- });
287
- return Promise.resolve();
288
- }
289
- function trackScreenViewEvent$2(details) {
290
- const data = {
291
- name: details.eventData.name,
292
- id: details.eventData.id ?? v4()
293
- };
294
- if (details.eventData.type != null) {
295
- data.type = details.eventData.type;
296
- }
297
- if (details.eventData.previousName != null) {
298
- data.previousName = details.eventData.previousName;
299
- }
300
- if (details.eventData.previousId != null) {
301
- data.previousId = details.eventData.previousId;
302
- }
303
- if (details.eventData.previousType != null) {
304
- data.previousType = details.eventData.previousType;
305
- }
306
- if (details.eventData.transitionType != null) {
307
- data.transitionType = details.eventData.transitionType;
308
- }
309
- return trackSelfDescribingEvent$2({
310
- tracker: details.tracker,
311
- eventData: {
312
- schema: schemas.screenViewSchema,
313
- data: data
314
- },
315
- contexts: details.contexts,
316
- });
317
- }
318
- function trackPageViewEvent$2(details) {
319
- forTracker(details.tracker, (tracker) => {
320
- tracker.track(buildPageView(details.eventData), details.contexts);
321
- });
322
- return Promise.resolve();
323
- }
324
- function trackTimingEvent$2(details) {
325
- return trackSelfDescribingEvent$2({
326
- tracker: details.tracker,
327
- eventData: {
328
- schema: schemas.timingSchema,
329
- data: details.eventData,
330
- },
331
- contexts: details.contexts,
332
- });
333
- }
334
- function trackConsentGrantedEvent$2(details) {
335
- forTracker(details.tracker, (tracker) => {
336
- const built = buildConsentGranted({
337
- id: details.eventData.documentId,
338
- version: details.eventData.version,
339
- name: details.eventData.name,
340
- description: details.eventData.documentDescription,
341
- expiry: details.eventData.expiry,
342
- });
343
- tracker.track(built.event, details.contexts.concat(built.context));
344
- });
345
- return Promise.resolve();
346
- }
347
- function trackConsentWithdrawnEvent$2(details) {
348
- forTracker(details.tracker, (tracker) => {
349
- const built = buildConsentWithdrawn({
350
- all: details.eventData.all,
351
- id: details.eventData.documentId,
352
- version: details.eventData.version,
353
- name: details.eventData.name,
354
- description: details.eventData.documentDescription,
355
- });
356
- tracker.track(built.event, details.contexts.concat(built.context));
357
- });
358
- return Promise.resolve();
359
- }
360
- function trackEcommerceTransactionEvent$2(details) {
361
- forTracker(details.tracker, (tracker) => {
362
- details.eventData.items.forEach(item => {
363
- tracker.track(buildEcommerceTransactionItem({
364
- ...item,
365
- orderId: details.eventData.orderId
366
- }), details.contexts);
367
- });
368
- tracker.track(buildEcommerceTransaction({
369
- orderId: details.eventData.orderId,
370
- total: details.eventData.totalValue,
371
- affiliation: details.eventData.affiliation,
372
- tax: details.eventData.taxValue,
373
- shipping: details.eventData.shipping,
374
- city: details.eventData.city,
375
- state: details.eventData.state,
376
- country: details.eventData.country,
377
- currency: details.eventData.currency,
378
- }), details.contexts);
379
- });
380
- return Promise.resolve();
381
- }
382
- function trackDeepLinkReceivedEvent$2(details) {
383
- return trackSelfDescribingEvent$2({
384
- tracker: details.tracker,
385
- eventData: {
386
- schema: schemas.deepLinkReceivedSchema,
387
- data: details.eventData,
388
- },
389
- contexts: details.contexts,
390
- });
391
- }
392
- function trackMessageNotificationEvent$2(details) {
393
- return trackSelfDescribingEvent$2({
394
- tracker: details.tracker,
395
- eventData: {
396
- schema: schemas.messageNotificationSchema,
397
- data: details.eventData,
398
- },
399
- contexts: details.contexts,
400
- });
401
- }
402
- function removeGlobalContexts$1() {
403
- return Promise.reject(new Error('Not implemented'));
404
- }
405
- function addGlobalContexts$1() {
406
- return Promise.reject(new Error('Not implemented'));
407
- }
408
- function setUserId$2(details) {
409
- trackers[details.tracker]?.setUserId(details.userId ?? '');
410
- return Promise.resolve();
411
- }
412
- function setNetworkUserId$2(details) {
413
- trackers[details.tracker]?.setNetworkUserId(details.networkUserId ?? '');
414
- return Promise.resolve();
415
- }
416
- function setDomainUserId$2(details) {
417
- trackers[details.tracker]?.setDomainUserId(details.domainUserId ?? '');
418
- return Promise.resolve();
419
- }
420
- function setIpAddress$2(details) {
421
- trackers[details.tracker]?.setIpAddress(details.ipAddress ?? '');
422
- return Promise.resolve();
423
- }
424
- function setUseragent$2(details) {
425
- trackers[details.tracker]?.setUseragent(details.useragent ?? '');
426
- return Promise.resolve();
427
- }
428
- function setTimezone$2(details) {
429
- trackers[details.tracker]?.setTimezone(details.timezone ?? '');
430
- return Promise.resolve();
431
- }
432
- function setLanguage$2(details) {
433
- trackers[details.tracker]?.setLang(details.language ?? '');
434
- return Promise.resolve();
435
- }
436
- function setScreenResolution$2(details) {
437
- if (details.screenResolution) {
438
- trackers[details.tracker]?.setScreenResolution(String(details.screenResolution[0]), String(details.screenResolution[1]));
439
- }
440
- else {
441
- trackers[details.tracker]?.addPayloadPair('res', '');
442
- }
443
- return Promise.resolve();
444
- }
445
- function setScreenViewport$2(details) {
446
- if (details.screenViewport) {
447
- trackers[details.tracker]?.setViewport(String(details.screenViewport[0]), String(details.screenViewport[1]));
448
- }
449
- else {
450
- trackers[details.tracker]?.addPayloadPair('vp', '');
451
- }
452
- return Promise.resolve();
453
- }
454
- function setColorDepth$2(details) {
455
- trackers[details.tracker]?.setColorDepth(String(details.colorDepth ?? ''));
456
- return Promise.resolve();
457
- }
458
- function getSessionUserId$1() {
459
- return Promise.reject(new Error('Not implemented'));
460
- }
461
- function getSessionId$1() {
462
- return Promise.reject(new Error('Not implemented'));
463
- }
464
- function getSessionIndex$1() {
465
- return Promise.reject(new Error('Not implemented'));
466
- }
467
- function getIsInBackground$1() {
468
- return Promise.reject(new Error('Not implemented'));
469
- }
470
- function getBackgroundIndex$1() {
471
- return Promise.reject(new Error('Not implemented'));
472
- }
473
- function getForegroundIndex$1() {
474
- return Promise.reject(new Error('Not implemented'));
475
- }
476
- const JSSnowplowTracker = Object.freeze({
477
- createTracker: createTracker$2,
478
- removeTracker: removeTracker$2,
479
- removeAllTrackers: removeAllTrackers$2,
480
- trackSelfDescribingEvent: trackSelfDescribingEvent$2,
481
- trackStructuredEvent: trackStructuredEvent$2,
482
- trackScreenViewEvent: trackScreenViewEvent$2,
483
- trackPageViewEvent: trackPageViewEvent$2,
484
- trackTimingEvent: trackTimingEvent$2,
485
- trackConsentGrantedEvent: trackConsentGrantedEvent$2,
486
- trackConsentWithdrawnEvent: trackConsentWithdrawnEvent$2,
487
- trackEcommerceTransactionEvent: trackEcommerceTransactionEvent$2,
488
- trackDeepLinkReceivedEvent: trackDeepLinkReceivedEvent$2,
489
- trackMessageNotificationEvent: trackMessageNotificationEvent$2,
490
- removeGlobalContexts: removeGlobalContexts$1,
491
- addGlobalContexts: addGlobalContexts$1,
492
- setUserId: setUserId$2,
493
- setNetworkUserId: setNetworkUserId$2,
494
- setDomainUserId: setDomainUserId$2,
495
- setIpAddress: setIpAddress$2,
496
- setUseragent: setUseragent$2,
497
- setTimezone: setTimezone$2,
498
- setLanguage: setLanguage$2,
499
- setScreenResolution: setScreenResolution$2,
500
- setScreenViewport: setScreenViewport$2,
501
- setColorDepth: setColorDepth$2,
502
- getSessionUserId: getSessionUserId$1,
503
- getSessionId: getSessionId$1,
504
- getSessionIndex: getSessionIndex$1,
505
- getIsInBackground: getIsInBackground$1,
506
- getBackgroundIndex: getBackgroundIndex$1,
507
- getForegroundIndex: getForegroundIndex$1,
508
- });
509
-
510
- /*
511
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
512
- *
513
- * This program is licensed to you under the Apache License Version 2.0,
514
- * and you may not use this file except in compliance with the Apache License Version 2.0.
515
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
516
- *
517
- * Unless required by applicable law or agreed to in writing,
518
- * software distributed under the Apache License Version 2.0 is distributed on an
519
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
520
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
521
- */
522
- const isAvailable = NativeModules.RNSnowplowTracker != null;
523
- if (!isAvailable) {
524
- errorHandler(new Error('Unable to access the native iOS/Android Snowplow tracker, a tracker implementation with very limited functionality is used.'));
525
- }
526
- const RNSnowplowTracker = isAvailable ? NativeModules.RNSnowplowTracker : JSSnowplowTracker;
527
-
528
- /*
529
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
530
- *
531
- * This program is licensed to you under the Apache License Version 2.0,
532
- * and you may not use this file except in compliance with the Apache License Version 2.0.
533
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
534
- *
535
- * Unless required by applicable law or agreed to in writing,
536
- * software distributed under the Apache License Version 2.0 is distributed on an
537
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
538
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
539
- */
540
- /**
541
- * Validates whether an object is valid self-describing
542
- *
543
- * @param sd {Object} - the object to validate
544
- * @returns - boolean
545
- */
546
- function isValidSD(sd) {
547
- return isObject(sd)
548
- && typeof sd.schema === 'string'
549
- && isObject(sd.data);
550
- }
551
- /**
552
- * Validates whether an object is a valid array of contexts
553
- *
554
- * @param contexts {Object} - the object to validate
555
- * @returns - boolean promise
556
- */
557
- function validateContexts(contexts) {
558
- const isValid = Object.prototype.toString.call(contexts) === '[object Array]'
559
- && contexts
560
- .map((c) => isValidSD(c))
561
- .reduce((acc, curr) => acc !== false && curr, true);
562
- if (!isValid) {
563
- return Promise.reject(new Error(logMessages.context));
564
- }
565
- return Promise.resolve(true);
566
- }
567
- /**
568
- * Validates whether an object is valid self describing
569
- *
570
- * @param argmap {Object} - the object to validate
571
- * @returns - boolean promise
572
- */
573
- function validateSelfDesc(argmap) {
574
- if (!isValidSD(argmap)) {
575
- return Promise.reject(new Error(logMessages.selfDesc));
576
- }
577
- return Promise.resolve(true);
578
- }
579
- /**
580
- * Validates a screen view event
581
- *
582
- * @param argmap {Object} - the object to validate
583
- * @returns - boolean promise
584
- */
585
- function validateScreenView(argmap) {
586
- // validate type
587
- if (!isObject(argmap)) {
588
- return Promise.reject(new Error(logMessages.evType));
589
- }
590
- // validate required props
591
- if (typeof argmap.name !== 'string') {
592
- return Promise.reject(new Error(logMessages.screenViewReq));
593
- }
594
- return Promise.resolve(true);
595
- }
596
- /**
597
- * Validates a structured event
598
- *
599
- * @param argmap {Object} - the object to validate
600
- * @returns - boolean promise
601
- */
602
- function validateStructured(argmap) {
603
- // validate type
604
- if (!isObject(argmap)) {
605
- return Promise.reject(new Error(logMessages.evType));
606
- }
607
- // validate required props
608
- if (typeof argmap.category !== 'string'
609
- || typeof argmap.action !== 'string') {
610
- return Promise.reject(new Error(logMessages.structuredReq));
611
- }
612
- return Promise.resolve(true);
613
- }
614
- /**
615
- * Validates a page-view event
616
- *
617
- * @param argmap {Object} - the object to validate
618
- * @returns - boolean promise
619
- */
620
- function validatePageView(argmap) {
621
- // validate type
622
- if (!isObject(argmap)) {
623
- return Promise.reject(new Error(logMessages.evType));
624
- }
625
- // validate required props
626
- if (typeof argmap.pageUrl !== 'string') {
627
- return Promise.reject(new Error(logMessages.pageviewReq));
628
- }
629
- return Promise.resolve(true);
630
- }
631
- /**
632
- * Validates a timing event
633
- *
634
- * @param argmap {Object} - the object to validate
635
- * @returns - boolean promise
636
- */
637
- function validateTiming(argmap) {
638
- // validate type
639
- if (!isObject(argmap)) {
640
- return Promise.reject(new Error(logMessages.evType));
641
- }
642
- // validate required props
643
- if (typeof argmap.category !== 'string'
644
- || typeof argmap.variable !== 'string'
645
- || typeof argmap.timing !== 'number') {
646
- return Promise.reject(new Error(logMessages.timingReq));
647
- }
648
- return Promise.resolve(true);
649
- }
650
- /**
651
- * Validates a consent-granted event
652
- *
653
- * @param argmap {Object} - the object to validate
654
- * @returns - boolean promise
655
- */
656
- function validateConsentGranted(argmap) {
657
- // validate type
658
- if (!isObject(argmap)) {
659
- return Promise.reject(new Error(logMessages.evType));
660
- }
661
- // validate required props
662
- if (typeof argmap.expiry !== 'string'
663
- || typeof argmap.documentId !== 'string'
664
- || typeof argmap.version !== 'string') {
665
- return Promise.reject(new Error(logMessages.consentGReq));
666
- }
667
- return Promise.resolve(true);
668
- }
669
- /**
670
- * Validates a consent-withdrawn event
671
- *
672
- * @param argmap {Object} - the object to validate
673
- * @returns - boolean promise
674
- */
675
- function validateConsentWithdrawn(argmap) {
676
- // validate type
677
- if (!isObject(argmap)) {
678
- return Promise.reject(new Error(logMessages.evType));
679
- }
680
- // validate required props
681
- if (typeof argmap.all !== 'boolean'
682
- || typeof argmap.documentId !== 'string'
683
- || typeof argmap.version !== 'string') {
684
- return Promise.reject(new Error(logMessages.consentWReq));
685
- }
686
- return Promise.resolve(true);
687
- }
688
- /**
689
- * Validates a deep link received event
690
- *
691
- * @param argmap {Object} - the object to validate
692
- * @returns - boolean promise
693
- */
694
- function validateDeepLinkReceived(argmap) {
695
- // validate type
696
- if (!isObject(argmap)) {
697
- return Promise.reject(new Error(logMessages.evType));
698
- }
699
- // validate required props
700
- if (typeof argmap.url !== 'string') {
701
- return Promise.reject(new Error(logMessages.deepLinkReq));
702
- }
703
- return Promise.resolve(true);
704
- }
705
- /**
706
- * Validates a message notification event
707
- *
708
- * @param argmap {Object} - the object to validate
709
- * @returns - boolean promise
710
- */
711
- function validateMessageNotification(argmap) {
712
- // validate type
713
- if (!isObject(argmap)) {
714
- return Promise.reject(new Error(logMessages.evType));
715
- }
716
- // validate required props
717
- if (typeof argmap.title !== 'string'
718
- || typeof argmap.body !== 'string'
719
- || typeof argmap.trigger !== 'string'
720
- || !['push', 'location', 'calendar', 'timeInterval', 'other'].includes(argmap.trigger)) {
721
- return Promise.reject(new Error(logMessages.messageNotificationReq));
722
- }
723
- return Promise.resolve(true);
724
- }
725
- /**
726
- * Validates whether an object is valid ecommerce-item
727
- *
728
- * @param item {Object} - the object to validate
729
- * @returns - boolean
730
- */
731
- function isValidEcomItem(item) {
732
- if (isObject(item)
733
- && typeof item.sku === 'string'
734
- && typeof item.price === 'number'
735
- && typeof item.quantity === 'number') {
736
- return true;
737
- }
738
- return false;
739
- }
740
- /**
741
- * Validates an array of ecommerce-items
742
- *
743
- * @param items {Object} - the object to validate
744
- * @returns - boolean promise
745
- */
746
- function validItemsArg(items) {
747
- return Object.prototype.toString.call(items) === '[object Array]'
748
- && items
749
- .map((i) => isValidEcomItem(i))
750
- .reduce((acc, curr) => acc !== false && curr, true);
751
- }
752
- /**
753
- * Validates an ecommerce-transaction event
754
- *
755
- * @param argmap {Object} - the object to validate
756
- * @returns - boolean promise
757
- */
758
- function validateEcommerceTransaction(argmap) {
759
- // validate type
760
- if (!isObject(argmap)) {
761
- return Promise.reject(new Error(logMessages.evType));
762
- }
763
- // validate required props
764
- if (typeof argmap.orderId !== 'string'
765
- || typeof argmap.totalValue !== 'number'
766
- || !validItemsArg(argmap.items)) {
767
- return Promise.reject(new Error(logMessages.ecomReq));
768
- }
769
- return Promise.resolve(true);
770
- }
771
-
772
- /*
773
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
774
- *
775
- * This program is licensed to you under the Apache License Version 2.0,
776
- * and you may not use this file except in compliance with the Apache License Version 2.0.
777
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
778
- *
779
- * Unless required by applicable law or agreed to in writing,
780
- * software distributed under the Apache License Version 2.0 is distributed on an
781
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
782
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
783
- */
784
- /**
785
- * Configuration properties
786
- */
787
- const networkProps = [
788
- 'endpoint',
789
- 'method',
790
- 'customPostPath',
791
- 'requestHeaders',
792
- ];
793
- const trackerProps = [
794
- 'appId',
795
- 'devicePlatform',
796
- 'base64Encoding',
797
- 'logLevel',
798
- 'applicationContext',
799
- 'platformContext',
800
- 'geoLocationContext',
801
- 'sessionContext',
802
- 'deepLinkContext',
803
- 'screenContext',
804
- 'screenViewAutotracking',
805
- 'lifecycleAutotracking',
806
- 'installAutotracking',
807
- 'exceptionAutotracking',
808
- 'diagnosticAutotracking',
809
- 'userAnonymisation'
810
- ];
811
- const sessionProps = [
812
- 'foregroundTimeout',
813
- 'backgroundTimeout'
814
- ];
815
- const emitterProps = [
816
- 'bufferOption',
817
- 'emitRange',
818
- 'threadPoolSize',
819
- 'byteLimitPost',
820
- 'byteLimitGet',
821
- 'serverAnonymisation',
822
- ];
823
- const subjectProps = [
824
- 'userId',
825
- 'networkUserId',
826
- 'domainUserId',
827
- 'useragent',
828
- 'ipAddress',
829
- 'timezone',
830
- 'language',
831
- 'screenResolution',
832
- 'screenViewport',
833
- 'colorDepth'
834
- ];
835
- const gdprProps = [
836
- 'basisForProcessing',
837
- 'documentId',
838
- 'documentVersion',
839
- 'documentDescription'
840
- ];
841
- const gcProps = [
842
- 'tag',
843
- 'globalContexts'
844
- ];
845
- /**
846
- * Validates whether an object is of valid configuration given its default keys
847
- *
848
- * @param config {Object} - the object to validate
849
- * @param defaultKeys {Array} - the default keys to validate against
850
- * @returns - boolean
851
- */
852
- function isValidConfig(config, defaultKeys) {
853
- return Object.keys(config).every(key => defaultKeys.includes(key));
854
- }
855
- /**
856
- * Validates the networkConfig
857
- *
858
- * @param config {Object} - the config to validate
859
- * @returns - boolean
860
- */
861
- function isValidNetworkConf(config) {
862
- if (!isObject(config)
863
- || !isValidConfig(config, networkProps)
864
- || typeof config.endpoint !== 'string'
865
- || !config.endpoint) {
866
- return false;
867
- }
868
- return true;
869
- }
870
- /**
871
- * Validates the trackerConfig
872
- *
873
- * @param config {Object} - the config to validate
874
- * @returns - boolean
875
- */
876
- function isValidTrackerConf(config) {
877
- if (!isObject(config) || !isValidConfig(config, trackerProps)) {
878
- return false;
879
- }
880
- return true;
881
- }
882
- /**
883
- * Validates the sessionConfig
884
- *
885
- * @param config {Object} - the config to validate
886
- * @returns - boolean
887
- */
888
- function isValidSessionConf(config) {
889
- if (!isObject(config)
890
- || !isValidConfig(config, sessionProps)
891
- || !sessionProps.every(key => Object.keys(config).includes(key))) {
892
- return false;
893
- }
894
- return true;
895
- }
896
- /**
897
- * Validates the emitterConfig
898
- *
899
- * @param config {Object} - the config to validate
900
- * @returns - boolean
901
- */
902
- function isValidEmitterConf(config) {
903
- if (!isObject(config) || !isValidConfig(config, emitterProps)) {
904
- return false;
905
- }
906
- return true;
907
- }
908
- /**
909
- * Validates whether an object is of ScreenSize type
910
- *
911
- * @param arr {Object} - the object to validate
912
- * @returns - boolean
913
- */
914
- function isScreenSize(arr) {
915
- return Array.isArray(arr)
916
- && arr.length === 2
917
- && arr.every((n) => typeof n === 'number');
918
- }
919
- /**
920
- * Validates the subjectConfig
921
- *
922
- * @param config {Object} - the config to validate
923
- * @returns - boolean
924
- */
925
- function isValidSubjectConf(config) {
926
- if (!isObject(config) || !isValidConfig(config, subjectProps)) {
927
- return false;
928
- }
929
- // validating ScreenSize here to simplify array handling in bridge
930
- if (Object.prototype.hasOwnProperty.call(config, 'screenResolution')
931
- && config.screenResolution !== null
932
- && !isScreenSize(config.screenResolution)) {
933
- return false;
934
- }
935
- if (Object.prototype.hasOwnProperty.call(config, 'screenViewport')
936
- && config.screenViewport !== null
937
- && !isScreenSize(config.screenViewport)) {
938
- return false;
939
- }
940
- return true;
941
- }
942
- /**
943
- * Validates the gdprConfig
944
- *
945
- * @param config {Object} - the config to validate
946
- * @returns - boolean
947
- */
948
- function isValidGdprConf(config) {
949
- if (!isObject(config)
950
- || !isValidConfig(config, gdprProps)
951
- || !gdprProps.every(key => Object.keys(config).includes(key))
952
- || !['consent', 'contract', 'legal_obligation', 'legitimate_interests', 'public_task', 'vital_interests'].includes(config.basisForProcessing)) {
953
- return false;
954
- }
955
- return true;
956
- }
957
- /**
958
- * Validates whether an object is of GlobalContext type
959
- *
960
- * @param gc {Object} - the object to validate
961
- * @returns - boolean
962
- */
963
- function isValidGC(gc) {
964
- return isObject(gc)
965
- && isValidConfig(gc, gcProps)
966
- && typeof gc.tag === 'string'
967
- && Array.isArray(gc.globalContexts)
968
- && gc.globalContexts.every(c => isValidSD(c));
969
- }
970
- /**
971
- * Validates the GCConfig (global contexts)
972
- *
973
- * @param config {Object} - the config to validate
974
- * @returns - boolean
975
- */
976
- function isValidGCConf(config) {
977
- if (!Array.isArray(config)) {
978
- return false;
979
- }
980
- if (!config.every(gc => isValidGC(gc))) {
981
- return false;
982
- }
983
- return true;
984
- }
985
- /**
986
- * Validates the initTrackerConfiguration
987
- *
988
- * @param init {Object} - the config to validate
989
- * @returns - boolean promise
990
- */
991
- function initValidate(init) {
992
- if (typeof init.namespace !== 'string' || !init.namespace) {
993
- return Promise.reject(new Error(logMessages.namespace));
994
- }
995
- if (!Object.prototype.hasOwnProperty.call(init, 'networkConfig')
996
- || !isValidNetworkConf(init.networkConfig)) {
997
- return Promise.reject(new Error(logMessages.network));
998
- }
999
- if (Object.prototype.hasOwnProperty.call(init, 'trackerConfig')
1000
- && !isValidTrackerConf(init.trackerConfig)) {
1001
- return Promise.reject(new Error(logMessages.tracker));
1002
- }
1003
- if (Object.prototype.hasOwnProperty.call(init, 'sessionConfig')
1004
- && (!isValidSessionConf(init.sessionConfig))) {
1005
- return Promise.reject(new Error(logMessages.session));
1006
- }
1007
- if (Object.prototype.hasOwnProperty.call(init, 'emitterConfig')
1008
- && !isValidEmitterConf(init.emitterConfig)) {
1009
- return Promise.reject(new Error(logMessages.emitter));
1010
- }
1011
- if (Object.prototype.hasOwnProperty.call(init, 'subjectConfig')
1012
- && !isValidSubjectConf(init.subjectConfig)) {
1013
- return Promise.reject(new Error(logMessages.subject));
1014
- }
1015
- if (Object.prototype.hasOwnProperty.call(init, 'gdprConfig')
1016
- && !isValidGdprConf(init.gdprConfig)) {
1017
- return Promise.reject(new Error(logMessages.gdpr));
1018
- }
1019
- if (Object.prototype.hasOwnProperty.call(init, 'gcConfig')
1020
- && !isValidGCConf(init.gcConfig)) {
1021
- return Promise.reject(new Error(logMessages.gc));
1022
- }
1023
- return Promise.resolve(true);
1024
- }
1025
-
1026
- /*
1027
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
1028
- *
1029
- * This program is licensed to you under the Apache License Version 2.0,
1030
- * and you may not use this file except in compliance with the Apache License Version 2.0.
1031
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
1032
- *
1033
- * Unless required by applicable law or agreed to in writing,
1034
- * software distributed under the Apache License Version 2.0 is distributed on an
1035
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1036
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1037
- */
1038
- /**
1039
- * Tracks a self-describing event
1040
- *
1041
- * @param namespace {string} - the tracker namespace
1042
- * @param argmap {Object} - the event data
1043
- * @param contexts {Array}- the event contexts
1044
- * @returns {Promise}
1045
- */
1046
- function trackSelfDescribingEvent$1(namespace, argmap, contexts = []) {
1047
- return validateSelfDesc(argmap)
1048
- .then(() => validateContexts(contexts))
1049
- .then(() => RNSnowplowTracker.trackSelfDescribingEvent({
1050
- tracker: namespace,
1051
- eventData: argmap,
1052
- contexts: contexts
1053
- }))
1054
- .catch((error) => {
1055
- throw new Error(`${logMessages.trackSelfDesc} ${error.message}`);
1056
- });
1057
- }
1058
- /**
1059
- * Tracks a screen-view event
1060
- *
1061
- * @param namespace {string} - the tracker namespace
1062
- * @param argmap {Object} - the event data
1063
- * @param contexts {Array}- the event contexts
1064
- * @returns {Promise}
1065
- */
1066
- function trackScreenViewEvent$1(namespace, argmap, contexts = []) {
1067
- return validateScreenView(argmap)
1068
- .then(() => validateContexts(contexts))
1069
- .then(() => RNSnowplowTracker.trackScreenViewEvent({
1070
- tracker: namespace,
1071
- eventData: argmap,
1072
- contexts: contexts
1073
- }))
1074
- .catch((error) => {
1075
- throw new Error(`${logMessages.trackScreenView} ${error.message}`);
1076
- });
1077
- }
1078
- /**
1079
- * Tracks a structured event
1080
- *
1081
- * @param namespace {string} - the tracker namespace
1082
- * @param argmap {Object} - the event data
1083
- * @param contexts {Array}- the event contexts
1084
- * @returns {Promise}
1085
- */
1086
- function trackStructuredEvent$1(namespace, argmap, contexts = []) {
1087
- return validateStructured(argmap)
1088
- .then(() => validateContexts(contexts))
1089
- .then(() => RNSnowplowTracker.trackStructuredEvent({
1090
- tracker: namespace,
1091
- eventData: argmap,
1092
- contexts: contexts
1093
- }))
1094
- .catch((error) => {
1095
- throw new Error(`${logMessages.trackStructured} ${error.message}`);
1096
- });
1097
- }
1098
- /**
1099
- * Tracks a page-view event
1100
- *
1101
- * @param namespace {string} - the tracker namespace
1102
- * @param argmap {Object} - the event data
1103
- * @param contexts {Array}- the event contexts
1104
- * @returns {Promise}
1105
- */
1106
- function trackPageViewEvent$1(namespace, argmap, contexts = []) {
1107
- return validatePageView(argmap)
1108
- .then(() => validateContexts(contexts))
1109
- .then(() => RNSnowplowTracker.trackPageViewEvent({
1110
- tracker: namespace,
1111
- eventData: argmap,
1112
- contexts: contexts
1113
- }))
1114
- .catch((error) => {
1115
- throw new Error(`${logMessages.trackPageView} ${error.message}`);
1116
- });
1117
- }
1118
- /**
1119
- * Tracks a timing event
1120
- *
1121
- * @param namespace {string} - the tracker namespace
1122
- * @param argmap {Object} - the event data
1123
- * @param contexts {Array}- the event contexts
1124
- * @returns {Promise}
1125
- */
1126
- function trackTimingEvent$1(namespace, argmap, contexts = []) {
1127
- return validateTiming(argmap)
1128
- .then(() => validateContexts(contexts))
1129
- .then(() => RNSnowplowTracker.trackTimingEvent({
1130
- tracker: namespace,
1131
- eventData: argmap,
1132
- contexts: contexts
1133
- }))
1134
- .catch((error) => {
1135
- throw new Error(`${logMessages.trackTiming} ${error.message}`);
1136
- });
1137
- }
1138
- /**
1139
- * Tracks a consent-granted event
1140
- *
1141
- * @param namespace {string} - the tracker namespace
1142
- * @param argmap {Object} - the event data
1143
- * @param contexts {Array}- the event contexts
1144
- * @returns {Promise}
1145
- */
1146
- function trackConsentGrantedEvent$1(namespace, argmap, contexts = []) {
1147
- return validateConsentGranted(argmap)
1148
- .then(() => validateContexts(contexts))
1149
- .then(() => RNSnowplowTracker.trackConsentGrantedEvent({
1150
- tracker: namespace,
1151
- eventData: argmap,
1152
- contexts: contexts
1153
- }))
1154
- .catch((error) => {
1155
- throw new Error(`${logMessages.trackConsentGranted} ${error.message}`);
1156
- });
1157
- }
1158
- /**
1159
- * Tracks a consent-withdrawn event
1160
- *
1161
- * @param namespace {string} - the tracker namespace
1162
- * @param argmap {Object} - the event data
1163
- * @param contexts {Array}- the event contexts
1164
- * @returns {Promise}
1165
- */
1166
- function trackConsentWithdrawnEvent$1(namespace, argmap, contexts = []) {
1167
- return validateConsentWithdrawn(argmap)
1168
- .then(() => validateContexts(contexts))
1169
- .then(() => RNSnowplowTracker.trackConsentWithdrawnEvent({
1170
- tracker: namespace,
1171
- eventData: argmap,
1172
- contexts: contexts
1173
- }))
1174
- .catch((error) => {
1175
- throw new Error(`${logMessages.trackConsentWithdrawn} ${error.message}`);
1176
- });
1177
- }
1178
- /**
1179
- * Tracks an ecommerce-transaction event
1180
- *
1181
- * @param namespace {string} - the tracker namespace
1182
- * @param argmap {Object} - the event data
1183
- * @param contexts {Array}- the event contexts
1184
- * @returns {Promise}
1185
- */
1186
- function trackEcommerceTransactionEvent$1(namespace, argmap, contexts = []) {
1187
- return validateEcommerceTransaction(argmap)
1188
- .then(() => validateContexts(contexts))
1189
- .then(() => RNSnowplowTracker.trackEcommerceTransactionEvent({
1190
- tracker: namespace,
1191
- eventData: argmap,
1192
- contexts: contexts
1193
- }))
1194
- .catch((error) => {
1195
- throw new Error(`${logMessages.trackEcommerceTransaction} ${error.message}`);
1196
- });
1197
- }
1198
- /**
1199
- * Tracks a deep link received event
1200
- *
1201
- * @param namespace {string} - the tracker namespace
1202
- * @param argmap {Object} - the event data
1203
- * @param contexts {Array}- the event contexts
1204
- * @returns {Promise}
1205
- */
1206
- function trackDeepLinkReceivedEvent$1(namespace, argmap, contexts = []) {
1207
- return validateDeepLinkReceived(argmap)
1208
- .then(() => validateContexts(contexts))
1209
- .then(() => RNSnowplowTracker.trackDeepLinkReceivedEvent({
1210
- tracker: namespace,
1211
- eventData: argmap,
1212
- contexts: contexts
1213
- }))
1214
- .catch((error) => {
1215
- throw new Error(`${logMessages.trackDeepLinkReceived} ${error.message}`);
1216
- });
1217
- }
1218
- /**
1219
- * Tracks a message notification event
1220
- *
1221
- * @param namespace {string} - the tracker namespace
1222
- * @param argmap {Object} - the event data
1223
- * @param contexts {Array}- the event contexts
1224
- * @returns {Promise}
1225
- */
1226
- function trackMessageNotificationEvent$1(namespace, argmap, contexts = []) {
1227
- return validateMessageNotification(argmap)
1228
- .then(() => validateContexts(contexts))
1229
- .then(() => RNSnowplowTracker.trackMessageNotificationEvent({
1230
- tracker: namespace,
1231
- eventData: argmap,
1232
- contexts: contexts
1233
- }))
1234
- .catch((error) => {
1235
- throw new Error(`${logMessages.trackMessageNotification} ${error.message}`);
1236
- });
1237
- }
1238
-
1239
- /*
1240
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
1241
- *
1242
- * This program is licensed to you under the Apache License Version 2.0,
1243
- * and you may not use this file except in compliance with the Apache License Version 2.0.
1244
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
1245
- *
1246
- * Unless required by applicable law or agreed to in writing,
1247
- * software distributed under the Apache License Version 2.0 is distributed on an
1248
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1249
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1250
- */
1251
- /**
1252
- * Sets the userId of the tracker subject
1253
- *
1254
- * @param namespace {string} - the tracker namespace
1255
- * @param newUid {string | null} - the new userId
1256
- * @returns - Promise
1257
- */
1258
- function setUserId$1(namespace, newUid) {
1259
- if (!(newUid === null || typeof newUid === 'string')) {
1260
- return Promise.reject(new Error(logMessages.setUserId));
1261
- }
1262
- return Promise.resolve(RNSnowplowTracker.setUserId({
1263
- tracker: namespace,
1264
- userId: newUid
1265
- }));
1266
- }
1267
- /**
1268
- * Sets the networkUserId of the tracker subject
1269
- *
1270
- * @param namespace {string} - the tracker namespace
1271
- * @param newNuid {string | null} - the new networkUserId
1272
- * @returns - Promise
1273
- */
1274
- function setNetworkUserId$1(namespace, newNuid) {
1275
- if (!(newNuid === null || typeof newNuid === 'string')) {
1276
- return Promise.reject(new Error(logMessages.setNetworkUserId));
1277
- }
1278
- return Promise.resolve(RNSnowplowTracker.setNetworkUserId({
1279
- tracker: namespace,
1280
- networkUserId: newNuid
1281
- }));
1282
- }
1283
- /**
1284
- * Sets the domainUserId of the tracker subject
1285
- *
1286
- * @param namespace {string} - the tracker namespace
1287
- * @param newDuid {string | null} - the new domainUserId
1288
- * @returns - Promise
1289
- */
1290
- function setDomainUserId$1(namespace, newDuid) {
1291
- if (!(newDuid === null || typeof newDuid === 'string')) {
1292
- return Promise.reject(new Error(logMessages.setDomainUserId));
1293
- }
1294
- return Promise.resolve(RNSnowplowTracker.setDomainUserId({
1295
- tracker: namespace,
1296
- domainUserId: newDuid
1297
- }));
1298
- }
1299
- /**
1300
- * Sets the ipAddress of the tracker subject
1301
- *
1302
- * @param namespace {string} - the tracker namespace
1303
- * @param newIp {string | null} - the new ipAddress
1304
- * @returns - Promise
1305
- */
1306
- function setIpAddress$1(namespace, newIp) {
1307
- if (!(newIp === null || typeof newIp === 'string')) {
1308
- return Promise.reject(new Error(logMessages.setIpAddress));
1309
- }
1310
- return Promise.resolve(RNSnowplowTracker.setIpAddress({
1311
- tracker: namespace,
1312
- ipAddress: newIp
1313
- }));
1314
- }
1315
- /**
1316
- * Sets the useragent of the tracker subject
1317
- *
1318
- * @param namespace {string} - the tracker namespace
1319
- * @param newUagent {string | null} - the new useragent
1320
- * @returns - Promise
1321
- */
1322
- function setUseragent$1(namespace, newUagent) {
1323
- if (!(newUagent === null || typeof newUagent === 'string')) {
1324
- return Promise.reject(new Error(logMessages.setUseragent));
1325
- }
1326
- return Promise.resolve(RNSnowplowTracker.setUseragent({
1327
- tracker: namespace,
1328
- useragent: newUagent
1329
- }));
1330
- }
1331
- /**
1332
- * Sets the timezone of the tracker subject
1333
- *
1334
- * @param namespace {string} - the tracker namespace
1335
- * @param newTz {string | null} - the new timezone
1336
- * @returns - Promise
1337
- */
1338
- function setTimezone$1(namespace, newTz) {
1339
- if (!(newTz === null || typeof newTz === 'string')) {
1340
- return Promise.reject(new Error(logMessages.setTimezone));
1341
- }
1342
- return Promise.resolve(RNSnowplowTracker.setTimezone({
1343
- tracker: namespace,
1344
- timezone: newTz
1345
- }));
1346
- }
1347
- /**
1348
- * Sets the language of the tracker subject
1349
- *
1350
- * @param namespace {string} - the tracker namespace
1351
- * @param newLang {string | null} - the new language
1352
- * @returns - Promise
1353
- */
1354
- function setLanguage$1(namespace, newLang) {
1355
- if (!(newLang === null || typeof newLang === 'string')) {
1356
- return Promise.reject(new Error(logMessages.setLanguage));
1357
- }
1358
- return Promise.resolve(RNSnowplowTracker.setLanguage({
1359
- tracker: namespace,
1360
- language: newLang
1361
- }));
1362
- }
1363
- /**
1364
- * Sets the screenResolution of the tracker subject
1365
- *
1366
- * @param namespace {string} - the tracker namespace
1367
- * @param newRes {ScreenSize | null} - the new screenResolution
1368
- * @returns - Promise
1369
- */
1370
- function setScreenResolution$1(namespace, newRes) {
1371
- if (!(newRes === null || isScreenSize(newRes))) {
1372
- return Promise.reject(new Error(logMessages.setScreenResolution));
1373
- }
1374
- return Promise.resolve(RNSnowplowTracker.setScreenResolution({
1375
- tracker: namespace,
1376
- screenResolution: newRes
1377
- }));
1378
- }
1379
- /**
1380
- * Sets the screenViewport of the tracker subject
1381
- *
1382
- * @param namespace {string} - the tracker namespace
1383
- * @param newView {ScreenSize | null} - the new screenViewport
1384
- * @returns - Promise
1385
- */
1386
- function setScreenViewport$1(namespace, newView) {
1387
- if (!(newView === null || isScreenSize(newView))) {
1388
- return Promise.reject(new Error(logMessages.setScreenViewport));
1389
- }
1390
- return Promise.resolve(RNSnowplowTracker.setScreenViewport({
1391
- tracker: namespace,
1392
- screenViewport: newView
1393
- }));
1394
- }
1395
- /**
1396
- * Sets the colorDepth of the tracker subject
1397
- *
1398
- * @param namespace {string} - the tracker namespace
1399
- * @param newColorD {number | null} - the new colorDepth
1400
- * @returns - Promise
1401
- */
1402
- function setColorDepth$1(namespace, newColorD) {
1403
- if (!(newColorD === null || typeof newColorD === 'number')) {
1404
- return Promise.reject(new Error(logMessages.setColorDepth));
1405
- }
1406
- return Promise.resolve(RNSnowplowTracker.setColorDepth({
1407
- tracker: namespace,
1408
- colorDepth: newColorD
1409
- }));
1410
- }
1411
- const setterMap = {
1412
- userId: setUserId$1,
1413
- networkUserId: setNetworkUserId$1,
1414
- domainUserId: setDomainUserId$1,
1415
- ipAddress: setIpAddress$1,
1416
- useragent: setUseragent$1,
1417
- timezone: setTimezone$1,
1418
- language: setLanguage$1,
1419
- screenResolution: setScreenResolution$1,
1420
- screenViewport: setScreenViewport$1,
1421
- colorDepth: setColorDepth$1
1422
- };
1423
- /**
1424
- * Sets the tracker subject
1425
- *
1426
- * @param namespace {string} - the tracker namespace
1427
- * @param config {SubjectConfiguration} - the new subject data
1428
- * @returns - Promise
1429
- */
1430
- function setSubjectData$1(namespace, config) {
1431
- if (!isValidSubjectConf(config)) {
1432
- return Promise.reject(new Error(`${logMessages.setSubjectData} ${logMessages.subject}`));
1433
- }
1434
- const promises = Object.keys(config)
1435
- .map((k) => {
1436
- const fun = setterMap[k];
1437
- return fun ? fun(namespace, config[k]) : undefined;
1438
- })
1439
- .filter((f) => f !== undefined);
1440
- // to use Promise.all (Promise.allSettled not supported in all RN versions)
1441
- const safePromises = promises
1442
- .map((p) => p
1443
- .then((x) => Object.assign({
1444
- status: 'fulfilled',
1445
- value: x
1446
- }))
1447
- .catch((err) => Object.assign({
1448
- status: 'rejected',
1449
- reason: err.message
1450
- })));
1451
- return Promise.all(safePromises).then((outcomes) => {
1452
- const anyReasons = outcomes.filter((res) => res.status === 'rejected');
1453
- if (anyReasons.length > 0) {
1454
- const allReasons = anyReasons
1455
- .reduce((acc, curr) => acc + ':' + curr.reason, logMessages.setSubjectData);
1456
- throw new Error(allReasons);
1457
- }
1458
- return true;
1459
- });
1460
- }
1461
-
1462
- /*
1463
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
1464
- *
1465
- * This program is licensed to you under the Apache License Version 2.0,
1466
- * and you may not use this file except in compliance with the Apache License Version 2.0.
1467
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
1468
- *
1469
- * Unless required by applicable law or agreed to in writing,
1470
- * software distributed under the Apache License Version 2.0 is distributed on an
1471
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1472
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1473
- */
1474
- /**
1475
- * Create a tracker from specified initial configuration.
1476
- *
1477
- * @param initConfig {Object} - The initial tracker configuration
1478
- * @returns - A promise fullfilled if the tracker is initialized
1479
- */
1480
- function createTracker$1(initConfig) {
1481
- return initValidate(initConfig)
1482
- .then(() => RNSnowplowTracker.createTracker(initConfig))
1483
- .catch((error) => {
1484
- throw new Error(`${logMessages.createTracker} ${error.message}.`);
1485
- });
1486
- }
1487
- /**
1488
- * Removes the tracker with given namespace
1489
- *
1490
- * @param trackerNamespace {string} - The tracker namespace
1491
- * @returns - A boolean promise
1492
- */
1493
- function removeTracker$1(trackerNamespace) {
1494
- if (typeof trackerNamespace !== 'string') {
1495
- return Promise.reject(new Error(logMessages.removeTracker));
1496
- }
1497
- return Promise.resolve(RNSnowplowTracker.removeTracker({ tracker: trackerNamespace }));
1498
- }
1499
- /**
1500
- * Removes all existing trackers
1501
- *
1502
- * @returns - A void promise
1503
- */
1504
- function removeAllTrackers$1() {
1505
- return Promise.resolve(RNSnowplowTracker.removeAllTrackers());
1506
- }
1507
- /**
1508
- * Returns a function to track a SelfDescribing event by a tracker
1509
- *
1510
- * @param namespace {string} - The tracker namespace
1511
- * @returns - A function to track a SelfDescribing event
1512
- */
1513
- function trackSelfDescribingEvent(namespace) {
1514
- return function (argmap, contexts = []) {
1515
- return trackSelfDescribingEvent$1(namespace, argmap, contexts);
1516
- };
1517
- }
1518
- /**
1519
- * Returns a function to track a ScreenView event by a tracker
1520
- *
1521
- * @param namespace {string} - The tracker namespace
1522
- * @returns - A function to track a ScreenView event
1523
- */
1524
- function trackScreenViewEvent(namespace) {
1525
- return function (argmap, contexts = []) {
1526
- return trackScreenViewEvent$1(namespace, argmap, contexts);
1527
- };
1528
- }
1529
- /**
1530
- * Returns a function to track a Structured event by a tracker
1531
- *
1532
- * @param namespace {string} - The tracker namespace
1533
- * @returns - A function to track a Structured event
1534
- */
1535
- function trackStructuredEvent(namespace) {
1536
- return function (argmap, contexts = []) {
1537
- return trackStructuredEvent$1(namespace, argmap, contexts);
1538
- };
1539
- }
1540
- /**
1541
- * Returns a function to track a PageView event by a tracker
1542
- *
1543
- * @param namespace {string} - The tracker namespace
1544
- * @returns - A function to track a PageView event
1545
- */
1546
- function trackPageViewEvent(namespace) {
1547
- return function (argmap, contexts = []) {
1548
- return trackPageViewEvent$1(namespace, argmap, contexts);
1549
- };
1550
- }
1551
- /**
1552
- * Returns a function to track a Timing event by a tracker
1553
- *
1554
- * @param namespace {string} - The tracker namespace
1555
- * @returns - A function to track a Timing event
1556
- */
1557
- function trackTimingEvent(namespace) {
1558
- return function (argmap, contexts = []) {
1559
- return trackTimingEvent$1(namespace, argmap, contexts);
1560
- };
1561
- }
1562
- /**
1563
- * Returns a function to track a ConsentGranted event by a tracker
1564
- *
1565
- * @param namespace {string} - The tracker namespace
1566
- * @returns - A function to track a ConsentGranted event
1567
- */
1568
- function trackConsentGrantedEvent(namespace) {
1569
- return function (argmap, contexts = []) {
1570
- return trackConsentGrantedEvent$1(namespace, argmap, contexts);
1571
- };
1572
- }
1573
- /**
1574
- * Returns a function to track a ConsentWithdrawn event by a tracker
1575
- *
1576
- * @param namespace {string} - The tracker namespace
1577
- * @returns - A function to track a ConsentWithdrawn event
1578
- */
1579
- function trackConsentWithdrawnEvent(namespace) {
1580
- return function (argmap, contexts = []) {
1581
- return trackConsentWithdrawnEvent$1(namespace, argmap, contexts);
1582
- };
1583
- }
1584
- /**
1585
- * Returns a function to track an EcommerceTransaction event by a tracker
1586
- *
1587
- * @param namespace {string} - The tracker namespace
1588
- * @returns - A function to track an EcommerceTransaction event
1589
- */
1590
- function trackEcommerceTransactionEvent(namespace) {
1591
- return function (argmap, contexts = []) {
1592
- return trackEcommerceTransactionEvent$1(namespace, argmap, contexts);
1593
- };
1594
- }
1595
- /**
1596
- * Returns a function to track an DeepLinkReceived event by a tracker
1597
- *
1598
- * @param namespace {string} - The tracker namespace
1599
- * @returns - A function to track an DeepLinkReceived event
1600
- */
1601
- function trackDeepLinkReceivedEvent(namespace) {
1602
- return function (argmap, contexts = []) {
1603
- return trackDeepLinkReceivedEvent$1(namespace, argmap, contexts);
1604
- };
1605
- }
1606
- /**
1607
- * Returns a function to track an MessageNotification event by a tracker
1608
- *
1609
- * @param namespace {string} - The tracker namespace
1610
- * @returns - A function to track an MessageNotification event
1611
- */
1612
- function trackMessageNotificationEvent(namespace) {
1613
- return function (argmap, contexts = []) {
1614
- return trackMessageNotificationEvent$1(namespace, argmap, contexts);
1615
- };
1616
- }
1617
- /**
1618
- * Returns a function to remove global contexts by a tracker
1619
- *
1620
- * @param namespace {string} - The tracker namespace
1621
- * @returns - A function to remove global contexts
1622
- */
1623
- function removeGlobalContexts(namespace) {
1624
- return function (tag) {
1625
- if (typeof tag !== 'string') {
1626
- return Promise.reject(new Error(`${logMessages.removeGlobalContexts} ${logMessages.gcTagType}`));
1627
- }
1628
- return Promise.resolve(RNSnowplowTracker.removeGlobalContexts({ tracker: namespace, removeTag: tag }));
1629
- };
1630
- }
1631
- /**
1632
- * Returns a function to add global contexts by a tracker
1633
- *
1634
- * @param namespace {string} - The tracker namespace
1635
- * @returns - A function to add global contexts
1636
- */
1637
- function addGlobalContexts(namespace) {
1638
- return function (gc) {
1639
- if (!isValidGC(gc)) {
1640
- return Promise.reject(new Error(`${logMessages.addGlobalContexts} ${logMessages.gcType}`));
1641
- }
1642
- return Promise.resolve(RNSnowplowTracker.addGlobalContexts({ tracker: namespace, addGlobalContext: gc }));
1643
- };
1644
- }
1645
- /**
1646
- * Returns a function to set the subject userId
1647
- *
1648
- * @param namespace {string} - The tracker namespace
1649
- * @returns - A function to set the userId
1650
- */
1651
- function setUserId(namespace) {
1652
- return function (newUid) {
1653
- return setUserId$1(namespace, newUid);
1654
- };
1655
- }
1656
- /**
1657
- * Returns a function to set the subject networkUserId
1658
- *
1659
- * @param namespace {string} - The tracker namespace
1660
- * @returns - A function to set the networkUserId
1661
- */
1662
- function setNetworkUserId(namespace) {
1663
- return function (newNuid) {
1664
- return setNetworkUserId$1(namespace, newNuid);
1665
- };
1666
- }
1667
- /**
1668
- * Returns a function to set the subject domainUserId
1669
- *
1670
- * @param namespace {string} - The tracker namespace
1671
- * @returns - A function to set the domainUserId
1672
- */
1673
- function setDomainUserId(namespace) {
1674
- return function (newDuid) {
1675
- return setDomainUserId$1(namespace, newDuid);
1676
- };
1677
- }
1678
- /**
1679
- * Returns a function to set the subject ipAddress
1680
- *
1681
- * @param namespace {string} - The tracker namespace
1682
- * @returns - A function to set the ipAddress
1683
- */
1684
- function setIpAddress(namespace) {
1685
- return function (newIp) {
1686
- return setIpAddress$1(namespace, newIp);
1687
- };
1688
- }
1689
- /**
1690
- * Returns a function to set the subject useragent
1691
- *
1692
- * @param namespace {string} - The tracker namespace
1693
- * @returns - A function to set the useragent
1694
- */
1695
- function setUseragent(namespace) {
1696
- return function (newUagent) {
1697
- return setUseragent$1(namespace, newUagent);
1698
- };
1699
- }
1700
- /**
1701
- * Returns a function to set the subject timezone
1702
- *
1703
- * @param namespace {string} - The tracker namespace
1704
- * @returns - A function to set the timezone
1705
- */
1706
- function setTimezone(namespace) {
1707
- return function (newTz) {
1708
- return setTimezone$1(namespace, newTz);
1709
- };
1710
- }
1711
- /**
1712
- * Returns a function to set the subject language
1713
- *
1714
- * @param namespace {string} - The tracker namespace
1715
- * @returns - A function to set the language
1716
- */
1717
- function setLanguage(namespace) {
1718
- return function (newLang) {
1719
- return setLanguage$1(namespace, newLang);
1720
- };
1721
- }
1722
- /**
1723
- * Returns a function to set the subject screenResolution
1724
- *
1725
- * @param namespace {string} - The tracker namespace
1726
- * @returns - A function to set the screenResolution
1727
- */
1728
- function setScreenResolution(namespace) {
1729
- return function (newRes) {
1730
- return setScreenResolution$1(namespace, newRes);
1731
- };
1732
- }
1733
- /**
1734
- * Returns a function to set the subject screenViewport
1735
- *
1736
- * @param namespace {string} - The tracker namespace
1737
- * @returns - A function to set the screenViewport
1738
- */
1739
- function setScreenViewport(namespace) {
1740
- return function (newView) {
1741
- return setScreenViewport$1(namespace, newView);
1742
- };
1743
- }
1744
- /**
1745
- * Returns a function to set the subject colorDepth
1746
- *
1747
- * @param namespace {string} - The tracker namespace
1748
- * @returns - A function to set the colorDepth
1749
- */
1750
- function setColorDepth(namespace) {
1751
- return function (newColorD) {
1752
- return setColorDepth$1(namespace, newColorD);
1753
- };
1754
- }
1755
- /**
1756
- * Returns a function to set subject data
1757
- *
1758
- * @param namespace {string} - The tracker namespace
1759
- * @returns - A function to set subject data
1760
- */
1761
- function setSubjectData(namespace) {
1762
- return function (config) {
1763
- return setSubjectData$1(namespace, config);
1764
- };
1765
- }
1766
- /**
1767
- * Returns a function to get the current session userId
1768
- *
1769
- * @param namespace {string} - The tracker namespace
1770
- * @returns - A function to get the session userId
1771
- */
1772
- function getSessionUserId(namespace) {
1773
- return function () {
1774
- return Promise
1775
- .resolve(RNSnowplowTracker.getSessionUserId({ tracker: namespace }));
1776
- };
1777
- }
1778
- /**
1779
- * Returns a function to get the current sessionId
1780
- *
1781
- * @param namespace {string} - The tracker namespace
1782
- * @returns - A function to get the sessionId
1783
- */
1784
- function getSessionId(namespace) {
1785
- return function () {
1786
- return Promise
1787
- .resolve(RNSnowplowTracker.getSessionId({ tracker: namespace }));
1788
- };
1789
- }
1790
- /**
1791
- * Returns a function to get the current session index
1792
- *
1793
- * @param namespace {string} - The tracker namespace
1794
- * @returns - A function to get the session index
1795
- */
1796
- function getSessionIndex(namespace) {
1797
- return function () {
1798
- return Promise
1799
- .resolve(RNSnowplowTracker.getSessionIndex({ tracker: namespace }));
1800
- };
1801
- }
1802
- /**
1803
- * Returns a function to get whether the app is in background
1804
- *
1805
- * @param namespace {string} - The tracker namespace
1806
- * @returns - A function to get whether the app isInBackground
1807
- */
1808
- function getIsInBackground(namespace) {
1809
- return function () {
1810
- return Promise
1811
- .resolve(RNSnowplowTracker.getIsInBackground({ tracker: namespace }));
1812
- };
1813
- }
1814
- /**
1815
- * Returns a function to get the background index
1816
- *
1817
- * @param namespace {string} - The tracker namespace
1818
- * @returns - A function to get the backgroundIndex
1819
- */
1820
- function getBackgroundIndex(namespace) {
1821
- return function () {
1822
- return Promise
1823
- .resolve(RNSnowplowTracker.getBackgroundIndex({ tracker: namespace }));
1824
- };
1825
- }
1826
- /**
1827
- * Returns a function to get the foreground index
1828
- *
1829
- * @param namespace {string} - The tracker namespace
1830
- * @returns - A function to get the foregroundIndex
1831
- */
1832
- function getForegroundIndex(namespace) {
1833
- return function () {
1834
- return Promise
1835
- .resolve(RNSnowplowTracker.getForegroundIndex({ tracker: namespace }));
1836
- };
1837
- }
1838
-
1839
- /*
1840
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
1841
- *
1842
- * This program is licensed to you under the Apache License Version 2.0,
1843
- * and you may not use this file except in compliance with the Apache License Version 2.0.
1844
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
1845
- *
1846
- * Unless required by applicable law or agreed to in writing,
1847
- * software distributed under the Apache License Version 2.0 is distributed on an
1848
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1849
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1850
- */
1851
- function forEachTracker(trackers, iterator) {
1852
- if (trackers && trackers.length > 0) {
1853
- trackers.forEach(iterator);
1854
- }
1855
- else {
1856
- iterator(null);
1857
- }
1858
- }
1859
- /**
1860
- * Enables tracking events from apps rendered in react-native-webview components.
1861
- * The apps need to use the Snowplow WebView tracker to track the events.
1862
- *
1863
- * To subscribe for the events, set the `onMessage` attribute:
1864
- * <WebView onMessage={getWebViewCallback()} ... />
1865
- *
1866
- * @returns Callback to subscribe for events from Web views tracked using the Snowplow WebView tracker.
1867
- */
1868
- function getWebViewCallback() {
1869
- return (message) => {
1870
- const data = JSON.parse(message.nativeEvent.data);
1871
- switch (data.command) {
1872
- case 'trackSelfDescribingEvent':
1873
- forEachTracker(data.trackers, (namespace) => {
1874
- trackSelfDescribingEvent$1(namespace, data.event, data.context || []).catch((error) => {
1875
- errorHandler(error);
1876
- });
1877
- });
1878
- break;
1879
- case 'trackStructEvent':
1880
- forEachTracker(data.trackers, (namespace) => {
1881
- trackStructuredEvent$1(namespace, data.event, data.context || []).catch((error) => {
1882
- errorHandler(error);
1883
- });
1884
- });
1885
- break;
1886
- case 'trackPageView':
1887
- forEachTracker(data.trackers, (namespace) => {
1888
- const event = data.event;
1889
- trackPageViewEvent$1(namespace, {
1890
- pageTitle: event.title ?? '',
1891
- pageUrl: event.url ?? '',
1892
- referrer: event.referrer,
1893
- }).catch((error) => {
1894
- errorHandler(error);
1895
- });
1896
- });
1897
- break;
1898
- case 'trackScreenView':
1899
- forEachTracker(data.trackers, (namespace) => {
1900
- trackScreenViewEvent$1(namespace, data.event, data.context || []).catch((error) => {
1901
- errorHandler(error);
1902
- });
1903
- });
1904
- break;
1905
- }
1906
- };
1907
- }
1908
-
1909
- /*
1910
- * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
1911
- *
1912
- * This program is licensed to you under the Apache License Version 2.0,
1913
- * and you may not use this file except in compliance with the Apache License Version 2.0.
1914
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
1915
- *
1916
- * Unless required by applicable law or agreed to in writing,
1917
- * software distributed under the Apache License Version 2.0 is distributed on an
1918
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1919
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1920
- */
1921
- /**
1922
- * Creates a React Native Tracker object
1923
- *
1924
- * @param namespace {string} - The tracker namespace
1925
- * @param networkConfig {Object} - The network configuration
1926
- * @param control {Array} - The tracker controller configuration
1927
- * @returns The tracker object
1928
- */
1929
- function createTracker(namespace, networkConfig, controllerConfig = {}) {
1930
- // initTrackerPromise
1931
- const initTrackerPromise = Promise.resolve(createTracker$1({
1932
- namespace,
1933
- networkConfig,
1934
- ...controllerConfig
1935
- }));
1936
- // mkMethod creates methods subscribed to the initTrackerPromise
1937
- const mkMethod = safeWait(initTrackerPromise, errorHandler);
1938
- // mkCallback creates callbacks subscribed to the initTrackerPromise
1939
- const mkCallback = safeWaitCallback(initTrackerPromise, errorHandler);
1940
- // track methods
1941
- const trackSelfDescribingEvent$1 = mkMethod(trackSelfDescribingEvent(namespace));
1942
- const trackScreenViewEvent$1 = mkMethod(trackScreenViewEvent(namespace));
1943
- const trackStructuredEvent$1 = mkMethod(trackStructuredEvent(namespace));
1944
- const trackPageViewEvent$1 = mkMethod(trackPageViewEvent(namespace));
1945
- const trackTimingEvent$1 = mkMethod(trackTimingEvent(namespace));
1946
- const trackConsentGrantedEvent$1 = mkMethod(trackConsentGrantedEvent(namespace));
1947
- const trackConsentWithdrawnEvent$1 = mkMethod(trackConsentWithdrawnEvent(namespace));
1948
- const trackEcommerceTransactionEvent$1 = mkMethod(trackEcommerceTransactionEvent(namespace));
1949
- const trackDeepLinkReceivedEvent$1 = mkMethod(trackDeepLinkReceivedEvent(namespace));
1950
- const trackMessageNotificationEvent$1 = mkMethod(trackMessageNotificationEvent(namespace));
1951
- // Global Contexts
1952
- const removeGlobalContexts$1 = mkMethod(removeGlobalContexts(namespace));
1953
- const addGlobalContexts$1 = mkMethod(addGlobalContexts(namespace));
1954
- // setters
1955
- const setUserId$1 = mkMethod(setUserId(namespace));
1956
- const setNetworkUserId$1 = mkMethod(setNetworkUserId(namespace));
1957
- const setDomainUserId$1 = mkMethod(setDomainUserId(namespace));
1958
- const setIpAddress$1 = mkMethod(setIpAddress(namespace));
1959
- const setUseragent$1 = mkMethod(setUseragent(namespace));
1960
- const setTimezone$1 = mkMethod(setTimezone(namespace));
1961
- const setLanguage$1 = mkMethod(setLanguage(namespace));
1962
- const setScreenResolution$1 = mkMethod(setScreenResolution(namespace));
1963
- const setScreenViewport$1 = mkMethod(setScreenViewport(namespace));
1964
- const setColorDepth$1 = mkMethod(setColorDepth(namespace));
1965
- const setSubjectData$1 = mkMethod(setSubjectData(namespace));
1966
- // callbacks
1967
- const getSessionUserId$1 = mkCallback(getSessionUserId(namespace));
1968
- const getSessionId$1 = mkCallback(getSessionId(namespace));
1969
- const getSessionIndex$1 = mkCallback(getSessionIndex(namespace));
1970
- const getIsInBackground$1 = mkCallback(getIsInBackground(namespace));
1971
- const getBackgroundIndex$1 = mkCallback(getBackgroundIndex(namespace));
1972
- const getForegroundIndex$1 = mkCallback(getForegroundIndex(namespace));
1973
- return Object.freeze({
1974
- trackSelfDescribingEvent: trackSelfDescribingEvent$1,
1975
- trackScreenViewEvent: trackScreenViewEvent$1,
1976
- trackStructuredEvent: trackStructuredEvent$1,
1977
- trackPageViewEvent: trackPageViewEvent$1,
1978
- trackTimingEvent: trackTimingEvent$1,
1979
- trackConsentGrantedEvent: trackConsentGrantedEvent$1,
1980
- trackConsentWithdrawnEvent: trackConsentWithdrawnEvent$1,
1981
- trackEcommerceTransactionEvent: trackEcommerceTransactionEvent$1,
1982
- trackDeepLinkReceivedEvent: trackDeepLinkReceivedEvent$1,
1983
- trackMessageNotificationEvent: trackMessageNotificationEvent$1,
1984
- removeGlobalContexts: removeGlobalContexts$1,
1985
- addGlobalContexts: addGlobalContexts$1,
1986
- setUserId: setUserId$1,
1987
- setNetworkUserId: setNetworkUserId$1,
1988
- setDomainUserId: setDomainUserId$1,
1989
- setIpAddress: setIpAddress$1,
1990
- setUseragent: setUseragent$1,
1991
- setTimezone: setTimezone$1,
1992
- setLanguage: setLanguage$1,
1993
- setScreenResolution: setScreenResolution$1,
1994
- setScreenViewport: setScreenViewport$1,
1995
- setColorDepth: setColorDepth$1,
1996
- setSubjectData: setSubjectData$1,
1997
- getSessionUserId: getSessionUserId$1,
1998
- getSessionId: getSessionId$1,
1999
- getSessionIndex: getSessionIndex$1,
2000
- getIsInBackground: getIsInBackground$1,
2001
- getBackgroundIndex: getBackgroundIndex$1,
2002
- getForegroundIndex: getForegroundIndex$1,
2003
- });
2004
- }
2005
- /**
2006
- * Removes a tracker given its namespace
2007
- *
2008
- * @param trackerNamespace {string}
2009
- * @returns - A boolean promise
2010
- */
2011
- function removeTracker(trackerNamespace) {
2012
- return removeTracker$1(trackerNamespace)
2013
- .catch((e) => errorHandler(e));
2014
- }
2015
- /**
2016
- * Removes all trackers
2017
- *
2018
- * @returns - A boolean promise
2019
- */
2020
- function removeAllTrackers() {
2021
- return removeAllTrackers$1()
2022
- .catch((e) => errorHandler(e));
2023
- }
2024
-
2025
- export { createTracker, getWebViewCallback, removeAllTrackers, removeTracker };
2026
- //# sourceMappingURL=index.js.map