@snowplow/react-native-tracker 1.3.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 (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 +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/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 +704 -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 +271 -0
  32. package/android/src/main/java/com/snowplow/reactnativetracker/util/EventUtil.kt +213 -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 +108 -0
  73. package/example/e2e/environment.js +23 -0
  74. package/example/e2e/helpers/microCommands.js +153 -0
  75. package/example/e2e/helpers/microHelpers.js +346 -0
  76. package/example/e2e/helpers/microHelpers.test.js +308 -0
  77. package/example/e2e/helpers/schemas.js +62 -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 +300 -0
  81. package/example/index.js +5 -0
  82. package/example/ios/.xcode.env +11 -0
  83. package/example/ios/Podfile +64 -0
  84. package/example/ios/Podfile.lock +737 -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 +557 -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 +165 -0
  107. package/ios/ReactNativeTracker.swift +757 -0
  108. package/ios/{RNSnowplowTracker.xcodeproj → ReactNativeTracker.xcodeproj}/project.pbxproj +55 -79
  109. package/ios/Util/ConfigUtils.swift +206 -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 +475 -0
  114. package/lib/commonjs/api.js.map +1 -0
  115. package/lib/commonjs/configurations.js +209 -0
  116. package/lib/commonjs/configurations.js.map +1 -0
  117. package/lib/commonjs/constants.js +85 -0
  118. package/lib/commonjs/constants.js.map +1 -0
  119. package/lib/commonjs/events.js +256 -0
  120. package/lib/commonjs/events.js.map +1 -0
  121. package/lib/commonjs/index.js +141 -0
  122. package/lib/commonjs/index.js.map +1 -0
  123. package/lib/commonjs/jsCore.js +393 -0
  124. package/lib/commonjs/jsCore.js.map +1 -0
  125. package/lib/commonjs/native.js +29 -0
  126. package/lib/commonjs/native.js.map +1 -0
  127. package/lib/commonjs/subject.js +248 -0
  128. package/lib/commonjs/subject.js.map +1 -0
  129. package/lib/commonjs/tracker.js +221 -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 +85 -0
  134. package/lib/commonjs/utils.js.map +1 -0
  135. package/lib/commonjs/webViewInterface.js +79 -0
  136. package/lib/commonjs/webViewInterface.js.map +1 -0
  137. package/lib/module/api.js +439 -0
  138. package/lib/module/api.js.map +1 -0
  139. package/lib/module/configurations.js +197 -0
  140. package/lib/module/configurations.js.map +1 -0
  141. package/lib/module/constants.js +80 -0
  142. package/lib/module/constants.js.map +1 -0
  143. package/lib/module/events.js +240 -0
  144. package/lib/module/events.js.map +1 -0
  145. package/lib/module/index.js +129 -0
  146. package/lib/module/index.js.map +1 -0
  147. package/lib/module/jsCore.js +390 -0
  148. package/lib/module/jsCore.js.map +1 -0
  149. package/lib/module/native.js +25 -0
  150. package/lib/module/native.js.map +1 -0
  151. package/lib/module/subject.js +235 -0
  152. package/lib/module/subject.js.map +1 -0
  153. package/lib/module/tracker.js +209 -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 +79 -0
  158. package/lib/module/utils.js.map +1 -0
  159. package/lib/module/webViewInterface.js +75 -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 +226 -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 +59 -0
  178. package/lib/typescript/constants.d.ts.map +1 -0
  179. package/lib/typescript/events.d.ts +101 -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 +140 -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 +93 -0
  190. package/lib/typescript/tracker.d.ts.map +1 -0
  191. package/{dist/index.d.ts → lib/typescript/types.d.ts} +188 -75
  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 +138 -51
  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 +34 -0
  202. package/src/__tests__/configurations.test.ts +620 -0
  203. package/src/__tests__/events.test.ts +749 -0
  204. package/src/__tests__/index.test.ts +27 -0
  205. package/src/__tests__/jsCore.test.ts +169 -0
  206. package/src/__tests__/utils.test.ts +23 -0
  207. package/src/api.ts +535 -0
  208. package/src/configurations.ts +337 -0
  209. package/src/constants.ts +102 -0
  210. package/src/events.ts +330 -0
  211. package/src/index.ts +189 -0
  212. package/src/jsCore.ts +553 -0
  213. package/src/native.ts +34 -0
  214. package/src/subject.ts +315 -0
  215. package/src/tracker.ts +330 -0
  216. package/src/types.ts +1087 -0
  217. package/src/utils.ts +78 -0
  218. package/src/webViewInterface.ts +105 -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 -1650
  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
package/dist/index.js DELETED
@@ -1,1650 +0,0 @@
1
- import { NativeModules } from 'react-native';
2
-
3
- /*
4
- * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
5
- *
6
- * This program is licensed to you under the Apache License Version 2.0,
7
- * and you may not use this file except in compliance with the Apache License Version 2.0.
8
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
9
- *
10
- * Unless required by applicable law or agreed to in writing,
11
- * software distributed under the Apache License Version 2.0 is distributed on an
12
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
14
- */
15
- const { RNSnowplowTracker } = NativeModules;
16
-
17
- /*
18
- * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
19
- *
20
- * This program is licensed to you under the Apache License Version 2.0,
21
- * and you may not use this file except in compliance with the Apache License Version 2.0.
22
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
23
- *
24
- * Unless required by applicable law or agreed to in writing,
25
- * software distributed under the Apache License Version 2.0 is distributed on an
26
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
28
- */
29
- /**
30
- * Returns a function that accepts a side-effect function as its argument and subscribes
31
- * that function to aPromise's fullfillment,
32
- * and errHandle to aPromise's rejection.
33
- *
34
- * @param aPromise - A void Promise
35
- * @param errHandle - A function to handle the promise being rejected
36
- * @returns - A function subscribed to the Promise's fullfillment
37
- */
38
- function safeWait(aPromise, errHandle) {
39
- return ((func) => {
40
- return (...args) => {
41
- return aPromise.then(() => func(...args)).catch((err) => errHandle(err));
42
- };
43
- });
44
- }
45
- /**
46
- * Returns a function that accepts a callback function as its argument and subscribes
47
- * that function to aPromise's fullfillment,
48
- * and errHandle to aPromise's rejection.
49
- *
50
- * @param aPromise - A void Promise
51
- * @param errHandle - A function to handle the promise being rejected
52
- * @returns - A function subscribed to the Promise's fullfillment
53
- */
54
- function safeWaitCallback(callPromise, errHandle) {
55
- return ((func) => {
56
- return (...args) => {
57
- return callPromise.then(() => func(...args)).catch((err) => errHandle(err));
58
- };
59
- });
60
- }
61
- /**
62
- * Handles an error.
63
- *
64
- * @param err - The error to be handled.
65
- */
66
- function errorHandler(err) {
67
- if (__DEV__) {
68
- console.warn('SnowplowTracker:' + err.message);
69
- return undefined;
70
- }
71
- return undefined;
72
- }
73
- /**
74
- * Helper to check whether its argument is of object type
75
- *
76
- * @param x - The argument to check.
77
- * @returns - A boolean
78
- */
79
- function isObject(x) {
80
- return Object.prototype.toString.call(x) === '[object Object]';
81
- }
82
-
83
- /*
84
- * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
85
- *
86
- * This program is licensed to you under the Apache License Version 2.0,
87
- * and you may not use this file except in compliance with the Apache License Version 2.0.
88
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
89
- *
90
- * Unless required by applicable law or agreed to in writing,
91
- * software distributed under the Apache License Version 2.0 is distributed on an
92
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
93
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
94
- */
95
- const logMessages = {
96
- // configuration errors
97
- namespace: 'namespace parameter is required to be set',
98
- endpoint: 'endpoint parameter is required to be set',
99
- network: 'networkConfig is invalid',
100
- tracker: 'trackerConfig is invalid',
101
- session: 'sessionConfig is invalid',
102
- emitter: 'emitterConfig is invalid',
103
- subject: 'subjectConfig is invalid',
104
- gdpr: 'gdprConfig is invalid',
105
- gc: 'gcConfig is invalid',
106
- // event errors
107
- context: 'invalid contexts parameter',
108
- selfDesc: 'selfDescribing event requires schema and data parameters to be set',
109
- evType: 'event argument can only be an object',
110
- screenViewReq: 'screenView event requires name as string parameter to be set',
111
- structuredReq: 'structured event requires category and action parameters to be set',
112
- pageviewReq: 'pageView event requires pageUrl parameter to be set',
113
- timingReq: 'timing event requires category, variable and timing parameters to be set',
114
- consentGReq: 'consentGranted event requires expiry, documentId and version parameters to be set',
115
- consentWReq: 'consentWithdrawn event requires all, documentId and version parameters to be set',
116
- ecomReq: 'ecommerceTransaction event requires orderId, totalValue to be set and items to be an array of valid ecommerceItems',
117
- deepLinkReq: 'deepLinkReceived event requires the url parameter to be set',
118
- messageNotificationReq: 'messageNotification event requires title, body, and trigger parameters to be set',
119
- // global contexts errors
120
- gcTagType: 'tag argument is required to be a string',
121
- gcType: 'global context argument is invalid',
122
- // api error prefix
123
- createTracker: 'createTracker:',
124
- removeTracker: 'removeTracker: trackerNamespace can only be a string',
125
- // methods
126
- trackSelfDesc: 'trackSelfDescribingEvent:',
127
- trackScreenView: 'trackScreenViewEvent:',
128
- trackStructured: 'trackStructuredEvent:',
129
- trackPageView: 'trackPageViewEvent:',
130
- trackTiming: 'trackTimingEvent:',
131
- trackConsentGranted: 'trackConsentGranted:',
132
- trackConsentWithdrawn: 'trackConsentWithdrawn:',
133
- trackEcommerceTransaction: 'trackEcommerceTransaction:',
134
- trackDeepLinkReceived: 'trackDeepLinkReceivedEvent:',
135
- trackMessageNotification: 'trackMessageNotificationEvent:',
136
- removeGlobalContexts: 'removeGlobalContexts:',
137
- addGlobalContexts: 'addGlobalContexts:',
138
- // setters
139
- setUserId: 'setUserId: userId can only be a string or null',
140
- setNetworkUserId: 'setNetworkUserId: networkUserId can only be a string(UUID) or null',
141
- setDomainUserId: 'setDomainUserId: domainUserId can only be a string(UUID) or null',
142
- setIpAddress: 'setIpAddress: ipAddress can only be a string or null',
143
- setUseragent: 'setUseragent: useragent can only be a string or null',
144
- setTimezone: 'setTimezone: timezone can only be a string or null',
145
- setLanguage: 'setLanguage: language can only be a string or null',
146
- setScreenResolution: 'setScreenResolution: screenResolution can only be of ScreenSize type or null',
147
- setScreenViewport: 'setScreenViewport: screenViewport can only be of ScreenSize type or null',
148
- setColorDepth: 'setColorDepth: colorDepth can only be a number(integer) or null',
149
- setSubjectData: 'setSubjectData:',
150
- };
151
-
152
- /*
153
- * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
154
- *
155
- * This program is licensed to you under the Apache License Version 2.0,
156
- * and you may not use this file except in compliance with the Apache License Version 2.0.
157
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
158
- *
159
- * Unless required by applicable law or agreed to in writing,
160
- * software distributed under the Apache License Version 2.0 is distributed on an
161
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
162
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
163
- */
164
- /**
165
- * Validates whether an object is valid self-describing
166
- *
167
- * @param sd {Object} - the object to validate
168
- * @returns - boolean
169
- */
170
- function isValidSD(sd) {
171
- return isObject(sd)
172
- && typeof sd.schema === 'string'
173
- && isObject(sd.data);
174
- }
175
- /**
176
- * Validates whether an object is a valid array of contexts
177
- *
178
- * @param contexts {Object} - the object to validate
179
- * @returns - boolean promise
180
- */
181
- function validateContexts(contexts) {
182
- const isValid = Object.prototype.toString.call(contexts) === '[object Array]'
183
- && contexts
184
- .map((c) => isValidSD(c))
185
- .reduce((acc, curr) => acc !== false && curr, true);
186
- if (!isValid) {
187
- return Promise.reject(new Error(logMessages.context));
188
- }
189
- return Promise.resolve(true);
190
- }
191
- /**
192
- * Validates whether an object is valid self describing
193
- *
194
- * @param argmap {Object} - the object to validate
195
- * @returns - boolean promise
196
- */
197
- function validateSelfDesc(argmap) {
198
- if (!isValidSD(argmap)) {
199
- return Promise.reject(new Error(logMessages.selfDesc));
200
- }
201
- return Promise.resolve(true);
202
- }
203
- /**
204
- * Validates a screen view event
205
- *
206
- * @param argmap {Object} - the object to validate
207
- * @returns - boolean promise
208
- */
209
- function validateScreenView(argmap) {
210
- // validate type
211
- if (!isObject(argmap)) {
212
- return Promise.reject(new Error(logMessages.evType));
213
- }
214
- // validate required props
215
- if (typeof argmap.name !== 'string') {
216
- return Promise.reject(new Error(logMessages.screenViewReq));
217
- }
218
- return Promise.resolve(true);
219
- }
220
- /**
221
- * Validates a structured event
222
- *
223
- * @param argmap {Object} - the object to validate
224
- * @returns - boolean promise
225
- */
226
- function validateStructured(argmap) {
227
- // validate type
228
- if (!isObject(argmap)) {
229
- return Promise.reject(new Error(logMessages.evType));
230
- }
231
- // validate required props
232
- if (typeof argmap.category !== 'string'
233
- || typeof argmap.action !== 'string') {
234
- return Promise.reject(new Error(logMessages.structuredReq));
235
- }
236
- return Promise.resolve(true);
237
- }
238
- /**
239
- * Validates a page-view event
240
- *
241
- * @param argmap {Object} - the object to validate
242
- * @returns - boolean promise
243
- */
244
- function validatePageView(argmap) {
245
- // validate type
246
- if (!isObject(argmap)) {
247
- return Promise.reject(new Error(logMessages.evType));
248
- }
249
- // validate required props
250
- if (typeof argmap.pageUrl !== 'string') {
251
- return Promise.reject(new Error(logMessages.pageviewReq));
252
- }
253
- return Promise.resolve(true);
254
- }
255
- /**
256
- * Validates a timing event
257
- *
258
- * @param argmap {Object} - the object to validate
259
- * @returns - boolean promise
260
- */
261
- function validateTiming(argmap) {
262
- // validate type
263
- if (!isObject(argmap)) {
264
- return Promise.reject(new Error(logMessages.evType));
265
- }
266
- // validate required props
267
- if (typeof argmap.category !== 'string'
268
- || typeof argmap.variable !== 'string'
269
- || typeof argmap.timing !== 'number') {
270
- return Promise.reject(new Error(logMessages.timingReq));
271
- }
272
- return Promise.resolve(true);
273
- }
274
- /**
275
- * Validates a consent-granted event
276
- *
277
- * @param argmap {Object} - the object to validate
278
- * @returns - boolean promise
279
- */
280
- function validateConsentGranted(argmap) {
281
- // validate type
282
- if (!isObject(argmap)) {
283
- return Promise.reject(new Error(logMessages.evType));
284
- }
285
- // validate required props
286
- if (typeof argmap.expiry !== 'string'
287
- || typeof argmap.documentId !== 'string'
288
- || typeof argmap.version !== 'string') {
289
- return Promise.reject(new Error(logMessages.consentGReq));
290
- }
291
- return Promise.resolve(true);
292
- }
293
- /**
294
- * Validates a consent-withdrawn event
295
- *
296
- * @param argmap {Object} - the object to validate
297
- * @returns - boolean promise
298
- */
299
- function validateConsentWithdrawn(argmap) {
300
- // validate type
301
- if (!isObject(argmap)) {
302
- return Promise.reject(new Error(logMessages.evType));
303
- }
304
- // validate required props
305
- if (typeof argmap.all !== 'boolean'
306
- || typeof argmap.documentId !== 'string'
307
- || typeof argmap.version !== 'string') {
308
- return Promise.reject(new Error(logMessages.consentWReq));
309
- }
310
- return Promise.resolve(true);
311
- }
312
- /**
313
- * Validates a deep link received event
314
- *
315
- * @param argmap {Object} - the object to validate
316
- * @returns - boolean promise
317
- */
318
- function validateDeepLinkReceived(argmap) {
319
- // validate type
320
- if (!isObject(argmap)) {
321
- return Promise.reject(new Error(logMessages.evType));
322
- }
323
- // validate required props
324
- if (typeof argmap.url !== 'string') {
325
- return Promise.reject(new Error(logMessages.deepLinkReq));
326
- }
327
- return Promise.resolve(true);
328
- }
329
- /**
330
- * Validates a message notification event
331
- *
332
- * @param argmap {Object} - the object to validate
333
- * @returns - boolean promise
334
- */
335
- function validateMessageNotification(argmap) {
336
- // validate type
337
- if (!isObject(argmap)) {
338
- return Promise.reject(new Error(logMessages.evType));
339
- }
340
- // validate required props
341
- if (typeof argmap.title !== 'string'
342
- || typeof argmap.body !== 'string'
343
- || typeof argmap.trigger !== 'string'
344
- || !['push', 'location', 'calendar', 'timeInterval', 'other'].includes(argmap.trigger)) {
345
- return Promise.reject(new Error(logMessages.messageNotificationReq));
346
- }
347
- return Promise.resolve(true);
348
- }
349
- /**
350
- * Validates whether an object is valid ecommerce-item
351
- *
352
- * @param item {Object} - the object to validate
353
- * @returns - boolean
354
- */
355
- function isValidEcomItem(item) {
356
- if (isObject(item)
357
- && typeof item.sku === 'string'
358
- && typeof item.price === 'number'
359
- && typeof item.quantity === 'number') {
360
- return true;
361
- }
362
- return false;
363
- }
364
- /**
365
- * Validates an array of ecommerce-items
366
- *
367
- * @param items {Object} - the object to validate
368
- * @returns - boolean promise
369
- */
370
- function validItemsArg(items) {
371
- return Object.prototype.toString.call(items) === '[object Array]'
372
- && items
373
- .map((i) => isValidEcomItem(i))
374
- .reduce((acc, curr) => acc !== false && curr, true);
375
- }
376
- /**
377
- * Validates an ecommerce-transaction event
378
- *
379
- * @param argmap {Object} - the object to validate
380
- * @returns - boolean promise
381
- */
382
- function validateEcommerceTransaction(argmap) {
383
- // validate type
384
- if (!isObject(argmap)) {
385
- return Promise.reject(new Error(logMessages.evType));
386
- }
387
- // validate required props
388
- if (typeof argmap.orderId !== 'string'
389
- || typeof argmap.totalValue !== 'number'
390
- || !validItemsArg(argmap.items)) {
391
- return Promise.reject(new Error(logMessages.ecomReq));
392
- }
393
- return Promise.resolve(true);
394
- }
395
-
396
- /*
397
- * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
398
- *
399
- * This program is licensed to you under the Apache License Version 2.0,
400
- * and you may not use this file except in compliance with the Apache License Version 2.0.
401
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
402
- *
403
- * Unless required by applicable law or agreed to in writing,
404
- * software distributed under the Apache License Version 2.0 is distributed on an
405
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
406
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
407
- */
408
- /**
409
- * Configuration properties
410
- */
411
- const networkProps = [
412
- 'endpoint',
413
- 'method',
414
- 'customPostPath',
415
- 'requestHeaders',
416
- ];
417
- const trackerProps = [
418
- 'appId',
419
- 'devicePlatform',
420
- 'base64Encoding',
421
- 'logLevel',
422
- 'applicationContext',
423
- 'platformContext',
424
- 'geoLocationContext',
425
- 'sessionContext',
426
- 'deepLinkContext',
427
- 'screenContext',
428
- 'screenViewAutotracking',
429
- 'lifecycleAutotracking',
430
- 'installAutotracking',
431
- 'exceptionAutotracking',
432
- 'diagnosticAutotracking',
433
- 'userAnonymisation'
434
- ];
435
- const sessionProps = [
436
- 'foregroundTimeout',
437
- 'backgroundTimeout'
438
- ];
439
- const emitterProps = [
440
- 'bufferOption',
441
- 'emitRange',
442
- 'threadPoolSize',
443
- 'byteLimitPost',
444
- 'byteLimitGet',
445
- 'serverAnonymisation',
446
- ];
447
- const subjectProps = [
448
- 'userId',
449
- 'networkUserId',
450
- 'domainUserId',
451
- 'useragent',
452
- 'ipAddress',
453
- 'timezone',
454
- 'language',
455
- 'screenResolution',
456
- 'screenViewport',
457
- 'colorDepth'
458
- ];
459
- const gdprProps = [
460
- 'basisForProcessing',
461
- 'documentId',
462
- 'documentVersion',
463
- 'documentDescription'
464
- ];
465
- const gcProps = [
466
- 'tag',
467
- 'globalContexts'
468
- ];
469
- /**
470
- * Validates whether an object is of valid configuration given its default keys
471
- *
472
- * @param config {Object} - the object to validate
473
- * @param defaultKeys {Array} - the default keys to validate against
474
- * @returns - boolean
475
- */
476
- function isValidConfig(config, defaultKeys) {
477
- return Object.keys(config).every(key => defaultKeys.includes(key));
478
- }
479
- /**
480
- * Validates the networkConfig
481
- *
482
- * @param config {Object} - the config to validate
483
- * @returns - boolean
484
- */
485
- function isValidNetworkConf(config) {
486
- if (!isObject(config)
487
- || !isValidConfig(config, networkProps)
488
- || typeof config.endpoint !== 'string'
489
- || !config.endpoint) {
490
- return false;
491
- }
492
- return true;
493
- }
494
- /**
495
- * Validates the trackerConfig
496
- *
497
- * @param config {Object} - the config to validate
498
- * @returns - boolean
499
- */
500
- function isValidTrackerConf(config) {
501
- if (!isObject(config) || !isValidConfig(config, trackerProps)) {
502
- return false;
503
- }
504
- return true;
505
- }
506
- /**
507
- * Validates the sessionConfig
508
- *
509
- * @param config {Object} - the config to validate
510
- * @returns - boolean
511
- */
512
- function isValidSessionConf(config) {
513
- if (!isObject(config)
514
- || !isValidConfig(config, sessionProps)
515
- || !sessionProps.every(key => Object.keys(config).includes(key))) {
516
- return false;
517
- }
518
- return true;
519
- }
520
- /**
521
- * Validates the emitterConfig
522
- *
523
- * @param config {Object} - the config to validate
524
- * @returns - boolean
525
- */
526
- function isValidEmitterConf(config) {
527
- if (!isObject(config) || !isValidConfig(config, emitterProps)) {
528
- return false;
529
- }
530
- return true;
531
- }
532
- /**
533
- * Validates whether an object is of ScreenSize type
534
- *
535
- * @param arr {Object} - the object to validate
536
- * @returns - boolean
537
- */
538
- function isScreenSize(arr) {
539
- return Array.isArray(arr)
540
- && arr.length === 2
541
- && arr.every((n) => typeof n === 'number');
542
- }
543
- /**
544
- * Validates the subjectConfig
545
- *
546
- * @param config {Object} - the config to validate
547
- * @returns - boolean
548
- */
549
- function isValidSubjectConf(config) {
550
- if (!isObject(config) || !isValidConfig(config, subjectProps)) {
551
- return false;
552
- }
553
- // validating ScreenSize here to simplify array handling in bridge
554
- if (Object.prototype.hasOwnProperty.call(config, 'screenResolution')
555
- && config.screenResolution !== null
556
- && !isScreenSize(config.screenResolution)) {
557
- return false;
558
- }
559
- if (Object.prototype.hasOwnProperty.call(config, 'screenViewport')
560
- && config.screenViewport !== null
561
- && !isScreenSize(config.screenViewport)) {
562
- return false;
563
- }
564
- return true;
565
- }
566
- /**
567
- * Validates the gdprConfig
568
- *
569
- * @param config {Object} - the config to validate
570
- * @returns - boolean
571
- */
572
- function isValidGdprConf(config) {
573
- if (!isObject(config)
574
- || !isValidConfig(config, gdprProps)
575
- || !gdprProps.every(key => Object.keys(config).includes(key))
576
- || !['consent', 'contract', 'legal_obligation', 'legitimate_interests', 'public_task', 'vital_interests'].includes(config.basisForProcessing)) {
577
- return false;
578
- }
579
- return true;
580
- }
581
- /**
582
- * Validates whether an object is of GlobalContext type
583
- *
584
- * @param gc {Object} - the object to validate
585
- * @returns - boolean
586
- */
587
- function isValidGC(gc) {
588
- return isObject(gc)
589
- && isValidConfig(gc, gcProps)
590
- && typeof gc.tag === 'string'
591
- && Array.isArray(gc.globalContexts)
592
- && gc.globalContexts.every(c => isValidSD(c));
593
- }
594
- /**
595
- * Validates the GCConfig (global contexts)
596
- *
597
- * @param config {Object} - the config to validate
598
- * @returns - boolean
599
- */
600
- function isValidGCConf(config) {
601
- if (!Array.isArray(config)) {
602
- return false;
603
- }
604
- if (!config.every(gc => isValidGC(gc))) {
605
- return false;
606
- }
607
- return true;
608
- }
609
- /**
610
- * Validates the initTrackerConfiguration
611
- *
612
- * @param init {Object} - the config to validate
613
- * @returns - boolean promise
614
- */
615
- function initValidate(init) {
616
- if (typeof init.namespace !== 'string' || !init.namespace) {
617
- return Promise.reject(new Error(logMessages.namespace));
618
- }
619
- if (!Object.prototype.hasOwnProperty.call(init, 'networkConfig')
620
- || !isValidNetworkConf(init.networkConfig)) {
621
- return Promise.reject(new Error(logMessages.network));
622
- }
623
- if (Object.prototype.hasOwnProperty.call(init, 'trackerConfig')
624
- && !isValidTrackerConf(init.trackerConfig)) {
625
- return Promise.reject(new Error(logMessages.tracker));
626
- }
627
- if (Object.prototype.hasOwnProperty.call(init, 'sessionConfig')
628
- && (!isValidSessionConf(init.sessionConfig))) {
629
- return Promise.reject(new Error(logMessages.session));
630
- }
631
- if (Object.prototype.hasOwnProperty.call(init, 'emitterConfig')
632
- && !isValidEmitterConf(init.emitterConfig)) {
633
- return Promise.reject(new Error(logMessages.emitter));
634
- }
635
- if (Object.prototype.hasOwnProperty.call(init, 'subjectConfig')
636
- && !isValidSubjectConf(init.subjectConfig)) {
637
- return Promise.reject(new Error(logMessages.subject));
638
- }
639
- if (Object.prototype.hasOwnProperty.call(init, 'gdprConfig')
640
- && !isValidGdprConf(init.gdprConfig)) {
641
- return Promise.reject(new Error(logMessages.gdpr));
642
- }
643
- if (Object.prototype.hasOwnProperty.call(init, 'gcConfig')
644
- && !isValidGCConf(init.gcConfig)) {
645
- return Promise.reject(new Error(logMessages.gc));
646
- }
647
- return Promise.resolve(true);
648
- }
649
-
650
- /*
651
- * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
652
- *
653
- * This program is licensed to you under the Apache License Version 2.0,
654
- * and you may not use this file except in compliance with the Apache License Version 2.0.
655
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
656
- *
657
- * Unless required by applicable law or agreed to in writing,
658
- * software distributed under the Apache License Version 2.0 is distributed on an
659
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
660
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
661
- */
662
- /**
663
- * Tracks a self-describing event
664
- *
665
- * @param namespace {string} - the tracker namespace
666
- * @param argmap {Object} - the event data
667
- * @param contexts {Array}- the event contexts
668
- * @returns {Promise}
669
- */
670
- function trackSelfDescribingEvent$1(namespace, argmap, contexts = []) {
671
- return validateSelfDesc(argmap)
672
- .then(() => validateContexts(contexts))
673
- .then(() => RNSnowplowTracker.trackSelfDescribingEvent({
674
- tracker: namespace,
675
- eventData: argmap,
676
- contexts: contexts
677
- }))
678
- .catch((error) => {
679
- throw new Error(`${logMessages.trackSelfDesc} ${error.message}`);
680
- });
681
- }
682
- /**
683
- * Tracks a screen-view event
684
- *
685
- * @param namespace {string} - the tracker namespace
686
- * @param argmap {Object} - the event data
687
- * @param contexts {Array}- the event contexts
688
- * @returns {Promise}
689
- */
690
- function trackScreenViewEvent$1(namespace, argmap, contexts = []) {
691
- return validateScreenView(argmap)
692
- .then(() => validateContexts(contexts))
693
- .then(() => RNSnowplowTracker.trackScreenViewEvent({
694
- tracker: namespace,
695
- eventData: argmap,
696
- contexts: contexts
697
- }))
698
- .catch((error) => {
699
- throw new Error(`${logMessages.trackScreenView} ${error.message}`);
700
- });
701
- }
702
- /**
703
- * Tracks a structured event
704
- *
705
- * @param namespace {string} - the tracker namespace
706
- * @param argmap {Object} - the event data
707
- * @param contexts {Array}- the event contexts
708
- * @returns {Promise}
709
- */
710
- function trackStructuredEvent$1(namespace, argmap, contexts = []) {
711
- return validateStructured(argmap)
712
- .then(() => validateContexts(contexts))
713
- .then(() => RNSnowplowTracker.trackStructuredEvent({
714
- tracker: namespace,
715
- eventData: argmap,
716
- contexts: contexts
717
- }))
718
- .catch((error) => {
719
- throw new Error(`${logMessages.trackStructured} ${error.message}`);
720
- });
721
- }
722
- /**
723
- * Tracks a page-view event
724
- *
725
- * @param namespace {string} - the tracker namespace
726
- * @param argmap {Object} - the event data
727
- * @param contexts {Array}- the event contexts
728
- * @returns {Promise}
729
- */
730
- function trackPageViewEvent$1(namespace, argmap, contexts = []) {
731
- return validatePageView(argmap)
732
- .then(() => validateContexts(contexts))
733
- .then(() => RNSnowplowTracker.trackPageViewEvent({
734
- tracker: namespace,
735
- eventData: argmap,
736
- contexts: contexts
737
- }))
738
- .catch((error) => {
739
- throw new Error(`${logMessages.trackPageView} ${error.message}`);
740
- });
741
- }
742
- /**
743
- * Tracks a timing event
744
- *
745
- * @param namespace {string} - the tracker namespace
746
- * @param argmap {Object} - the event data
747
- * @param contexts {Array}- the event contexts
748
- * @returns {Promise}
749
- */
750
- function trackTimingEvent$1(namespace, argmap, contexts = []) {
751
- return validateTiming(argmap)
752
- .then(() => validateContexts(contexts))
753
- .then(() => RNSnowplowTracker.trackTimingEvent({
754
- tracker: namespace,
755
- eventData: argmap,
756
- contexts: contexts
757
- }))
758
- .catch((error) => {
759
- throw new Error(`${logMessages.trackTiming} ${error.message}`);
760
- });
761
- }
762
- /**
763
- * Tracks a consent-granted event
764
- *
765
- * @param namespace {string} - the tracker namespace
766
- * @param argmap {Object} - the event data
767
- * @param contexts {Array}- the event contexts
768
- * @returns {Promise}
769
- */
770
- function trackConsentGrantedEvent$1(namespace, argmap, contexts = []) {
771
- return validateConsentGranted(argmap)
772
- .then(() => validateContexts(contexts))
773
- .then(() => RNSnowplowTracker.trackConsentGrantedEvent({
774
- tracker: namespace,
775
- eventData: argmap,
776
- contexts: contexts
777
- }))
778
- .catch((error) => {
779
- throw new Error(`${logMessages.trackConsentGranted} ${error.message}`);
780
- });
781
- }
782
- /**
783
- * Tracks a consent-withdrawn event
784
- *
785
- * @param namespace {string} - the tracker namespace
786
- * @param argmap {Object} - the event data
787
- * @param contexts {Array}- the event contexts
788
- * @returns {Promise}
789
- */
790
- function trackConsentWithdrawnEvent$1(namespace, argmap, contexts = []) {
791
- return validateConsentWithdrawn(argmap)
792
- .then(() => validateContexts(contexts))
793
- .then(() => RNSnowplowTracker.trackConsentWithdrawnEvent({
794
- tracker: namespace,
795
- eventData: argmap,
796
- contexts: contexts
797
- }))
798
- .catch((error) => {
799
- throw new Error(`${logMessages.trackConsentWithdrawn} ${error.message}`);
800
- });
801
- }
802
- /**
803
- * Tracks an ecommerce-transaction event
804
- *
805
- * @param namespace {string} - the tracker namespace
806
- * @param argmap {Object} - the event data
807
- * @param contexts {Array}- the event contexts
808
- * @returns {Promise}
809
- */
810
- function trackEcommerceTransactionEvent$1(namespace, argmap, contexts = []) {
811
- return validateEcommerceTransaction(argmap)
812
- .then(() => validateContexts(contexts))
813
- .then(() => RNSnowplowTracker.trackEcommerceTransactionEvent({
814
- tracker: namespace,
815
- eventData: argmap,
816
- contexts: contexts
817
- }))
818
- .catch((error) => {
819
- throw new Error(`${logMessages.trackEcommerceTransaction} ${error.message}`);
820
- });
821
- }
822
- /**
823
- * Tracks a deep link received event
824
- *
825
- * @param namespace {string} - the tracker namespace
826
- * @param argmap {Object} - the event data
827
- * @param contexts {Array}- the event contexts
828
- * @returns {Promise}
829
- */
830
- function trackDeepLinkReceivedEvent$1(namespace, argmap, contexts = []) {
831
- return validateDeepLinkReceived(argmap)
832
- .then(() => validateContexts(contexts))
833
- .then(() => RNSnowplowTracker.trackDeepLinkReceivedEvent({
834
- tracker: namespace,
835
- eventData: argmap,
836
- contexts: contexts
837
- }))
838
- .catch((error) => {
839
- throw new Error(`${logMessages.trackDeepLinkReceived} ${error.message}`);
840
- });
841
- }
842
- /**
843
- * Tracks a message notification event
844
- *
845
- * @param namespace {string} - the tracker namespace
846
- * @param argmap {Object} - the event data
847
- * @param contexts {Array}- the event contexts
848
- * @returns {Promise}
849
- */
850
- function trackMessageNotificationEvent$1(namespace, argmap, contexts = []) {
851
- return validateMessageNotification(argmap)
852
- .then(() => validateContexts(contexts))
853
- .then(() => RNSnowplowTracker.trackMessageNotificationEvent({
854
- tracker: namespace,
855
- eventData: argmap,
856
- contexts: contexts
857
- }))
858
- .catch((error) => {
859
- throw new Error(`${logMessages.trackMessageNotification} ${error.message}`);
860
- });
861
- }
862
-
863
- /*
864
- * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
865
- *
866
- * This program is licensed to you under the Apache License Version 2.0,
867
- * and you may not use this file except in compliance with the Apache License Version 2.0.
868
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
869
- *
870
- * Unless required by applicable law or agreed to in writing,
871
- * software distributed under the Apache License Version 2.0 is distributed on an
872
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
873
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
874
- */
875
- /**
876
- * Sets the userId of the tracker subject
877
- *
878
- * @param namespace {string} - the tracker namespace
879
- * @param newUid {string | null} - the new userId
880
- * @returns - Promise
881
- */
882
- function setUserId$1(namespace, newUid) {
883
- if (!(newUid === null || typeof newUid === 'string')) {
884
- return Promise.reject(new Error(logMessages.setUserId));
885
- }
886
- return Promise.resolve(RNSnowplowTracker.setUserId({
887
- tracker: namespace,
888
- userId: newUid
889
- }));
890
- }
891
- /**
892
- * Sets the networkUserId of the tracker subject
893
- *
894
- * @param namespace {string} - the tracker namespace
895
- * @param newNuid {string | null} - the new networkUserId
896
- * @returns - Promise
897
- */
898
- function setNetworkUserId$1(namespace, newNuid) {
899
- if (!(newNuid === null || typeof newNuid === 'string')) {
900
- return Promise.reject(new Error(logMessages.setNetworkUserId));
901
- }
902
- return Promise.resolve(RNSnowplowTracker.setNetworkUserId({
903
- tracker: namespace,
904
- networkUserId: newNuid
905
- }));
906
- }
907
- /**
908
- * Sets the domainUserId of the tracker subject
909
- *
910
- * @param namespace {string} - the tracker namespace
911
- * @param newDuid {string | null} - the new domainUserId
912
- * @returns - Promise
913
- */
914
- function setDomainUserId$1(namespace, newDuid) {
915
- if (!(newDuid === null || typeof newDuid === 'string')) {
916
- return Promise.reject(new Error(logMessages.setDomainUserId));
917
- }
918
- return Promise.resolve(RNSnowplowTracker.setDomainUserId({
919
- tracker: namespace,
920
- domainUserId: newDuid
921
- }));
922
- }
923
- /**
924
- * Sets the ipAddress of the tracker subject
925
- *
926
- * @param namespace {string} - the tracker namespace
927
- * @param newIp {string | null} - the new ipAddress
928
- * @returns - Promise
929
- */
930
- function setIpAddress$1(namespace, newIp) {
931
- if (!(newIp === null || typeof newIp === 'string')) {
932
- return Promise.reject(new Error(logMessages.setIpAddress));
933
- }
934
- return Promise.resolve(RNSnowplowTracker.setIpAddress({
935
- tracker: namespace,
936
- ipAddress: newIp
937
- }));
938
- }
939
- /**
940
- * Sets the useragent of the tracker subject
941
- *
942
- * @param namespace {string} - the tracker namespace
943
- * @param newUagent {string | null} - the new useragent
944
- * @returns - Promise
945
- */
946
- function setUseragent$1(namespace, newUagent) {
947
- if (!(newUagent === null || typeof newUagent === 'string')) {
948
- return Promise.reject(new Error(logMessages.setUseragent));
949
- }
950
- return Promise.resolve(RNSnowplowTracker.setUseragent({
951
- tracker: namespace,
952
- useragent: newUagent
953
- }));
954
- }
955
- /**
956
- * Sets the timezone of the tracker subject
957
- *
958
- * @param namespace {string} - the tracker namespace
959
- * @param newTz {string | null} - the new timezone
960
- * @returns - Promise
961
- */
962
- function setTimezone$1(namespace, newTz) {
963
- if (!(newTz === null || typeof newTz === 'string')) {
964
- return Promise.reject(new Error(logMessages.setTimezone));
965
- }
966
- return Promise.resolve(RNSnowplowTracker.setTimezone({
967
- tracker: namespace,
968
- timezone: newTz
969
- }));
970
- }
971
- /**
972
- * Sets the language of the tracker subject
973
- *
974
- * @param namespace {string} - the tracker namespace
975
- * @param newLang {string | null} - the new language
976
- * @returns - Promise
977
- */
978
- function setLanguage$1(namespace, newLang) {
979
- if (!(newLang === null || typeof newLang === 'string')) {
980
- return Promise.reject(new Error(logMessages.setLanguage));
981
- }
982
- return Promise.resolve(RNSnowplowTracker.setLanguage({
983
- tracker: namespace,
984
- language: newLang
985
- }));
986
- }
987
- /**
988
- * Sets the screenResolution of the tracker subject
989
- *
990
- * @param namespace {string} - the tracker namespace
991
- * @param newRes {ScreenSize | null} - the new screenResolution
992
- * @returns - Promise
993
- */
994
- function setScreenResolution$1(namespace, newRes) {
995
- if (!(newRes === null || isScreenSize(newRes))) {
996
- return Promise.reject(new Error(logMessages.setScreenResolution));
997
- }
998
- return Promise.resolve(RNSnowplowTracker.setScreenResolution({
999
- tracker: namespace,
1000
- screenResolution: newRes
1001
- }));
1002
- }
1003
- /**
1004
- * Sets the screenViewport of the tracker subject
1005
- *
1006
- * @param namespace {string} - the tracker namespace
1007
- * @param newView {ScreenSize | null} - the new screenViewport
1008
- * @returns - Promise
1009
- */
1010
- function setScreenViewport$1(namespace, newView) {
1011
- if (!(newView === null || isScreenSize(newView))) {
1012
- return Promise.reject(new Error(logMessages.setScreenViewport));
1013
- }
1014
- return Promise.resolve(RNSnowplowTracker.setScreenViewport({
1015
- tracker: namespace,
1016
- screenViewport: newView
1017
- }));
1018
- }
1019
- /**
1020
- * Sets the colorDepth of the tracker subject
1021
- *
1022
- * @param namespace {string} - the tracker namespace
1023
- * @param newColorD {number | null} - the new colorDepth
1024
- * @returns - Promise
1025
- */
1026
- function setColorDepth$1(namespace, newColorD) {
1027
- if (!(newColorD === null || typeof newColorD === 'number')) {
1028
- return Promise.reject(new Error(logMessages.setColorDepth));
1029
- }
1030
- return Promise.resolve(RNSnowplowTracker.setColorDepth({
1031
- tracker: namespace,
1032
- colorDepth: newColorD
1033
- }));
1034
- }
1035
- const setterMap = {
1036
- userId: setUserId$1,
1037
- networkUserId: setNetworkUserId$1,
1038
- domainUserId: setDomainUserId$1,
1039
- ipAddress: setIpAddress$1,
1040
- useragent: setUseragent$1,
1041
- timezone: setTimezone$1,
1042
- language: setLanguage$1,
1043
- screenResolution: setScreenResolution$1,
1044
- screenViewport: setScreenViewport$1,
1045
- colorDepth: setColorDepth$1
1046
- };
1047
- /**
1048
- * Sets the tracker subject
1049
- *
1050
- * @param namespace {string} - the tracker namespace
1051
- * @param config {SubjectConfiguration} - the new subject data
1052
- * @returns - Promise
1053
- */
1054
- function setSubjectData$1(namespace, config) {
1055
- if (!isValidSubjectConf(config)) {
1056
- return Promise.reject(new Error(`${logMessages.setSubjectData} ${logMessages.subject}`));
1057
- }
1058
- const promises = Object.keys(config)
1059
- .map((k) => {
1060
- const fun = setterMap[k];
1061
- return fun ? fun(namespace, config[k]) : undefined;
1062
- })
1063
- .filter((f) => f !== undefined);
1064
- // to use Promise.all (Promise.allSettled not supported in all RN versions)
1065
- const safePromises = promises
1066
- .map((p) => p
1067
- .then((x) => Object.assign({
1068
- status: 'fulfilled',
1069
- value: x
1070
- }))
1071
- .catch((err) => Object.assign({
1072
- status: 'rejected',
1073
- reason: err.message
1074
- })));
1075
- return Promise.all(safePromises).then((outcomes) => {
1076
- const anyReasons = outcomes.filter((res) => res.status === 'rejected');
1077
- if (anyReasons.length > 0) {
1078
- const allReasons = anyReasons
1079
- .reduce((acc, curr) => acc + ':' + curr.reason, logMessages.setSubjectData);
1080
- throw new Error(allReasons);
1081
- }
1082
- return true;
1083
- });
1084
- }
1085
-
1086
- /*
1087
- * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
1088
- *
1089
- * This program is licensed to you under the Apache License Version 2.0,
1090
- * and you may not use this file except in compliance with the Apache License Version 2.0.
1091
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
1092
- *
1093
- * Unless required by applicable law or agreed to in writing,
1094
- * software distributed under the Apache License Version 2.0 is distributed on an
1095
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1096
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1097
- */
1098
- /**
1099
- * Create a tracker from specified initial configuration.
1100
- *
1101
- * @param initConfig {Object} - The initial tracker configuration
1102
- * @returns - A promise fullfilled if the tracker is initialized
1103
- */
1104
- function createTracker$1(initConfig) {
1105
- return initValidate(initConfig)
1106
- .then(() => RNSnowplowTracker.createTracker(initConfig))
1107
- .catch((error) => {
1108
- throw new Error(`${logMessages.createTracker} ${error.message}.`);
1109
- });
1110
- }
1111
- /**
1112
- * Removes the tracker with given namespace
1113
- *
1114
- * @param trackerNamespace {string} - The tracker namespace
1115
- * @returns - A boolean promise
1116
- */
1117
- function removeTracker$1(trackerNamespace) {
1118
- if (typeof trackerNamespace !== 'string') {
1119
- return Promise.reject(new Error(logMessages.removeTracker));
1120
- }
1121
- return Promise.resolve(RNSnowplowTracker.removeTracker({ tracker: trackerNamespace }));
1122
- }
1123
- /**
1124
- * Removes all existing trackers
1125
- *
1126
- * @returns - A void promise
1127
- */
1128
- function removeAllTrackers$1() {
1129
- return Promise.resolve(RNSnowplowTracker.removeAllTrackers());
1130
- }
1131
- /**
1132
- * Returns a function to track a SelfDescribing event by a tracker
1133
- *
1134
- * @param namespace {string} - The tracker namespace
1135
- * @returns - A function to track a SelfDescribing event
1136
- */
1137
- function trackSelfDescribingEvent(namespace) {
1138
- return function (argmap, contexts = []) {
1139
- return trackSelfDescribingEvent$1(namespace, argmap, contexts);
1140
- };
1141
- }
1142
- /**
1143
- * Returns a function to track a ScreenView event by a tracker
1144
- *
1145
- * @param namespace {string} - The tracker namespace
1146
- * @returns - A function to track a ScreenView event
1147
- */
1148
- function trackScreenViewEvent(namespace) {
1149
- return function (argmap, contexts = []) {
1150
- return trackScreenViewEvent$1(namespace, argmap, contexts);
1151
- };
1152
- }
1153
- /**
1154
- * Returns a function to track a Structured event by a tracker
1155
- *
1156
- * @param namespace {string} - The tracker namespace
1157
- * @returns - A function to track a Structured event
1158
- */
1159
- function trackStructuredEvent(namespace) {
1160
- return function (argmap, contexts = []) {
1161
- return trackStructuredEvent$1(namespace, argmap, contexts);
1162
- };
1163
- }
1164
- /**
1165
- * Returns a function to track a PageView event by a tracker
1166
- *
1167
- * @param namespace {string} - The tracker namespace
1168
- * @returns - A function to track a PageView event
1169
- */
1170
- function trackPageViewEvent(namespace) {
1171
- return function (argmap, contexts = []) {
1172
- return trackPageViewEvent$1(namespace, argmap, contexts);
1173
- };
1174
- }
1175
- /**
1176
- * Returns a function to track a Timing event by a tracker
1177
- *
1178
- * @param namespace {string} - The tracker namespace
1179
- * @returns - A function to track a Timing event
1180
- */
1181
- function trackTimingEvent(namespace) {
1182
- return function (argmap, contexts = []) {
1183
- return trackTimingEvent$1(namespace, argmap, contexts);
1184
- };
1185
- }
1186
- /**
1187
- * Returns a function to track a ConsentGranted event by a tracker
1188
- *
1189
- * @param namespace {string} - The tracker namespace
1190
- * @returns - A function to track a ConsentGranted event
1191
- */
1192
- function trackConsentGrantedEvent(namespace) {
1193
- return function (argmap, contexts = []) {
1194
- return trackConsentGrantedEvent$1(namespace, argmap, contexts);
1195
- };
1196
- }
1197
- /**
1198
- * Returns a function to track a ConsentWithdrawn event by a tracker
1199
- *
1200
- * @param namespace {string} - The tracker namespace
1201
- * @returns - A function to track a ConsentWithdrawn event
1202
- */
1203
- function trackConsentWithdrawnEvent(namespace) {
1204
- return function (argmap, contexts = []) {
1205
- return trackConsentWithdrawnEvent$1(namespace, argmap, contexts);
1206
- };
1207
- }
1208
- /**
1209
- * Returns a function to track an EcommerceTransaction event by a tracker
1210
- *
1211
- * @param namespace {string} - The tracker namespace
1212
- * @returns - A function to track an EcommerceTransaction event
1213
- */
1214
- function trackEcommerceTransactionEvent(namespace) {
1215
- return function (argmap, contexts = []) {
1216
- return trackEcommerceTransactionEvent$1(namespace, argmap, contexts);
1217
- };
1218
- }
1219
- /**
1220
- * Returns a function to track an DeepLinkReceived event by a tracker
1221
- *
1222
- * @param namespace {string} - The tracker namespace
1223
- * @returns - A function to track an DeepLinkReceived event
1224
- */
1225
- function trackDeepLinkReceivedEvent(namespace) {
1226
- return function (argmap, contexts = []) {
1227
- return trackDeepLinkReceivedEvent$1(namespace, argmap, contexts);
1228
- };
1229
- }
1230
- /**
1231
- * Returns a function to track an MessageNotification event by a tracker
1232
- *
1233
- * @param namespace {string} - The tracker namespace
1234
- * @returns - A function to track an MessageNotification event
1235
- */
1236
- function trackMessageNotificationEvent(namespace) {
1237
- return function (argmap, contexts = []) {
1238
- return trackMessageNotificationEvent$1(namespace, argmap, contexts);
1239
- };
1240
- }
1241
- /**
1242
- * Returns a function to remove global contexts by a tracker
1243
- *
1244
- * @param namespace {string} - The tracker namespace
1245
- * @returns - A function to remove global contexts
1246
- */
1247
- function removeGlobalContexts(namespace) {
1248
- return function (tag) {
1249
- if (typeof tag !== 'string') {
1250
- return Promise.reject(new Error(`${logMessages.removeGlobalContexts} ${logMessages.gcTagType}`));
1251
- }
1252
- return Promise.resolve(RNSnowplowTracker.removeGlobalContexts({ tracker: namespace, removeTag: tag }));
1253
- };
1254
- }
1255
- /**
1256
- * Returns a function to add global contexts by a tracker
1257
- *
1258
- * @param namespace {string} - The tracker namespace
1259
- * @returns - A function to add global contexts
1260
- */
1261
- function addGlobalContexts(namespace) {
1262
- return function (gc) {
1263
- if (!isValidGC(gc)) {
1264
- return Promise.reject(new Error(`${logMessages.addGlobalContexts} ${logMessages.gcType}`));
1265
- }
1266
- return Promise.resolve(RNSnowplowTracker.addGlobalContexts({ tracker: namespace, addGlobalContext: gc }));
1267
- };
1268
- }
1269
- /**
1270
- * Returns a function to set the subject userId
1271
- *
1272
- * @param namespace {string} - The tracker namespace
1273
- * @returns - A function to set the userId
1274
- */
1275
- function setUserId(namespace) {
1276
- return function (newUid) {
1277
- return setUserId$1(namespace, newUid);
1278
- };
1279
- }
1280
- /**
1281
- * Returns a function to set the subject networkUserId
1282
- *
1283
- * @param namespace {string} - The tracker namespace
1284
- * @returns - A function to set the networkUserId
1285
- */
1286
- function setNetworkUserId(namespace) {
1287
- return function (newNuid) {
1288
- return setNetworkUserId$1(namespace, newNuid);
1289
- };
1290
- }
1291
- /**
1292
- * Returns a function to set the subject domainUserId
1293
- *
1294
- * @param namespace {string} - The tracker namespace
1295
- * @returns - A function to set the domainUserId
1296
- */
1297
- function setDomainUserId(namespace) {
1298
- return function (newDuid) {
1299
- return setDomainUserId$1(namespace, newDuid);
1300
- };
1301
- }
1302
- /**
1303
- * Returns a function to set the subject ipAddress
1304
- *
1305
- * @param namespace {string} - The tracker namespace
1306
- * @returns - A function to set the ipAddress
1307
- */
1308
- function setIpAddress(namespace) {
1309
- return function (newIp) {
1310
- return setIpAddress$1(namespace, newIp);
1311
- };
1312
- }
1313
- /**
1314
- * Returns a function to set the subject useragent
1315
- *
1316
- * @param namespace {string} - The tracker namespace
1317
- * @returns - A function to set the useragent
1318
- */
1319
- function setUseragent(namespace) {
1320
- return function (newUagent) {
1321
- return setUseragent$1(namespace, newUagent);
1322
- };
1323
- }
1324
- /**
1325
- * Returns a function to set the subject timezone
1326
- *
1327
- * @param namespace {string} - The tracker namespace
1328
- * @returns - A function to set the timezone
1329
- */
1330
- function setTimezone(namespace) {
1331
- return function (newTz) {
1332
- return setTimezone$1(namespace, newTz);
1333
- };
1334
- }
1335
- /**
1336
- * Returns a function to set the subject language
1337
- *
1338
- * @param namespace {string} - The tracker namespace
1339
- * @returns - A function to set the language
1340
- */
1341
- function setLanguage(namespace) {
1342
- return function (newLang) {
1343
- return setLanguage$1(namespace, newLang);
1344
- };
1345
- }
1346
- /**
1347
- * Returns a function to set the subject screenResolution
1348
- *
1349
- * @param namespace {string} - The tracker namespace
1350
- * @returns - A function to set the screenResolution
1351
- */
1352
- function setScreenResolution(namespace) {
1353
- return function (newRes) {
1354
- return setScreenResolution$1(namespace, newRes);
1355
- };
1356
- }
1357
- /**
1358
- * Returns a function to set the subject screenViewport
1359
- *
1360
- * @param namespace {string} - The tracker namespace
1361
- * @returns - A function to set the screenViewport
1362
- */
1363
- function setScreenViewport(namespace) {
1364
- return function (newView) {
1365
- return setScreenViewport$1(namespace, newView);
1366
- };
1367
- }
1368
- /**
1369
- * Returns a function to set the subject colorDepth
1370
- *
1371
- * @param namespace {string} - The tracker namespace
1372
- * @returns - A function to set the colorDepth
1373
- */
1374
- function setColorDepth(namespace) {
1375
- return function (newColorD) {
1376
- return setColorDepth$1(namespace, newColorD);
1377
- };
1378
- }
1379
- /**
1380
- * Returns a function to set subject data
1381
- *
1382
- * @param namespace {string} - The tracker namespace
1383
- * @returns - A function to set subject data
1384
- */
1385
- function setSubjectData(namespace) {
1386
- return function (config) {
1387
- return setSubjectData$1(namespace, config);
1388
- };
1389
- }
1390
- /**
1391
- * Returns a function to get the current session userId
1392
- *
1393
- * @param namespace {string} - The tracker namespace
1394
- * @returns - A function to get the session userId
1395
- */
1396
- function getSessionUserId(namespace) {
1397
- return function () {
1398
- return Promise
1399
- .resolve(RNSnowplowTracker.getSessionUserId({ tracker: namespace }));
1400
- };
1401
- }
1402
- /**
1403
- * Returns a function to get the current sessionId
1404
- *
1405
- * @param namespace {string} - The tracker namespace
1406
- * @returns - A function to get the sessionId
1407
- */
1408
- function getSessionId(namespace) {
1409
- return function () {
1410
- return Promise
1411
- .resolve(RNSnowplowTracker.getSessionId({ tracker: namespace }));
1412
- };
1413
- }
1414
- /**
1415
- * Returns a function to get the current session index
1416
- *
1417
- * @param namespace {string} - The tracker namespace
1418
- * @returns - A function to get the session index
1419
- */
1420
- function getSessionIndex(namespace) {
1421
- return function () {
1422
- return Promise
1423
- .resolve(RNSnowplowTracker.getSessionIndex({ tracker: namespace }));
1424
- };
1425
- }
1426
- /**
1427
- * Returns a function to get whether the app is in background
1428
- *
1429
- * @param namespace {string} - The tracker namespace
1430
- * @returns - A function to get whether the app isInBackground
1431
- */
1432
- function getIsInBackground(namespace) {
1433
- return function () {
1434
- return Promise
1435
- .resolve(RNSnowplowTracker.getIsInBackground({ tracker: namespace }));
1436
- };
1437
- }
1438
- /**
1439
- * Returns a function to get the background index
1440
- *
1441
- * @param namespace {string} - The tracker namespace
1442
- * @returns - A function to get the backgroundIndex
1443
- */
1444
- function getBackgroundIndex(namespace) {
1445
- return function () {
1446
- return Promise
1447
- .resolve(RNSnowplowTracker.getBackgroundIndex({ tracker: namespace }));
1448
- };
1449
- }
1450
- /**
1451
- * Returns a function to get the foreground index
1452
- *
1453
- * @param namespace {string} - The tracker namespace
1454
- * @returns - A function to get the foregroundIndex
1455
- */
1456
- function getForegroundIndex(namespace) {
1457
- return function () {
1458
- return Promise
1459
- .resolve(RNSnowplowTracker.getForegroundIndex({ tracker: namespace }));
1460
- };
1461
- }
1462
-
1463
- /*
1464
- * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
1465
- *
1466
- * This program is licensed to you under the Apache License Version 2.0,
1467
- * and you may not use this file except in compliance with the Apache License Version 2.0.
1468
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
1469
- *
1470
- * Unless required by applicable law or agreed to in writing,
1471
- * software distributed under the Apache License Version 2.0 is distributed on an
1472
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1473
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1474
- */
1475
- function forEachTracker(trackers, iterator) {
1476
- if (trackers && trackers.length > 0) {
1477
- trackers.forEach(iterator);
1478
- }
1479
- else {
1480
- iterator(null);
1481
- }
1482
- }
1483
- /**
1484
- * Enables tracking events from apps rendered in react-native-webview components.
1485
- * The apps need to use the Snowplow WebView tracker to track the events.
1486
- *
1487
- * To subscribe for the events, set the `onMessage` attribute:
1488
- * <WebView onMessage={getWebViewCallback()} ... />
1489
- *
1490
- * @returns Callback to subscribe for events from Web views tracked using the Snowplow WebView tracker.
1491
- */
1492
- function getWebViewCallback() {
1493
- return (message) => {
1494
- const data = JSON.parse(message.nativeEvent.data);
1495
- switch (data.command) {
1496
- case 'trackSelfDescribingEvent':
1497
- forEachTracker(data.trackers, (namespace) => {
1498
- trackSelfDescribingEvent$1(namespace, data.event, data.context || []).catch((error) => {
1499
- errorHandler(error);
1500
- });
1501
- });
1502
- break;
1503
- case 'trackStructEvent':
1504
- forEachTracker(data.trackers, (namespace) => {
1505
- trackStructuredEvent$1(namespace, data.event, data.context || []).catch((error) => {
1506
- errorHandler(error);
1507
- });
1508
- });
1509
- break;
1510
- case 'trackPageView':
1511
- forEachTracker(data.trackers, (namespace) => {
1512
- const event = data.event;
1513
- trackPageViewEvent$1(namespace, {
1514
- pageTitle: event.title ?? '',
1515
- pageUrl: event.url ?? '',
1516
- referrer: event.referrer,
1517
- }).catch((error) => {
1518
- errorHandler(error);
1519
- });
1520
- });
1521
- break;
1522
- case 'trackScreenView':
1523
- forEachTracker(data.trackers, (namespace) => {
1524
- trackScreenViewEvent$1(namespace, data.event, data.context || []).catch((error) => {
1525
- errorHandler(error);
1526
- });
1527
- });
1528
- break;
1529
- }
1530
- };
1531
- }
1532
-
1533
- /*
1534
- * Copyright (c) 2020-2022 Snowplow Analytics Ltd. All rights reserved.
1535
- *
1536
- * This program is licensed to you under the Apache License Version 2.0,
1537
- * and you may not use this file except in compliance with the Apache License Version 2.0.
1538
- * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
1539
- *
1540
- * Unless required by applicable law or agreed to in writing,
1541
- * software distributed under the Apache License Version 2.0 is distributed on an
1542
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1543
- * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
1544
- */
1545
- /**
1546
- * Creates a React Native Tracker object
1547
- *
1548
- * @param namespace {string} - The tracker namespace
1549
- * @param networkConfig {Object} - The network configuration
1550
- * @param control {Array} - The tracker controller configuration
1551
- * @returns The tracker object
1552
- */
1553
- function createTracker(namespace, networkConfig, controllerConfig = {}) {
1554
- // initTrackerPromise
1555
- const initTrackerPromise = Promise.resolve(createTracker$1({
1556
- namespace,
1557
- networkConfig,
1558
- ...controllerConfig
1559
- }));
1560
- // mkMethod creates methods subscribed to the initTrackerPromise
1561
- const mkMethod = safeWait(initTrackerPromise, errorHandler);
1562
- // mkCallback creates callbacks subscribed to the initTrackerPromise
1563
- const mkCallback = safeWaitCallback(initTrackerPromise, errorHandler);
1564
- // track methods
1565
- const trackSelfDescribingEvent$1 = mkMethod(trackSelfDescribingEvent(namespace));
1566
- const trackScreenViewEvent$1 = mkMethod(trackScreenViewEvent(namespace));
1567
- const trackStructuredEvent$1 = mkMethod(trackStructuredEvent(namespace));
1568
- const trackPageViewEvent$1 = mkMethod(trackPageViewEvent(namespace));
1569
- const trackTimingEvent$1 = mkMethod(trackTimingEvent(namespace));
1570
- const trackConsentGrantedEvent$1 = mkMethod(trackConsentGrantedEvent(namespace));
1571
- const trackConsentWithdrawnEvent$1 = mkMethod(trackConsentWithdrawnEvent(namespace));
1572
- const trackEcommerceTransactionEvent$1 = mkMethod(trackEcommerceTransactionEvent(namespace));
1573
- const trackDeepLinkReceivedEvent$1 = mkMethod(trackDeepLinkReceivedEvent(namespace));
1574
- const trackMessageNotificationEvent$1 = mkMethod(trackMessageNotificationEvent(namespace));
1575
- // Global Contexts
1576
- const removeGlobalContexts$1 = mkMethod(removeGlobalContexts(namespace));
1577
- const addGlobalContexts$1 = mkMethod(addGlobalContexts(namespace));
1578
- // setters
1579
- const setUserId$1 = mkMethod(setUserId(namespace));
1580
- const setNetworkUserId$1 = mkMethod(setNetworkUserId(namespace));
1581
- const setDomainUserId$1 = mkMethod(setDomainUserId(namespace));
1582
- const setIpAddress$1 = mkMethod(setIpAddress(namespace));
1583
- const setUseragent$1 = mkMethod(setUseragent(namespace));
1584
- const setTimezone$1 = mkMethod(setTimezone(namespace));
1585
- const setLanguage$1 = mkMethod(setLanguage(namespace));
1586
- const setScreenResolution$1 = mkMethod(setScreenResolution(namespace));
1587
- const setScreenViewport$1 = mkMethod(setScreenViewport(namespace));
1588
- const setColorDepth$1 = mkMethod(setColorDepth(namespace));
1589
- const setSubjectData$1 = mkMethod(setSubjectData(namespace));
1590
- // callbacks
1591
- const getSessionUserId$1 = mkCallback(getSessionUserId(namespace));
1592
- const getSessionId$1 = mkCallback(getSessionId(namespace));
1593
- const getSessionIndex$1 = mkCallback(getSessionIndex(namespace));
1594
- const getIsInBackground$1 = mkCallback(getIsInBackground(namespace));
1595
- const getBackgroundIndex$1 = mkCallback(getBackgroundIndex(namespace));
1596
- const getForegroundIndex$1 = mkCallback(getForegroundIndex(namespace));
1597
- return Object.freeze({
1598
- trackSelfDescribingEvent: trackSelfDescribingEvent$1,
1599
- trackScreenViewEvent: trackScreenViewEvent$1,
1600
- trackStructuredEvent: trackStructuredEvent$1,
1601
- trackPageViewEvent: trackPageViewEvent$1,
1602
- trackTimingEvent: trackTimingEvent$1,
1603
- trackConsentGrantedEvent: trackConsentGrantedEvent$1,
1604
- trackConsentWithdrawnEvent: trackConsentWithdrawnEvent$1,
1605
- trackEcommerceTransactionEvent: trackEcommerceTransactionEvent$1,
1606
- trackDeepLinkReceivedEvent: trackDeepLinkReceivedEvent$1,
1607
- trackMessageNotificationEvent: trackMessageNotificationEvent$1,
1608
- removeGlobalContexts: removeGlobalContexts$1,
1609
- addGlobalContexts: addGlobalContexts$1,
1610
- setUserId: setUserId$1,
1611
- setNetworkUserId: setNetworkUserId$1,
1612
- setDomainUserId: setDomainUserId$1,
1613
- setIpAddress: setIpAddress$1,
1614
- setUseragent: setUseragent$1,
1615
- setTimezone: setTimezone$1,
1616
- setLanguage: setLanguage$1,
1617
- setScreenResolution: setScreenResolution$1,
1618
- setScreenViewport: setScreenViewport$1,
1619
- setColorDepth: setColorDepth$1,
1620
- setSubjectData: setSubjectData$1,
1621
- getSessionUserId: getSessionUserId$1,
1622
- getSessionId: getSessionId$1,
1623
- getSessionIndex: getSessionIndex$1,
1624
- getIsInBackground: getIsInBackground$1,
1625
- getBackgroundIndex: getBackgroundIndex$1,
1626
- getForegroundIndex: getForegroundIndex$1,
1627
- });
1628
- }
1629
- /**
1630
- * Removes a tracker given its namespace
1631
- *
1632
- * @param trackerNamespace {string}
1633
- * @returns - A boolean promise
1634
- */
1635
- function removeTracker(trackerNamespace) {
1636
- return removeTracker$1(trackerNamespace)
1637
- .catch((e) => errorHandler(e));
1638
- }
1639
- /**
1640
- * Removes all trackers
1641
- *
1642
- * @returns - A boolean promise
1643
- */
1644
- function removeAllTrackers() {
1645
- return removeAllTrackers$1()
1646
- .catch((e) => errorHandler(e));
1647
- }
1648
-
1649
- export { createTracker, getWebViewCallback, removeAllTrackers, removeTracker };
1650
- //# sourceMappingURL=index.js.map