@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/src/api.ts ADDED
@@ -0,0 +1,535 @@
1
+ /*
2
+ * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
3
+ *
4
+ * This program is licensed to you under the Apache License Version 2.0,
5
+ * and you may not use this file except in compliance with the Apache License Version 2.0.
6
+ * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
+ *
8
+ * Unless required by applicable law or agreed to in writing,
9
+ * software distributed under the Apache License Version 2.0 is distributed on an
10
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12
+ */
13
+
14
+ 'use strict';
15
+
16
+ import { RNSnowplowTracker } from './native';
17
+ import { initValidate, isValidGC } from './configurations';
18
+ import { logMessages } from './constants';
19
+ import * as tracker from './tracker';
20
+ import * as subject from './subject';
21
+
22
+ import type {
23
+ InitTrackerConfiguration,
24
+ SubjectConfiguration,
25
+ SelfDescribing,
26
+ EventContext,
27
+ ScreenViewProps,
28
+ StructuredProps,
29
+ PageViewProps,
30
+ TimingProps,
31
+ ConsentGrantedProps,
32
+ ConsentWithdrawnProps,
33
+ EcommerceTransactionProps,
34
+ GlobalContext,
35
+ ScreenSize,
36
+ DeepLinkReceivedProps,
37
+ MessageNotificationProps,
38
+ } from './types';
39
+
40
+ /**
41
+ * Create a tracker from specified initial configuration.
42
+ *
43
+ * @param initConfig {Object} - The initial tracker configuration
44
+ * @returns - A promise fullfilled if the tracker is initialized
45
+ */
46
+ function createTracker(initConfig: InitTrackerConfiguration): Promise<void> {
47
+ return <Promise<void>>initValidate(initConfig)
48
+ .then(() => <Promise<void>>RNSnowplowTracker.createTracker(initConfig))
49
+ .catch((error) => {
50
+ throw new Error(`${logMessages.createTracker} ${error.message}.`);
51
+ });
52
+ }
53
+
54
+ /**
55
+ * Removes the tracker with given namespace
56
+ *
57
+ * @param trackerNamespace {string} - The tracker namespace
58
+ * @returns - A boolean promise
59
+ */
60
+ function removeTracker(trackerNamespace: string): Promise<boolean> {
61
+ if (typeof trackerNamespace !== 'string') {
62
+ return Promise.reject(new Error(logMessages.removeTracker));
63
+ }
64
+ return <Promise<boolean>>(
65
+ Promise.resolve(
66
+ RNSnowplowTracker.removeTracker({ tracker: trackerNamespace })
67
+ )
68
+ );
69
+ }
70
+
71
+ /**
72
+ * Removes all existing trackers
73
+ *
74
+ * @returns - A void promise
75
+ */
76
+ function removeAllTrackers(): Promise<boolean> {
77
+ return <Promise<boolean>>(
78
+ Promise.resolve(RNSnowplowTracker.removeAllTrackers())
79
+ );
80
+ }
81
+
82
+ /**
83
+ * Returns a function to track a SelfDescribing event by a tracker
84
+ *
85
+ * @param namespace {string} - The tracker namespace
86
+ * @returns - A function to track a SelfDescribing event
87
+ */
88
+ function trackSelfDescribingEvent(namespace: string) {
89
+ return function (
90
+ argmap: SelfDescribing,
91
+ contexts: EventContext[] = []
92
+ ): Promise<void> {
93
+ return tracker.trackSelfDescribingEvent(namespace, argmap, contexts);
94
+ };
95
+ }
96
+
97
+ /**
98
+ * Returns a function to track a ScreenView event by a tracker
99
+ *
100
+ * @param namespace {string} - The tracker namespace
101
+ * @returns - A function to track a ScreenView event
102
+ */
103
+ function trackScreenViewEvent(namespace: string) {
104
+ return function (
105
+ argmap: ScreenViewProps,
106
+ contexts: EventContext[] = []
107
+ ): Promise<void> {
108
+ return tracker.trackScreenViewEvent(namespace, argmap, contexts);
109
+ };
110
+ }
111
+
112
+ /**
113
+ * Returns a function to track a Structured event by a tracker
114
+ *
115
+ * @param namespace {string} - The tracker namespace
116
+ * @returns - A function to track a Structured event
117
+ */
118
+ function trackStructuredEvent(namespace: string) {
119
+ return function (
120
+ argmap: StructuredProps,
121
+ contexts: EventContext[] = []
122
+ ): Promise<void> {
123
+ return tracker.trackStructuredEvent(namespace, argmap, contexts);
124
+ };
125
+ }
126
+
127
+ /**
128
+ * Returns a function to track a PageView event by a tracker
129
+ *
130
+ * @param namespace {string} - The tracker namespace
131
+ * @returns - A function to track a PageView event
132
+ */
133
+ function trackPageViewEvent(namespace: string) {
134
+ return function (
135
+ argmap: PageViewProps,
136
+ contexts: EventContext[] = []
137
+ ): Promise<void> {
138
+ return tracker.trackPageViewEvent(namespace, argmap, contexts);
139
+ };
140
+ }
141
+
142
+ /**
143
+ * Returns a function to track a Timing event by a tracker
144
+ *
145
+ * @param namespace {string} - The tracker namespace
146
+ * @returns - A function to track a Timing event
147
+ */
148
+ function trackTimingEvent(namespace: string) {
149
+ return function (
150
+ argmap: TimingProps,
151
+ contexts: EventContext[] = []
152
+ ): Promise<void> {
153
+ return tracker.trackTimingEvent(namespace, argmap, contexts);
154
+ };
155
+ }
156
+
157
+ /**
158
+ * Returns a function to track a ConsentGranted event by a tracker
159
+ *
160
+ * @param namespace {string} - The tracker namespace
161
+ * @returns - A function to track a ConsentGranted event
162
+ */
163
+ function trackConsentGrantedEvent(namespace: string) {
164
+ return function (
165
+ argmap: ConsentGrantedProps,
166
+ contexts: EventContext[] = []
167
+ ): Promise<void> {
168
+ return tracker.trackConsentGrantedEvent(namespace, argmap, contexts);
169
+ };
170
+ }
171
+
172
+ /**
173
+ * Returns a function to track a ConsentWithdrawn event by a tracker
174
+ *
175
+ * @param namespace {string} - The tracker namespace
176
+ * @returns - A function to track a ConsentWithdrawn event
177
+ */
178
+ function trackConsentWithdrawnEvent(namespace: string) {
179
+ return function (
180
+ argmap: ConsentWithdrawnProps,
181
+ contexts: EventContext[] = []
182
+ ): Promise<void> {
183
+ return tracker.trackConsentWithdrawnEvent(namespace, argmap, contexts);
184
+ };
185
+ }
186
+
187
+ /**
188
+ * Returns a function to track an EcommerceTransaction event by a tracker
189
+ *
190
+ * @param namespace {string} - The tracker namespace
191
+ * @returns - A function to track an EcommerceTransaction event
192
+ */
193
+ function trackEcommerceTransactionEvent(namespace: string) {
194
+ return function (
195
+ argmap: EcommerceTransactionProps,
196
+ contexts: EventContext[] = []
197
+ ): Promise<void> {
198
+ return tracker.trackEcommerceTransactionEvent(namespace, argmap, contexts);
199
+ };
200
+ }
201
+
202
+ /**
203
+ * Returns a function to track an DeepLinkReceived event by a tracker
204
+ *
205
+ * @param namespace {string} - The tracker namespace
206
+ * @returns - A function to track an DeepLinkReceived event
207
+ */
208
+ function trackDeepLinkReceivedEvent(namespace: string) {
209
+ return function (
210
+ argmap: DeepLinkReceivedProps,
211
+ contexts: EventContext[] = []
212
+ ): Promise<void> {
213
+ return tracker.trackDeepLinkReceivedEvent(namespace, argmap, contexts);
214
+ };
215
+ }
216
+
217
+ /**
218
+ * Returns a function to track an MessageNotification event by a tracker
219
+ *
220
+ * @param namespace {string} - The tracker namespace
221
+ * @returns - A function to track an MessageNotification event
222
+ */
223
+ function trackMessageNotificationEvent(namespace: string) {
224
+ return function (
225
+ argmap: MessageNotificationProps,
226
+ contexts: EventContext[] = []
227
+ ): Promise<void> {
228
+ return tracker.trackMessageNotificationEvent(namespace, argmap, contexts);
229
+ };
230
+ }
231
+
232
+ /**
233
+ * Returns a function to remove global contexts by a tracker
234
+ *
235
+ * @param namespace {string} - The tracker namespace
236
+ * @returns - A function to remove global contexts
237
+ */
238
+ function removeGlobalContexts(namespace: string) {
239
+ return function (tag: string): Promise<void> {
240
+ if (typeof tag !== 'string') {
241
+ return Promise.reject(
242
+ new Error(
243
+ `${logMessages.removeGlobalContexts} ${logMessages.gcTagType}`
244
+ )
245
+ );
246
+ }
247
+ return Promise.resolve(
248
+ RNSnowplowTracker.removeGlobalContexts({
249
+ tracker: namespace,
250
+ removeTag: tag,
251
+ })
252
+ );
253
+ };
254
+ }
255
+
256
+ /**
257
+ * Returns a function to add global contexts by a tracker
258
+ *
259
+ * @param namespace {string} - The tracker namespace
260
+ * @returns - A function to add global contexts
261
+ */
262
+ function addGlobalContexts(namespace: string) {
263
+ return function (gc: GlobalContext): Promise<void> {
264
+ if (!isValidGC(gc)) {
265
+ return Promise.reject(
266
+ new Error(`${logMessages.addGlobalContexts} ${logMessages.gcType}`)
267
+ );
268
+ }
269
+ return Promise.resolve(
270
+ RNSnowplowTracker.addGlobalContexts({
271
+ tracker: namespace,
272
+ addGlobalContext: gc,
273
+ })
274
+ );
275
+ };
276
+ }
277
+
278
+ /**
279
+ * Returns a function to set the subject userId
280
+ *
281
+ * @param namespace {string} - The tracker namespace
282
+ * @returns - A function to set the userId
283
+ */
284
+ function setUserId(namespace: string) {
285
+ return function (newUid: string | null): Promise<void> {
286
+ return subject.setUserId(namespace, newUid);
287
+ };
288
+ }
289
+
290
+ /**
291
+ * Returns a function to set the subject networkUserId
292
+ *
293
+ * @param namespace {string} - The tracker namespace
294
+ * @returns - A function to set the networkUserId
295
+ */
296
+ function setNetworkUserId(namespace: string) {
297
+ return function (newNuid: string | null): Promise<void> {
298
+ return subject.setNetworkUserId(namespace, newNuid);
299
+ };
300
+ }
301
+
302
+ /**
303
+ * Returns a function to set the subject domainUserId
304
+ *
305
+ * @param namespace {string} - The tracker namespace
306
+ * @returns - A function to set the domainUserId
307
+ */
308
+ function setDomainUserId(namespace: string) {
309
+ return function (newDuid: string | null): Promise<void> {
310
+ return subject.setDomainUserId(namespace, newDuid);
311
+ };
312
+ }
313
+
314
+ /**
315
+ * Returns a function to set the subject ipAddress
316
+ *
317
+ * @param namespace {string} - The tracker namespace
318
+ * @returns - A function to set the ipAddress
319
+ */
320
+ function setIpAddress(namespace: string) {
321
+ return function (newIp: string | null): Promise<void> {
322
+ return subject.setIpAddress(namespace, newIp);
323
+ };
324
+ }
325
+
326
+ /**
327
+ * Returns a function to set the subject useragent
328
+ *
329
+ * @param namespace {string} - The tracker namespace
330
+ * @returns - A function to set the useragent
331
+ */
332
+ function setUseragent(namespace: string) {
333
+ return function (newUagent: string | null): Promise<void> {
334
+ return subject.setUseragent(namespace, newUagent);
335
+ };
336
+ }
337
+
338
+ /**
339
+ * Returns a function to set the subject timezone
340
+ *
341
+ * @param namespace {string} - The tracker namespace
342
+ * @returns - A function to set the timezone
343
+ */
344
+ function setTimezone(namespace: string) {
345
+ return function (newTz: string | null): Promise<void> {
346
+ return subject.setTimezone(namespace, newTz);
347
+ };
348
+ }
349
+
350
+ /**
351
+ * Returns a function to set the subject language
352
+ *
353
+ * @param namespace {string} - The tracker namespace
354
+ * @returns - A function to set the language
355
+ */
356
+ function setLanguage(namespace: string) {
357
+ return function (newLang: string | null): Promise<void> {
358
+ return subject.setLanguage(namespace, newLang);
359
+ };
360
+ }
361
+
362
+ /**
363
+ * Returns a function to set the subject screenResolution
364
+ *
365
+ * @param namespace {string} - The tracker namespace
366
+ * @returns - A function to set the screenResolution
367
+ */
368
+ function setScreenResolution(namespace: string) {
369
+ return function (newRes: ScreenSize | null): Promise<void> {
370
+ return subject.setScreenResolution(namespace, newRes);
371
+ };
372
+ }
373
+
374
+ /**
375
+ * Returns a function to set the subject screenViewport
376
+ *
377
+ * @param namespace {string} - The tracker namespace
378
+ * @returns - A function to set the screenViewport
379
+ */
380
+ function setScreenViewport(namespace: string) {
381
+ return function (newView: ScreenSize | null): Promise<void> {
382
+ return subject.setScreenViewport(namespace, newView);
383
+ };
384
+ }
385
+
386
+ /**
387
+ * Returns a function to set the subject colorDepth
388
+ *
389
+ * @param namespace {string} - The tracker namespace
390
+ * @returns - A function to set the colorDepth
391
+ */
392
+ function setColorDepth(namespace: string) {
393
+ return function (newColorD: number | null): Promise<void> {
394
+ return subject.setColorDepth(namespace, newColorD);
395
+ };
396
+ }
397
+
398
+ /**
399
+ * Returns a function to set subject data
400
+ *
401
+ * @param namespace {string} - The tracker namespace
402
+ * @returns - A function to set subject data
403
+ */
404
+ function setSubjectData(namespace: string) {
405
+ return function (config: SubjectConfiguration): Promise<void> {
406
+ return subject.setSubjectData(namespace, config);
407
+ };
408
+ }
409
+
410
+ /**
411
+ * Returns a function to get the current session userId
412
+ *
413
+ * @param namespace {string} - The tracker namespace
414
+ * @returns - A function to get the session userId
415
+ */
416
+ function getSessionUserId(namespace: string) {
417
+ return function (): Promise<string> {
418
+ return <Promise<string>>(
419
+ Promise.resolve(
420
+ RNSnowplowTracker.getSessionUserId({ tracker: namespace })
421
+ )
422
+ );
423
+ };
424
+ }
425
+
426
+ /**
427
+ * Returns a function to get the current sessionId
428
+ *
429
+ * @param namespace {string} - The tracker namespace
430
+ * @returns - A function to get the sessionId
431
+ */
432
+ function getSessionId(namespace: string) {
433
+ return function (): Promise<string> {
434
+ return <Promise<string>>(
435
+ Promise.resolve(RNSnowplowTracker.getSessionId({ tracker: namespace }))
436
+ );
437
+ };
438
+ }
439
+
440
+ /**
441
+ * Returns a function to get the current session index
442
+ *
443
+ * @param namespace {string} - The tracker namespace
444
+ * @returns - A function to get the session index
445
+ */
446
+ function getSessionIndex(namespace: string) {
447
+ return function (): Promise<number> {
448
+ return <Promise<number>>(
449
+ Promise.resolve(RNSnowplowTracker.getSessionIndex({ tracker: namespace }))
450
+ );
451
+ };
452
+ }
453
+
454
+ /**
455
+ * Returns a function to get whether the app is in background
456
+ *
457
+ * @param namespace {string} - The tracker namespace
458
+ * @returns - A function to get whether the app isInBackground
459
+ */
460
+ function getIsInBackground(namespace: string) {
461
+ return function (): Promise<boolean> {
462
+ return <Promise<boolean>>(
463
+ Promise.resolve(
464
+ RNSnowplowTracker.getIsInBackground({ tracker: namespace })
465
+ )
466
+ );
467
+ };
468
+ }
469
+
470
+ /**
471
+ * Returns a function to get the background index
472
+ *
473
+ * @param namespace {string} - The tracker namespace
474
+ * @returns - A function to get the backgroundIndex
475
+ */
476
+ function getBackgroundIndex(namespace: string) {
477
+ return function (): Promise<number> {
478
+ return <Promise<number>>(
479
+ Promise.resolve(
480
+ RNSnowplowTracker.getBackgroundIndex({ tracker: namespace })
481
+ )
482
+ );
483
+ };
484
+ }
485
+
486
+ /**
487
+ * Returns a function to get the foreground index
488
+ *
489
+ * @param namespace {string} - The tracker namespace
490
+ * @returns - A function to get the foregroundIndex
491
+ */
492
+ function getForegroundIndex(namespace: string) {
493
+ return function (): Promise<number> {
494
+ return <Promise<number>>(
495
+ Promise.resolve(
496
+ RNSnowplowTracker.getForegroundIndex({ tracker: namespace })
497
+ )
498
+ );
499
+ };
500
+ }
501
+
502
+ export {
503
+ createTracker,
504
+ removeTracker,
505
+ removeAllTrackers,
506
+ trackSelfDescribingEvent,
507
+ trackScreenViewEvent,
508
+ trackStructuredEvent,
509
+ trackPageViewEvent,
510
+ trackTimingEvent,
511
+ trackConsentGrantedEvent,
512
+ trackConsentWithdrawnEvent,
513
+ trackEcommerceTransactionEvent,
514
+ trackDeepLinkReceivedEvent,
515
+ trackMessageNotificationEvent,
516
+ removeGlobalContexts,
517
+ addGlobalContexts,
518
+ setUserId,
519
+ setNetworkUserId,
520
+ setDomainUserId,
521
+ setIpAddress,
522
+ setUseragent,
523
+ setTimezone,
524
+ setLanguage,
525
+ setScreenResolution,
526
+ setScreenViewport,
527
+ setColorDepth,
528
+ setSubjectData,
529
+ getSessionUserId,
530
+ getSessionId,
531
+ getSessionIndex,
532
+ getIsInBackground,
533
+ getBackgroundIndex,
534
+ getForegroundIndex,
535
+ };