@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
@@ -0,0 +1,17 @@
1
+ package com.snowplow.reactnativetracker
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+
9
+ class ReactNativeTrackerPackage : ReactPackage {
10
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
+ return listOf(ReactNativeTrackerModule(reactContext))
12
+ }
13
+
14
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
15
+ return emptyList()
16
+ }
17
+ }
@@ -0,0 +1,271 @@
1
+ package com.snowplow.reactnativetracker.util
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReadableArray
5
+ import com.facebook.react.bridge.ReadableMap
6
+ import com.snowplowanalytics.snowplow.configuration.*
7
+ import com.snowplowanalytics.snowplow.emitter.BufferOption
8
+ import com.snowplowanalytics.snowplow.globalcontexts.GlobalContext
9
+ import com.snowplowanalytics.snowplow.payload.SelfDescribingJson
10
+ import com.snowplowanalytics.snowplow.tracker.DevicePlatform
11
+ import com.snowplowanalytics.snowplow.tracker.LogLevel
12
+ import com.snowplowanalytics.snowplow.util.Basis
13
+ import com.snowplowanalytics.snowplow.util.Size
14
+ import com.snowplowanalytics.snowplow.util.TimeMeasure
15
+ import java.util.concurrent.TimeUnit
16
+
17
+ object ConfigUtil {
18
+ fun mkTrackerConfiguration(
19
+ trackerConfig: ReadableMap?,
20
+ context: ReactApplicationContext
21
+ ): TrackerConfiguration {
22
+ val appId = trackerConfig?.getString("appId") ?: context.packageName
23
+ val trackerConfiguration = TrackerConfiguration(appId)
24
+ .trackerVersionSuffix(TrackerVersion.RN_TRACKER_VERSION)
25
+ .screenViewAutotracking(false)
26
+
27
+ val trackerConfig = trackerConfig ?: run { return trackerConfiguration }
28
+ if (trackerConfig.hasKey("devicePlatform")) {
29
+ val devicePlatform = mkDevicePlatform(trackerConfig.getString("devicePlatform")!!)
30
+ trackerConfiguration.devicePlatform(devicePlatform)
31
+ }
32
+ if (trackerConfig.hasKey("logLevel")) {
33
+ val logLevel = mkLogLevel(trackerConfig.getString("logLevel")!!)
34
+ trackerConfiguration.logLevel(logLevel)
35
+ }
36
+ if (trackerConfig.hasKey("base64Encoding")) {
37
+ trackerConfiguration.base64encoding(trackerConfig.getBoolean("base64Encoding"))
38
+ }
39
+ if (trackerConfig.hasKey("applicationContext")) {
40
+ trackerConfiguration.applicationContext(trackerConfig.getBoolean("applicationContext"))
41
+ }
42
+ if (trackerConfig.hasKey("platformContext")) {
43
+ trackerConfiguration.platformContext(trackerConfig.getBoolean("platformContext"))
44
+ }
45
+ if (trackerConfig.hasKey("geoLocationContext")) {
46
+ trackerConfiguration.geoLocationContext(trackerConfig.getBoolean("geoLocationContext"))
47
+ }
48
+ if (trackerConfig.hasKey("sessionContext")) {
49
+ trackerConfiguration.sessionContext(trackerConfig.getBoolean("sessionContext"))
50
+ }
51
+ if (trackerConfig.hasKey("screenContext")) {
52
+ trackerConfiguration.screenContext(trackerConfig.getBoolean("screenContext"))
53
+ }
54
+ if (trackerConfig.hasKey("screenViewAutotracking")) {
55
+ trackerConfiguration.screenViewAutotracking(trackerConfig.getBoolean("screenViewAutotracking"))
56
+ }
57
+ if (trackerConfig.hasKey("lifecycleAutotracking")) {
58
+ trackerConfiguration.lifecycleAutotracking(trackerConfig.getBoolean("lifecycleAutotracking"))
59
+ }
60
+ if (trackerConfig.hasKey("installAutotracking")) {
61
+ trackerConfiguration.installAutotracking(trackerConfig.getBoolean("installAutotracking"))
62
+ }
63
+ if (trackerConfig.hasKey("exceptionAutotracking")) {
64
+ trackerConfiguration.exceptionAutotracking(trackerConfig.getBoolean("exceptionAutotracking"))
65
+ }
66
+ if (trackerConfig.hasKey("diagnosticAutotracking")) {
67
+ trackerConfiguration.diagnosticAutotracking(trackerConfig.getBoolean("diagnosticAutotracking"))
68
+ }
69
+ if (trackerConfig.hasKey("deepLinkContext")) {
70
+ trackerConfiguration.deepLinkContext(trackerConfig.getBoolean("deepLinkContext"))
71
+ }
72
+ if (trackerConfig.hasKey("userAnonymisation")) {
73
+ trackerConfiguration.userAnonymisation(trackerConfig.getBoolean("userAnonymisation"))
74
+ }
75
+ return trackerConfiguration
76
+ }
77
+
78
+ fun mkSessionConfiguration(sessionConfig: ReadableMap): SessionConfiguration {
79
+ val foregroundTimeout = sessionConfig.getDouble("foregroundTimeout").toLong()
80
+ val backgroundTimeout = sessionConfig.getDouble("backgroundTimeout").toLong()
81
+ return SessionConfiguration(
82
+ TimeMeasure(foregroundTimeout, TimeUnit.SECONDS),
83
+ TimeMeasure(backgroundTimeout, TimeUnit.SECONDS)
84
+ )
85
+ }
86
+
87
+ fun mkEmitterConfiguration(emitterConfig: ReadableMap): EmitterConfiguration {
88
+ val emitterConfiguration = EmitterConfiguration()
89
+ emitterConfig.getString("bufferOption")?.let { opt -> mkBufferOption(opt)?.let { emitterConfiguration.bufferOption(it) } }
90
+ if (emitterConfig.hasKey("emitRange")) {
91
+ val emitRange = emitterConfig.getDouble("emitRange").toInt()
92
+ emitterConfiguration.emitRange(emitRange)
93
+ }
94
+ if (emitterConfig.hasKey("threadPoolSize")) {
95
+ val threadPoolSize = emitterConfig.getDouble("threadPoolSize").toInt()
96
+ emitterConfiguration.threadPoolSize(threadPoolSize)
97
+ }
98
+ if (emitterConfig.hasKey("byteLimitPost")) {
99
+ val byteLimitPost = emitterConfig.getDouble("byteLimitPost").toInt()
100
+ emitterConfiguration.byteLimitPost(byteLimitPost)
101
+ }
102
+ if (emitterConfig.hasKey("byteLimitGet")) {
103
+ val byteLimitGet = emitterConfig.getDouble("byteLimitGet").toInt()
104
+ emitterConfiguration.byteLimitGet(byteLimitGet)
105
+ }
106
+ if (emitterConfig.hasKey("serverAnonymisation")) {
107
+ emitterConfiguration.serverAnonymisation(emitterConfig.getBoolean("serverAnonymisation"))
108
+ }
109
+ return emitterConfiguration
110
+ }
111
+
112
+ fun mkSubjectConfiguration(subjectConfig: ReadableMap): SubjectConfiguration {
113
+ val subjectConfiguration = SubjectConfiguration()
114
+ if (subjectConfig.hasKey("userId")) {
115
+ if (subjectConfig.isNull("userId")) {
116
+ subjectConfiguration.userId(null)
117
+ } else {
118
+ subjectConfiguration.userId(subjectConfig.getString("userId"))
119
+ }
120
+ }
121
+ if (subjectConfig.hasKey("networkUserId")) {
122
+ if (subjectConfig.isNull("networkUserId")) {
123
+ subjectConfiguration.networkUserId(null)
124
+ } else {
125
+ subjectConfiguration.networkUserId(subjectConfig.getString("networkUserId"))
126
+ }
127
+ }
128
+ if (subjectConfig.hasKey("domainUserId")) {
129
+ if (subjectConfig.isNull("domainUserId")) {
130
+ subjectConfiguration.domainUserId(null)
131
+ } else {
132
+ subjectConfiguration.domainUserId(subjectConfig.getString("domainUserId"))
133
+ }
134
+ }
135
+ if (subjectConfig.hasKey("useragent")) {
136
+ if (subjectConfig.isNull("useragent")) {
137
+ subjectConfiguration.useragent(null)
138
+ } else {
139
+ subjectConfiguration.useragent(subjectConfig.getString("useragent"))
140
+ }
141
+ }
142
+ if (subjectConfig.hasKey("ipAddress")) {
143
+ if (subjectConfig.isNull("ipAddress")) {
144
+ subjectConfiguration.ipAddress(null)
145
+ } else {
146
+ subjectConfiguration.ipAddress(subjectConfig.getString("ipAddress"))
147
+ }
148
+ }
149
+ if (subjectConfig.hasKey("timezone")) {
150
+ if (subjectConfig.isNull("timezone")) {
151
+ subjectConfiguration.timezone(null)
152
+ } else {
153
+ subjectConfiguration.timezone(subjectConfig.getString("timezone"))
154
+ }
155
+ }
156
+ if (subjectConfig.hasKey("language")) {
157
+ if (subjectConfig.isNull("language")) {
158
+ subjectConfiguration.language(null)
159
+ } else {
160
+ subjectConfiguration.language(subjectConfig.getString("language"))
161
+ }
162
+ }
163
+ if (subjectConfig.hasKey("screenResolution")) {
164
+ if (subjectConfig.isNull("screenResolution")) {
165
+ subjectConfiguration.screenResolution(null)
166
+ } else {
167
+ val screenRes: ReadableArray = subjectConfig.getArray("screenResolution")!!
168
+ val screenWidth = screenRes.getDouble(0).toInt()
169
+ val screenHeight = screenRes.getDouble(1).toInt()
170
+ val screenResolution = Size(screenWidth, screenHeight)
171
+ subjectConfiguration.screenResolution(screenResolution)
172
+ }
173
+ }
174
+ if (subjectConfig.hasKey("screenViewport")) {
175
+ if (subjectConfig.isNull("screenViewport")) {
176
+ subjectConfiguration.screenViewPort(null)
177
+ } else {
178
+ val screenVP: ReadableArray = subjectConfig.getArray("screenViewport")!!
179
+ val screenVPWidth = screenVP.getDouble(0).toInt()
180
+ val screenVPHeight = screenVP.getDouble(1).toInt()
181
+ val screenViewport = Size(screenVPWidth, screenVPHeight)
182
+ subjectConfiguration.screenViewPort(screenViewport)
183
+ }
184
+ }
185
+ if (subjectConfig.hasKey("colorDepth")) {
186
+ if (subjectConfig.isNull("colorDepth")) {
187
+ subjectConfiguration.colorDepth(null)
188
+ } else {
189
+ val colorDepth = subjectConfig.getDouble("colorDepth").toInt()
190
+ subjectConfiguration.colorDepth(colorDepth)
191
+ }
192
+ }
193
+ return subjectConfiguration
194
+ }
195
+
196
+ fun mkGdprConfiguration(gdprConfig: ReadableMap): GdprConfiguration {
197
+ val basis = mkBasis(gdprConfig.getString("basisForProcessing")!!)
198
+ val docId: String = gdprConfig.getString("documentId")!!
199
+ val docVer: String = gdprConfig.getString("documentVersion")!!
200
+ val docDesc: String = gdprConfig.getString("documentDescription")!!
201
+ return GdprConfiguration(
202
+ basis,
203
+ docId,
204
+ docVer,
205
+ docDesc
206
+ )
207
+ }
208
+
209
+ fun mkGCConfiguration(gcConfig: ReadableArray): GlobalContextsConfiguration {
210
+ val contextGens: MutableMap<String, GlobalContext> = HashMap()
211
+ for (i in 0 until gcConfig.size()) {
212
+ val gcMap: ReadableMap = gcConfig.getMap(i)
213
+ val itag: String = gcMap.getString("tag")!!
214
+ val globalContexts: ReadableArray = gcMap.getArray("globalContexts")!!
215
+ val staticContexts: MutableList<SelfDescribingJson> =
216
+ ArrayList()
217
+ for (x in 0 until globalContexts.size()) {
218
+ val gContext: SelfDescribingJson =
219
+ EventUtil.createSelfDescribingJson(globalContexts.getMap(x))
220
+ staticContexts.add(gContext)
221
+ }
222
+ val gcStatic = GlobalContext(staticContexts)
223
+ if (!contextGens.containsKey(itag)) {
224
+ contextGens[itag] = gcStatic
225
+ }
226
+ }
227
+ return GlobalContextsConfiguration(contextGens)
228
+ }
229
+
230
+ private fun mkDevicePlatform(devPlatform: String): DevicePlatform {
231
+ return when (devPlatform) {
232
+ "web" -> DevicePlatform.Web
233
+ "srv" -> DevicePlatform.ServerSideApp
234
+ "pc" -> DevicePlatform.Desktop
235
+ "app" -> DevicePlatform.General
236
+ "tv" -> DevicePlatform.ConnectedTV
237
+ "cnsl" -> DevicePlatform.GameConsole
238
+ "iot" -> DevicePlatform.InternetOfThings
239
+ else -> DevicePlatform.Mobile
240
+ }
241
+ }
242
+
243
+ private fun mkLogLevel(logLvl: String): LogLevel {
244
+ return when (logLvl) {
245
+ "error" -> LogLevel.ERROR
246
+ "debug" -> LogLevel.DEBUG
247
+ "verbose" -> LogLevel.VERBOSE
248
+ else -> LogLevel.OFF
249
+ }
250
+ }
251
+
252
+ private fun mkBufferOption(bufferOpt: String): BufferOption? {
253
+ return when (bufferOpt) {
254
+ "single" -> BufferOption.Single
255
+ "default" -> BufferOption.DefaultGroup
256
+ "large" -> BufferOption.HeavyGroup
257
+ else -> null
258
+ }
259
+ }
260
+
261
+ private fun mkBasis(basis: String): Basis {
262
+ return when (basis) {
263
+ "contract" -> Basis.CONTRACT
264
+ "legal_obligation" -> Basis.LEGAL_OBLIGATION
265
+ "legitimate_interests" -> Basis.LEGITIMATE_INTERESTS
266
+ "public_task" -> Basis.PUBLIC_TASK
267
+ "vital_interests" -> Basis.VITAL_INTERESTS
268
+ else -> Basis.CONSENT
269
+ }
270
+ }
271
+ }
@@ -0,0 +1,213 @@
1
+ package com.snowplow.reactnativetracker.util
2
+
3
+ import com.facebook.react.bridge.ReadableArray
4
+ import com.facebook.react.bridge.ReadableMap
5
+ import com.snowplowanalytics.snowplow.event.*
6
+ import com.snowplowanalytics.snowplow.payload.SelfDescribingJson
7
+ import java.util.*
8
+
9
+ object EventUtil {
10
+ fun createSelfDescribingJson(json: ReadableMap): SelfDescribingJson {
11
+ val schema: String = json.getString("schema")!!
12
+ val dataMap: ReadableMap = json.getMap("data")!!
13
+ return SelfDescribingJson(schema, dataMap.toHashMap())
14
+ }
15
+
16
+ fun createContexts(contexts: ReadableArray): List<SelfDescribingJson> {
17
+ val nativeContexts: MutableList<SelfDescribingJson> = ArrayList()
18
+ for (i in 0 until contexts.size()) {
19
+ val json = createSelfDescribingJson(contexts.getMap(i))
20
+ nativeContexts.add(json)
21
+ }
22
+ return nativeContexts
23
+ }
24
+
25
+ fun createStructuredEvent(argmap: ReadableMap): Structured {
26
+ val event = Structured(
27
+ argmap.getString("category")!!,
28
+ argmap.getString("action")!!
29
+ )
30
+ argmap.getString("label")?.let { event.label(it) }
31
+ argmap.getString("property")?.let { event.property(it) }
32
+ // React Native forces primitive double type - so null "value" parameter is handled by not setting at all
33
+ if (argmap.hasKey("value") && !argmap.isNull("value")) {
34
+ event.value(argmap.getDouble("value"))
35
+ }
36
+ return event
37
+ }
38
+
39
+ fun createScreenViewEvent(argmap: ReadableMap): ScreenView {
40
+ val name: String = argmap.getString("name")!!
41
+ val event = if (argmap.hasKey("id")) ScreenView(
42
+ name,
43
+ UUID.fromString(argmap.getString("id"))
44
+ ) else ScreenView(name)
45
+ argmap.getString("type")?.let { event.type(it) }
46
+ argmap.getString("previousName")?.let { event.previousName(it) }
47
+ argmap.getString("previousType")?.let { event.previousType(it) }
48
+ argmap.getString("previousId")?.let { event.previousId(it) }
49
+ argmap.getString("transitionType")?.let { event.transitionType(it) }
50
+ return event
51
+ }
52
+
53
+ fun createPageViewEvent(argmap: ReadableMap): PageView {
54
+ val event = PageView(argmap.getString("pageUrl")!!)
55
+ argmap.getString("pageTitle")?.let { event.pageTitle(it) }
56
+ argmap.getString("referrer")?.let { event.referrer(it) }
57
+ return event
58
+ }
59
+
60
+ fun createTimingEvent(argmap: ReadableMap): Timing {
61
+ val event = Timing(
62
+ argmap.getString("category")!!,
63
+ argmap.getString("variable")!!,
64
+ argmap.getDouble("timing").toInt()
65
+ )
66
+ argmap.getString("label")?.let { label ->
67
+ event.label(label)
68
+ }
69
+ return event
70
+ }
71
+
72
+ fun createConsentGrantedEvent(argmap: ReadableMap): ConsentGranted {
73
+ val event = ConsentGranted(
74
+ argmap.getString("expiry")!!,
75
+ argmap.getString("documentId")!!,
76
+ argmap.getString("version")!!
77
+ )
78
+ argmap.getString("name")?.let { event.documentName(it) }
79
+ argmap.getString("documentDescription")?.let { event.documentDescription(it) }
80
+ return event
81
+ }
82
+
83
+ fun createConsentWithdrawnEvent(argmap: ReadableMap): ConsentWithdrawn {
84
+ val event = ConsentWithdrawn(
85
+ argmap.getBoolean("all"),
86
+ argmap.getString("documentId")!!,
87
+ argmap.getString("version")!!
88
+ )
89
+ argmap.getString("name")?.let { event.documentName(it) }
90
+ argmap.getString("documentDescription")?.let { event.documentDescription(it) }
91
+ return event
92
+ }
93
+
94
+ fun createEcommerceTransactionItems(items: ReadableArray): List<EcommerceTransactionItem> {
95
+ val ecomItems: MutableList<EcommerceTransactionItem> = ArrayList()
96
+ for (i in 0 until items.size()) {
97
+ val argItem: ReadableMap = items.getMap(i)
98
+ val item = EcommerceTransactionItem(
99
+ argItem.getString("sku")!!,
100
+ argItem.getDouble("price"),
101
+ argItem.getDouble("quantity").toInt()
102
+ )
103
+ argItem.getString("name")?.let { item.name(it) }
104
+ argItem.getString("category")?.let { item.category(it) }
105
+ argItem.getString("currency")?.let { item.currency(it) }
106
+ ecomItems.add(item)
107
+ }
108
+ return ecomItems
109
+ }
110
+
111
+ fun createEcommerceTransactionEvent(argmap: ReadableMap): EcommerceTransaction {
112
+ val ecomItems = createEcommerceTransactionItems(
113
+ argmap.getArray("items")!!
114
+ )
115
+ val event = EcommerceTransaction(
116
+ argmap.getString("orderId")!!,
117
+ argmap.getDouble("totalValue"),
118
+ ecomItems
119
+ )
120
+ argmap.getString("affiliation")?.let { event.affiliation(it) }
121
+ if (argmap.hasKey("taxValue")) {
122
+ event.taxValue(argmap.getDouble("taxValue"))
123
+ }
124
+ if (argmap.hasKey("shipping")) {
125
+ event.shipping(argmap.getDouble("shipping"))
126
+ }
127
+ argmap.getString("city")?.let { event.city(it) }
128
+ argmap.getString("state")?.let { event.state(it) }
129
+ argmap.getString("country")?.let { event.country(it) }
130
+ argmap.getString("currency")?.let { event.currency(it) }
131
+ return event
132
+ }
133
+
134
+ fun createDeepLinkReceivedEvent(argmap: ReadableMap): DeepLinkReceived {
135
+ val event = DeepLinkReceived(
136
+ argmap.getString("url")!!
137
+ )
138
+ argmap.getString("referrer")?.let { event.referrer(it) }
139
+ return event
140
+ }
141
+
142
+ fun createMessageNotificationAttachments(items: ReadableArray): List<MessageNotificationAttachment> {
143
+ val attachments: MutableList<MessageNotificationAttachment> = ArrayList()
144
+ for (i in 0 until items.size()) {
145
+ val argItem: ReadableMap = items.getMap(i)
146
+ val attachment = MessageNotificationAttachment(
147
+ argItem.getString("identifier")!!,
148
+ argItem.getString("type")!!,
149
+ argItem.getString("url")!!
150
+ )
151
+ attachments.add(attachment)
152
+ }
153
+ return attachments
154
+ }
155
+
156
+ fun createStrings(items: ReadableArray): List<String> {
157
+ val results: MutableList<String> = ArrayList()
158
+ for (i in 0 until items.size()) {
159
+ results.add(items.getString(i))
160
+ }
161
+ return results
162
+ }
163
+
164
+ fun createMessageNotificationEvent(argmap: ReadableMap): MessageNotification {
165
+ val trigger: MessageNotificationTrigger
166
+ trigger =
167
+ when (argmap.getString("trigger")!!) {
168
+ "push" -> MessageNotificationTrigger.push
169
+ "location" -> MessageNotificationTrigger.location
170
+ "calendar" -> MessageNotificationTrigger.calendar
171
+ "timeInterval" -> MessageNotificationTrigger.timeInterval
172
+ else -> MessageNotificationTrigger.other
173
+ }
174
+ val event = MessageNotification(
175
+ argmap.getString("title")!!,
176
+ argmap.getString("body")!!,
177
+ trigger
178
+ )
179
+ argmap.getString("action")?.let { event.action(it) }
180
+ if (argmap.hasKey("attachments")) {
181
+ argmap.getArray("attachments")?.let { attachments ->
182
+ event.attachments(createMessageNotificationAttachments(attachments))
183
+ }
184
+ }
185
+ if (argmap.hasKey("bodyLocArgs")) {
186
+ argmap.getArray("bodyLocArgs")?.let { bodyLocArgs ->
187
+ event.bodyLocArgs(createStrings(bodyLocArgs))
188
+ }
189
+ }
190
+ argmap.getString("bodyLocKey")?.let { event.bodyLocKey(it) }
191
+ argmap.getString("category")?.let { event.category(it) }
192
+ if (argmap.hasKey("contentAvailable")) {
193
+ event.contentAvailable(argmap.getBoolean("contentAvailable"))
194
+ }
195
+ argmap.getString("group")?.let { event.group(it) }
196
+ argmap.getString("icon")?.let { event.icon(it) }
197
+ if (argmap.hasKey("notificationCount")) {
198
+ event.notificationCount(argmap.getDouble("notificationCount").toInt())
199
+ }
200
+ argmap.getString("notificationTimestamp")?.let { event.notificationTimestamp(it) }
201
+ argmap.getString("sound")?.let { event.sound(it) }
202
+ argmap.getString("subtitle")?.let { event.subtitle(it) }
203
+ argmap.getString("tag")?.let { event.tag(it) }
204
+ argmap.getString("threadIdentifier")?.let { event.threadIdentifier(it) }
205
+ if (argmap.hasKey("titleLocArgs")) {
206
+ argmap.getArray("titleLocArgs")?.let { titleLocArgs ->
207
+ event.titleLocArgs(createStrings(titleLocArgs))
208
+ }
209
+ }
210
+ argmap.getString("titleLocKey")?.let { event.titleLocKey(it) }
211
+ return event
212
+ }
213
+ }
@@ -0,0 +1,5 @@
1
+ package com.snowplow.reactnativetracker.util
2
+
3
+ object TrackerVersion {
4
+ const val RN_TRACKER_VERSION = "rn-2.0.0"
5
+ }
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ presets: ['module:metro-react-native-babel-preset'],
3
+ };
@@ -0,0 +1 @@
1
+ {}
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4
+ ruby ">= 2.6.10"
5
+
6
+ gem 'cocoapods', '~> 1.12'
@@ -0,0 +1,129 @@
1
+ apply plugin: "com.android.application"
2
+ apply plugin: "com.facebook.react"
3
+
4
+ /**
5
+ * This is the configuration block to customize your React Native Android app.
6
+ * By default you don't need to apply any configuration, just uncomment the lines you need.
7
+ */
8
+ react {
9
+ /* Folders */
10
+ // The root of your project, i.e. where "package.json" lives. Default is '..'
11
+ // root = file("../")
12
+ // The folder where the react-native NPM package is. Default is ../node_modules/react-native
13
+ // reactNativeDir = file("../node_modules/react-native")
14
+ // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
15
+ // codegenDir = file("../node_modules/@react-native/codegen")
16
+ // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
17
+ // cliFile = file("../node_modules/react-native/cli.js")
18
+
19
+ /* Variants */
20
+ // The list of variants to that are debuggable. For those we're going to
21
+ // skip the bundling of the JS bundle and the assets. By default is just 'debug'.
22
+ // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
23
+ // debuggableVariants = ["liteDebug", "prodDebug"]
24
+
25
+ /* Bundling */
26
+ // A list containing the node command and its flags. Default is just 'node'.
27
+ // nodeExecutableAndArgs = ["node"]
28
+ //
29
+ // The command to run when bundling. By default is 'bundle'
30
+ // bundleCommand = "ram-bundle"
31
+ //
32
+ // The path to the CLI configuration file. Default is empty.
33
+ // bundleConfig = file(../rn-cli.config.js)
34
+ //
35
+ // The name of the generated asset file containing your JS bundle
36
+ // bundleAssetName = "MyApplication.android.bundle"
37
+ //
38
+ // The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
39
+ // entryFile = file("../js/MyApplication.android.js")
40
+ //
41
+ // A list of extra flags to pass to the 'bundle' commands.
42
+ // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
43
+ // extraPackagerArgs = []
44
+
45
+ /* Hermes Commands */
46
+ // The hermes compiler command to run. By default it is 'hermesc'
47
+ // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
48
+ //
49
+ // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
50
+ // hermesFlags = ["-O", "-output-source-map"]
51
+ }
52
+
53
+ /**
54
+ * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
55
+ */
56
+ def enableProguardInReleaseBuilds = false
57
+
58
+ /**
59
+ * The preferred build flavor of JavaScriptCore (JSC)
60
+ *
61
+ * For example, to use the international variant, you can use:
62
+ * `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
63
+ *
64
+ * The international variant includes ICU i18n library and necessary data
65
+ * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
66
+ * give correct results when using with locales other than en-US. Note that
67
+ * this variant is about 6MiB larger per architecture than default.
68
+ */
69
+ def jscFlavor = 'org.webkit:android-jsc:+'
70
+
71
+ android {
72
+ ndkVersion rootProject.ext.ndkVersion
73
+
74
+ compileSdkVersion rootProject.ext.compileSdkVersion
75
+
76
+ namespace "com.reactnativetrackerexample"
77
+ defaultConfig {
78
+ applicationId "com.reactnativetrackerexample"
79
+ minSdkVersion rootProject.ext.minSdkVersion
80
+ targetSdkVersion rootProject.ext.targetSdkVersion
81
+ versionCode 1
82
+ versionName "1.0"
83
+ testBuildType System.getProperty('testBuildType', 'debug')
84
+ testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
85
+ }
86
+ signingConfigs {
87
+ debug {
88
+ storeFile file('debug.keystore')
89
+ storePassword 'android'
90
+ keyAlias 'androiddebugkey'
91
+ keyPassword 'android'
92
+ }
93
+ }
94
+ buildTypes {
95
+ debug {
96
+ signingConfig signingConfigs.debug
97
+ }
98
+ release {
99
+ // Caution! In production, you need to generate your own keystore file.
100
+ // see https://reactnative.dev/docs/signed-apk-android.
101
+ signingConfig signingConfigs.debug
102
+ minifyEnabled enableProguardInReleaseBuilds
103
+ proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
104
+ proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
105
+ }
106
+ }
107
+ }
108
+
109
+ dependencies {
110
+ // The version of react-native is set by the React Native Gradle Plugin
111
+ implementation("com.facebook.react:react-android")
112
+
113
+ debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
114
+ debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
115
+ exclude group:'com.squareup.okhttp3', module:'okhttp'
116
+ }
117
+
118
+ debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
119
+ if (hermesEnabled.toBoolean()) {
120
+ implementation("com.facebook.react:hermes-android")
121
+ } else {
122
+ implementation jscFlavor
123
+ }
124
+
125
+ androidTestImplementation 'com.wix:detox:+'
126
+ implementation 'androidx.appcompat:appcompat:1.1.0'
127
+ }
128
+
129
+ apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
@@ -0,0 +1,10 @@
1
+ # Add project specific ProGuard rules here.
2
+ # By default, the flags in this file are appended to flags specified
3
+ # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4
+ # You can edit the include path and order by changing the proguardFiles
5
+ # directive in build.gradle.
6
+ #
7
+ # For more details, see
8
+ # http://developer.android.com/guide/developing/tools/proguard.html
9
+
10
+ # Add any project specific keep options here: