react-native-nitro-amplitude 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (411) hide show
  1. package/.watchmanconfig +6 -0
  2. package/LICENSE +21 -0
  3. package/README.md +139 -0
  4. package/android/CMakeLists.txt +34 -0
  5. package/android/build.gradle +85 -0
  6. package/android/consumer-rules.pro +35 -0
  7. package/android/gradle.properties +4 -0
  8. package/android/src/main/cpp/AndroidAmplitudeAdapterCpp.cpp +126 -0
  9. package/android/src/main/cpp/AndroidAmplitudeAdapterCpp.hpp +48 -0
  10. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  11. package/android/src/main/java/com/nitroamplitude/AndroidAmplitudeAdapter.kt +147 -0
  12. package/android/src/main/java/com/nitroamplitude/NitroAmplitudePackage.kt +24 -0
  13. package/app.plugin.js +36 -0
  14. package/cpp/bindings/HybridAmplitudeContext.cpp +83 -0
  15. package/cpp/bindings/HybridAmplitudeContext.hpp +29 -0
  16. package/cpp/bindings/HybridAmplitudeStorage.cpp +163 -0
  17. package/cpp/bindings/HybridAmplitudeStorage.hpp +38 -0
  18. package/cpp/bindings/HybridAmplitudeWorker.cpp +162 -0
  19. package/cpp/bindings/HybridAmplitudeWorker.hpp +74 -0
  20. package/cpp/core/NativeAmplitudeAdapter.hpp +44 -0
  21. package/ios/IOSAmplitudeAdapterCpp.hpp +37 -0
  22. package/ios/IOSAmplitudeAdapterCpp.mm +155 -0
  23. package/lib/commonjs/AmplitudeContext.nitro.js +6 -0
  24. package/lib/commonjs/AmplitudeContext.nitro.js.map +1 -0
  25. package/lib/commonjs/AmplitudeStorage.nitro.js +6 -0
  26. package/lib/commonjs/AmplitudeStorage.nitro.js.map +1 -0
  27. package/lib/commonjs/AmplitudeWorker.nitro.js +6 -0
  28. package/lib/commonjs/AmplitudeWorker.nitro.js.map +1 -0
  29. package/lib/commonjs/analytics/campaign/campaign-tracker.js +105 -0
  30. package/lib/commonjs/analytics/campaign/campaign-tracker.js.map +1 -0
  31. package/lib/commonjs/analytics/campaign/types.js +6 -0
  32. package/lib/commonjs/analytics/campaign/types.js.map +1 -0
  33. package/lib/commonjs/analytics/config.js +283 -0
  34. package/lib/commonjs/analytics/config.js.map +1 -0
  35. package/lib/commonjs/analytics/cookie-migration/index.js +59 -0
  36. package/lib/commonjs/analytics/cookie-migration/index.js.map +1 -0
  37. package/lib/commonjs/analytics/index.js +95 -0
  38. package/lib/commonjs/analytics/index.js.map +1 -0
  39. package/lib/commonjs/analytics/migration/remnant-data-migration.js +177 -0
  40. package/lib/commonjs/analytics/migration/remnant-data-migration.js.map +1 -0
  41. package/lib/commonjs/analytics/nitro-transport.js +31 -0
  42. package/lib/commonjs/analytics/nitro-transport.js.map +1 -0
  43. package/lib/commonjs/analytics/plugins/context.js +140 -0
  44. package/lib/commonjs/analytics/plugins/context.js.map +1 -0
  45. package/lib/commonjs/analytics/react-native-client.js +352 -0
  46. package/lib/commonjs/analytics/react-native-client.js.map +1 -0
  47. package/lib/commonjs/analytics/storage/local-storage.js +73 -0
  48. package/lib/commonjs/analytics/storage/local-storage.js.map +1 -0
  49. package/lib/commonjs/analytics/types.js +175 -0
  50. package/lib/commonjs/analytics/types.js.map +1 -0
  51. package/lib/commonjs/analytics/typings/browser-snippet.d.js +6 -0
  52. package/lib/commonjs/analytics/typings/browser-snippet.d.js.map +1 -0
  53. package/lib/commonjs/analytics/typings/ua-parser.d.js +2 -0
  54. package/lib/commonjs/analytics/typings/ua-parser.d.js.map +1 -0
  55. package/lib/commonjs/analytics/utils/platform.js +16 -0
  56. package/lib/commonjs/analytics/utils/platform.js.map +1 -0
  57. package/lib/commonjs/analytics/version.js +8 -0
  58. package/lib/commonjs/analytics/version.js.map +1 -0
  59. package/lib/commonjs/experiment/experimentClient.js +792 -0
  60. package/lib/commonjs/experiment/experimentClient.js.map +1 -0
  61. package/lib/commonjs/experiment/factory.js +77 -0
  62. package/lib/commonjs/experiment/factory.js.map +1 -0
  63. package/lib/commonjs/experiment/gen/version.js +9 -0
  64. package/lib/commonjs/experiment/gen/version.js.map +1 -0
  65. package/lib/commonjs/experiment/index.js +143 -0
  66. package/lib/commonjs/experiment/index.js.map +1 -0
  67. package/lib/commonjs/experiment/integration/NativeExperimentReactNativeClient.js +11 -0
  68. package/lib/commonjs/experiment/integration/NativeExperimentReactNativeClient.js.map +1 -0
  69. package/lib/commonjs/experiment/integration/connector.js +67 -0
  70. package/lib/commonjs/experiment/integration/connector.js.map +1 -0
  71. package/lib/commonjs/experiment/integration/default.js +92 -0
  72. package/lib/commonjs/experiment/integration/default.js.map +1 -0
  73. package/lib/commonjs/experiment/logger/ampLogger.js +80 -0
  74. package/lib/commonjs/experiment/logger/ampLogger.js.map +1 -0
  75. package/lib/commonjs/experiment/logger/consoleLogger.js +60 -0
  76. package/lib/commonjs/experiment/logger/consoleLogger.js.map +1 -0
  77. package/lib/commonjs/experiment/storage/cache.js +197 -0
  78. package/lib/commonjs/experiment/storage/cache.js.map +1 -0
  79. package/lib/commonjs/experiment/storage/local-storage.js +25 -0
  80. package/lib/commonjs/experiment/storage/local-storage.js.map +1 -0
  81. package/lib/commonjs/experiment/stubClient.js +46 -0
  82. package/lib/commonjs/experiment/stubClient.js.map +1 -0
  83. package/lib/commonjs/experiment/transport/http.js +72 -0
  84. package/lib/commonjs/experiment/transport/http.js.map +1 -0
  85. package/lib/commonjs/experiment/types/client.js +6 -0
  86. package/lib/commonjs/experiment/types/client.js.map +1 -0
  87. package/lib/commonjs/experiment/types/config.js +67 -0
  88. package/lib/commonjs/experiment/types/config.js.map +1 -0
  89. package/lib/commonjs/experiment/types/exposure.js +2 -0
  90. package/lib/commonjs/experiment/types/exposure.js.map +1 -0
  91. package/lib/commonjs/experiment/types/logger.js +42 -0
  92. package/lib/commonjs/experiment/types/logger.js.map +1 -0
  93. package/lib/commonjs/experiment/types/source.js +54 -0
  94. package/lib/commonjs/experiment/types/source.js.map +1 -0
  95. package/lib/commonjs/experiment/types/storage.js +2 -0
  96. package/lib/commonjs/experiment/types/storage.js.map +1 -0
  97. package/lib/commonjs/experiment/types/transport.js +2 -0
  98. package/lib/commonjs/experiment/types/transport.js.map +1 -0
  99. package/lib/commonjs/experiment/types/user.js +2 -0
  100. package/lib/commonjs/experiment/types/user.js.map +1 -0
  101. package/lib/commonjs/experiment/types/variant.js +2 -0
  102. package/lib/commonjs/experiment/types/variant.js.map +1 -0
  103. package/lib/commonjs/experiment/util/backoff.js +54 -0
  104. package/lib/commonjs/experiment/util/backoff.js.map +1 -0
  105. package/lib/commonjs/experiment/util/base64.js +23 -0
  106. package/lib/commonjs/experiment/util/base64.js.map +1 -0
  107. package/lib/commonjs/experiment/util/convert.js +78 -0
  108. package/lib/commonjs/experiment/util/convert.js.map +1 -0
  109. package/lib/commonjs/experiment/util/index.js +25 -0
  110. package/lib/commonjs/experiment/util/index.js.map +1 -0
  111. package/lib/commonjs/experiment/util/platform.js +16 -0
  112. package/lib/commonjs/experiment/util/platform.js.map +1 -0
  113. package/lib/commonjs/experiment/util/randomstring.js +16 -0
  114. package/lib/commonjs/experiment/util/randomstring.js.map +1 -0
  115. package/lib/commonjs/experiment/util/userSessionExposureTracker.js +40 -0
  116. package/lib/commonjs/experiment/util/userSessionExposureTracker.js.map +1 -0
  117. package/lib/commonjs/index.js +298 -0
  118. package/lib/commonjs/index.js.map +1 -0
  119. package/lib/commonjs/index.web.js +22 -0
  120. package/lib/commonjs/index.web.js.map +1 -0
  121. package/lib/commonjs/native/context.js +43 -0
  122. package/lib/commonjs/native/context.js.map +1 -0
  123. package/lib/commonjs/native/http.js +62 -0
  124. package/lib/commonjs/native/http.js.map +1 -0
  125. package/lib/commonjs/native/hybrid.js +31 -0
  126. package/lib/commonjs/native/hybrid.js.map +1 -0
  127. package/lib/commonjs/native/storage.js +93 -0
  128. package/lib/commonjs/native/storage.js.map +1 -0
  129. package/lib/commonjs/package.json +1 -0
  130. package/lib/module/AmplitudeContext.nitro.js +4 -0
  131. package/lib/module/AmplitudeContext.nitro.js.map +1 -0
  132. package/lib/module/AmplitudeStorage.nitro.js +4 -0
  133. package/lib/module/AmplitudeStorage.nitro.js.map +1 -0
  134. package/lib/module/AmplitudeWorker.nitro.js +4 -0
  135. package/lib/module/AmplitudeWorker.nitro.js.map +1 -0
  136. package/lib/module/analytics/campaign/campaign-tracker.js +100 -0
  137. package/lib/module/analytics/campaign/campaign-tracker.js.map +1 -0
  138. package/lib/module/analytics/campaign/types.js +4 -0
  139. package/lib/module/analytics/campaign/types.js.map +1 -0
  140. package/lib/module/analytics/config.js +272 -0
  141. package/lib/module/analytics/config.js.map +1 -0
  142. package/lib/module/analytics/cookie-migration/index.js +51 -0
  143. package/lib/module/analytics/cookie-migration/index.js.map +1 -0
  144. package/lib/module/analytics/index.js +34 -0
  145. package/lib/module/analytics/index.js.map +1 -0
  146. package/lib/module/analytics/migration/remnant-data-migration.js +172 -0
  147. package/lib/module/analytics/migration/remnant-data-migration.js.map +1 -0
  148. package/lib/module/analytics/nitro-transport.js +26 -0
  149. package/lib/module/analytics/nitro-transport.js.map +1 -0
  150. package/lib/module/analytics/plugins/context.js +134 -0
  151. package/lib/module/analytics/plugins/context.js.map +1 -0
  152. package/lib/module/analytics/react-native-client.js +346 -0
  153. package/lib/module/analytics/react-native-client.js.map +1 -0
  154. package/lib/module/analytics/storage/local-storage.js +68 -0
  155. package/lib/module/analytics/storage/local-storage.js.map +1 -0
  156. package/lib/module/analytics/types.js +4 -0
  157. package/lib/module/analytics/types.js.map +1 -0
  158. package/lib/module/analytics/typings/browser-snippet.d.js +4 -0
  159. package/lib/module/analytics/typings/browser-snippet.d.js.map +1 -0
  160. package/lib/module/analytics/typings/ua-parser.d.js +2 -0
  161. package/lib/module/analytics/typings/ua-parser.d.js.map +1 -0
  162. package/lib/module/analytics/utils/platform.js +10 -0
  163. package/lib/module/analytics/utils/platform.js.map +1 -0
  164. package/lib/module/analytics/version.js +4 -0
  165. package/lib/module/analytics/version.js.map +1 -0
  166. package/lib/module/experiment/experimentClient.js +788 -0
  167. package/lib/module/experiment/experimentClient.js.map +1 -0
  168. package/lib/module/experiment/factory.js +73 -0
  169. package/lib/module/experiment/factory.js.map +1 -0
  170. package/lib/module/experiment/gen/version.js +5 -0
  171. package/lib/module/experiment/gen/version.js.map +1 -0
  172. package/lib/module/experiment/index.js +16 -0
  173. package/lib/module/experiment/index.js.map +1 -0
  174. package/lib/module/experiment/integration/NativeExperimentReactNativeClient.js +7 -0
  175. package/lib/module/experiment/integration/NativeExperimentReactNativeClient.js.map +1 -0
  176. package/lib/module/experiment/integration/connector.js +61 -0
  177. package/lib/module/experiment/integration/connector.js.map +1 -0
  178. package/lib/module/experiment/integration/default.js +87 -0
  179. package/lib/module/experiment/integration/default.js.map +1 -0
  180. package/lib/module/experiment/logger/ampLogger.js +76 -0
  181. package/lib/module/experiment/logger/ampLogger.js.map +1 -0
  182. package/lib/module/experiment/logger/consoleLogger.js +55 -0
  183. package/lib/module/experiment/logger/consoleLogger.js.map +1 -0
  184. package/lib/module/experiment/storage/cache.js +187 -0
  185. package/lib/module/experiment/storage/cache.js.map +1 -0
  186. package/lib/module/experiment/storage/local-storage.js +19 -0
  187. package/lib/module/experiment/storage/local-storage.js.map +1 -0
  188. package/lib/module/experiment/stubClient.js +41 -0
  189. package/lib/module/experiment/stubClient.js.map +1 -0
  190. package/lib/module/experiment/transport/http.js +66 -0
  191. package/lib/module/experiment/transport/http.js.map +1 -0
  192. package/lib/module/experiment/types/client.js +4 -0
  193. package/lib/module/experiment/types/client.js.map +1 -0
  194. package/lib/module/experiment/types/config.js +64 -0
  195. package/lib/module/experiment/types/config.js.map +1 -0
  196. package/lib/module/experiment/types/exposure.js +2 -0
  197. package/lib/module/experiment/types/exposure.js.map +1 -0
  198. package/lib/module/experiment/types/logger.js +39 -0
  199. package/lib/module/experiment/types/logger.js.map +1 -0
  200. package/lib/module/experiment/types/source.js +51 -0
  201. package/lib/module/experiment/types/source.js.map +1 -0
  202. package/lib/module/experiment/types/storage.js +2 -0
  203. package/lib/module/experiment/types/storage.js.map +1 -0
  204. package/lib/module/experiment/types/transport.js +2 -0
  205. package/lib/module/experiment/types/transport.js.map +1 -0
  206. package/lib/module/experiment/types/user.js +2 -0
  207. package/lib/module/experiment/types/user.js.map +1 -0
  208. package/lib/module/experiment/types/variant.js +2 -0
  209. package/lib/module/experiment/types/variant.js.map +1 -0
  210. package/lib/module/experiment/util/backoff.js +49 -0
  211. package/lib/module/experiment/util/backoff.js.map +1 -0
  212. package/lib/module/experiment/util/base64.js +16 -0
  213. package/lib/module/experiment/util/base64.js.map +1 -0
  214. package/lib/module/experiment/util/convert.js +71 -0
  215. package/lib/module/experiment/util/convert.js.map +1 -0
  216. package/lib/module/experiment/util/index.js +17 -0
  217. package/lib/module/experiment/util/index.js.map +1 -0
  218. package/lib/module/experiment/util/platform.js +10 -0
  219. package/lib/module/experiment/util/platform.js.map +1 -0
  220. package/lib/module/experiment/util/randomstring.js +11 -0
  221. package/lib/module/experiment/util/randomstring.js.map +1 -0
  222. package/lib/module/experiment/util/userSessionExposureTracker.js +35 -0
  223. package/lib/module/experiment/util/userSessionExposureTracker.js.map +1 -0
  224. package/lib/module/index.js +50 -0
  225. package/lib/module/index.js.map +1 -0
  226. package/lib/module/index.web.js +14 -0
  227. package/lib/module/index.web.js.map +1 -0
  228. package/lib/module/native/context.js +35 -0
  229. package/lib/module/native/context.js.map +1 -0
  230. package/lib/module/native/http.js +57 -0
  231. package/lib/module/native/http.js.map +1 -0
  232. package/lib/module/native/hybrid.js +24 -0
  233. package/lib/module/native/hybrid.js.map +1 -0
  234. package/lib/module/native/storage.js +86 -0
  235. package/lib/module/native/storage.js.map +1 -0
  236. package/lib/typescript/AmplitudeContext.nitro.d.ts +17 -0
  237. package/lib/typescript/AmplitudeContext.nitro.d.ts.map +1 -0
  238. package/lib/typescript/AmplitudeStorage.nitro.d.ts +17 -0
  239. package/lib/typescript/AmplitudeStorage.nitro.d.ts.map +1 -0
  240. package/lib/typescript/AmplitudeWorker.nitro.d.ts +11 -0
  241. package/lib/typescript/AmplitudeWorker.nitro.d.ts.map +1 -0
  242. package/lib/typescript/analytics/campaign/campaign-tracker.d.ts +85 -0
  243. package/lib/typescript/analytics/campaign/campaign-tracker.d.ts.map +1 -0
  244. package/lib/typescript/analytics/campaign/types.d.ts +11 -0
  245. package/lib/typescript/analytics/campaign/types.d.ts.map +1 -0
  246. package/lib/typescript/analytics/config.d.ts +68 -0
  247. package/lib/typescript/analytics/config.d.ts.map +1 -0
  248. package/lib/typescript/analytics/cookie-migration/index.d.ts +6 -0
  249. package/lib/typescript/analytics/cookie-migration/index.d.ts.map +1 -0
  250. package/lib/typescript/analytics/index.d.ts +7 -0
  251. package/lib/typescript/analytics/index.d.ts.map +1 -0
  252. package/lib/typescript/analytics/migration/remnant-data-migration.d.ts +20 -0
  253. package/lib/typescript/analytics/migration/remnant-data-migration.d.ts.map +1 -0
  254. package/lib/typescript/analytics/nitro-transport.d.ts +9 -0
  255. package/lib/typescript/analytics/nitro-transport.d.ts.map +1 -0
  256. package/lib/typescript/analytics/plugins/context.d.ts +14 -0
  257. package/lib/typescript/analytics/plugins/context.d.ts.map +1 -0
  258. package/lib/typescript/analytics/react-native-client.d.ts +55 -0
  259. package/lib/typescript/analytics/react-native-client.d.ts.map +1 -0
  260. package/lib/typescript/analytics/storage/local-storage.d.ts +14 -0
  261. package/lib/typescript/analytics/storage/local-storage.d.ts.map +1 -0
  262. package/lib/typescript/analytics/types.d.ts +2 -0
  263. package/lib/typescript/analytics/types.d.ts.map +1 -0
  264. package/lib/typescript/analytics/utils/platform.d.ts +3 -0
  265. package/lib/typescript/analytics/utils/platform.d.ts.map +1 -0
  266. package/lib/typescript/analytics/version.d.ts +2 -0
  267. package/lib/typescript/analytics/version.d.ts.map +1 -0
  268. package/lib/typescript/experiment/experimentClient.d.ts +234 -0
  269. package/lib/typescript/experiment/experimentClient.d.ts.map +1 -0
  270. package/lib/typescript/experiment/factory.d.ts +11 -0
  271. package/lib/typescript/experiment/factory.d.ts.map +1 -0
  272. package/lib/typescript/experiment/gen/version.d.ts +2 -0
  273. package/lib/typescript/experiment/gen/version.d.ts.map +1 -0
  274. package/lib/typescript/experiment/index.d.ts +15 -0
  275. package/lib/typescript/experiment/index.d.ts.map +1 -0
  276. package/lib/typescript/experiment/integration/NativeExperimentReactNativeClient.d.ts +16 -0
  277. package/lib/typescript/experiment/integration/NativeExperimentReactNativeClient.d.ts.map +1 -0
  278. package/lib/typescript/experiment/integration/connector.d.ts +16 -0
  279. package/lib/typescript/experiment/integration/connector.d.ts.map +1 -0
  280. package/lib/typescript/experiment/integration/default.d.ts +20 -0
  281. package/lib/typescript/experiment/integration/default.d.ts.map +1 -0
  282. package/lib/typescript/experiment/logger/ampLogger.d.ts +47 -0
  283. package/lib/typescript/experiment/logger/ampLogger.d.ts.map +1 -0
  284. package/lib/typescript/experiment/logger/consoleLogger.d.ts +40 -0
  285. package/lib/typescript/experiment/logger/consoleLogger.d.ts.map +1 -0
  286. package/lib/typescript/experiment/storage/cache.d.ts +35 -0
  287. package/lib/typescript/experiment/storage/cache.d.ts.map +1 -0
  288. package/lib/typescript/experiment/storage/local-storage.d.ts +11 -0
  289. package/lib/typescript/experiment/storage/local-storage.d.ts.map +1 -0
  290. package/lib/typescript/experiment/stubClient.d.ts +21 -0
  291. package/lib/typescript/experiment/stubClient.d.ts.map +1 -0
  292. package/lib/typescript/experiment/transport/http.d.ts +17 -0
  293. package/lib/typescript/experiment/transport/http.d.ts.map +1 -0
  294. package/lib/typescript/experiment/types/client.d.ts +36 -0
  295. package/lib/typescript/experiment/types/client.d.ts.map +1 -0
  296. package/lib/typescript/experiment/types/config.d.ts +164 -0
  297. package/lib/typescript/experiment/types/config.d.ts.map +1 -0
  298. package/lib/typescript/experiment/types/exposure.d.ts +107 -0
  299. package/lib/typescript/experiment/types/exposure.d.ts.map +1 -0
  300. package/lib/typescript/experiment/types/logger.d.ts +67 -0
  301. package/lib/typescript/experiment/types/logger.d.ts.map +1 -0
  302. package/lib/typescript/experiment/types/source.d.ts +43 -0
  303. package/lib/typescript/experiment/types/source.d.ts.map +1 -0
  304. package/lib/typescript/experiment/types/storage.d.ts +7 -0
  305. package/lib/typescript/experiment/types/storage.d.ts.map +1 -0
  306. package/lib/typescript/experiment/types/transport.d.ts +8 -0
  307. package/lib/typescript/experiment/types/transport.d.ts.map +1 -0
  308. package/lib/typescript/experiment/types/user.d.ts +106 -0
  309. package/lib/typescript/experiment/types/user.d.ts.map +1 -0
  310. package/lib/typescript/experiment/types/variant.d.ts +33 -0
  311. package/lib/typescript/experiment/types/variant.d.ts.map +1 -0
  312. package/lib/typescript/experiment/util/backoff.d.ts +14 -0
  313. package/lib/typescript/experiment/util/backoff.d.ts.map +1 -0
  314. package/lib/typescript/experiment/util/base64.d.ts +3 -0
  315. package/lib/typescript/experiment/util/base64.d.ts.map +1 -0
  316. package/lib/typescript/experiment/util/convert.d.ts +7 -0
  317. package/lib/typescript/experiment/util/convert.d.ts.map +1 -0
  318. package/lib/typescript/experiment/util/index.d.ts +6 -0
  319. package/lib/typescript/experiment/util/index.d.ts.map +1 -0
  320. package/lib/typescript/experiment/util/platform.d.ts +3 -0
  321. package/lib/typescript/experiment/util/platform.d.ts.map +1 -0
  322. package/lib/typescript/experiment/util/randomstring.d.ts +2 -0
  323. package/lib/typescript/experiment/util/randomstring.d.ts.map +1 -0
  324. package/lib/typescript/experiment/util/userSessionExposureTracker.d.ts +16 -0
  325. package/lib/typescript/experiment/util/userSessionExposureTracker.d.ts.map +1 -0
  326. package/lib/typescript/index.d.ts +31 -0
  327. package/lib/typescript/index.d.ts.map +1 -0
  328. package/lib/typescript/index.web.d.ts +12 -0
  329. package/lib/typescript/index.web.d.ts.map +1 -0
  330. package/lib/typescript/native/context.d.ts +29 -0
  331. package/lib/typescript/native/context.d.ts.map +1 -0
  332. package/lib/typescript/native/http.d.ts +6 -0
  333. package/lib/typescript/native/http.d.ts.map +1 -0
  334. package/lib/typescript/native/hybrid.d.ts +8 -0
  335. package/lib/typescript/native/hybrid.d.ts.map +1 -0
  336. package/lib/typescript/native/storage.d.ts +29 -0
  337. package/lib/typescript/native/storage.d.ts.map +1 -0
  338. package/nitro.json +33 -0
  339. package/nitrogen/generated/.gitattributes +1 -0
  340. package/nitrogen/generated/android/NitroAmplitude+autolinking.cmake +83 -0
  341. package/nitrogen/generated/android/NitroAmplitude+autolinking.gradle +27 -0
  342. package/nitrogen/generated/android/NitroAmplitudeOnLoad.cpp +69 -0
  343. package/nitrogen/generated/android/NitroAmplitudeOnLoad.hpp +34 -0
  344. package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitroamplitude/NitroAmplitudeOnLoad.kt +35 -0
  345. package/nitrogen/generated/ios/NitroAmplitude+autolinking.rb +62 -0
  346. package/nitrogen/generated/ios/NitroAmplitude-Swift-Cxx-Bridge.cpp +17 -0
  347. package/nitrogen/generated/ios/NitroAmplitude-Swift-Cxx-Bridge.hpp +27 -0
  348. package/nitrogen/generated/ios/NitroAmplitude-Swift-Cxx-Umbrella.hpp +38 -0
  349. package/nitrogen/generated/ios/NitroAmplitudeAutolinking.mm +55 -0
  350. package/nitrogen/generated/ios/NitroAmplitudeAutolinking.swift +16 -0
  351. package/nitrogen/generated/shared/c++/HybridAmplitudeContextSpec.cpp +25 -0
  352. package/nitrogen/generated/shared/c++/HybridAmplitudeContextSpec.hpp +67 -0
  353. package/nitrogen/generated/shared/c++/HybridAmplitudeStorageSpec.cpp +30 -0
  354. package/nitrogen/generated/shared/c++/HybridAmplitudeStorageSpec.hpp +73 -0
  355. package/nitrogen/generated/shared/c++/HybridAmplitudeWorkerSpec.cpp +24 -0
  356. package/nitrogen/generated/shared/c++/HybridAmplitudeWorkerSpec.hpp +66 -0
  357. package/package.json +130 -0
  358. package/react-native-nitro-amplitude.podspec +36 -0
  359. package/src/AmplitudeContext.nitro.ts +21 -0
  360. package/src/AmplitudeStorage.nitro.ts +17 -0
  361. package/src/AmplitudeWorker.nitro.ts +25 -0
  362. package/src/analytics/campaign/campaign-tracker.ts +162 -0
  363. package/src/analytics/campaign/types.ts +18 -0
  364. package/src/analytics/config.ts +373 -0
  365. package/src/analytics/cookie-migration/index.ts +69 -0
  366. package/src/analytics/index.ts +36 -0
  367. package/src/analytics/migration/remnant-data-migration.ts +206 -0
  368. package/src/analytics/nitro-transport.ts +35 -0
  369. package/src/analytics/plugins/context.ts +166 -0
  370. package/src/analytics/react-native-client.ts +573 -0
  371. package/src/analytics/storage/local-storage.ts +76 -0
  372. package/src/analytics/types.ts +30 -0
  373. package/src/analytics/typings/browser-snippet.d.ts +7 -0
  374. package/src/analytics/typings/ua-parser.d.ts +4 -0
  375. package/src/analytics/utils/platform.ts +9 -0
  376. package/src/analytics/version.ts +1 -0
  377. package/src/experiment/experimentClient.ts +987 -0
  378. package/src/experiment/factory.ts +86 -0
  379. package/src/experiment/gen/version.ts +2 -0
  380. package/src/experiment/index.ts +14 -0
  381. package/src/experiment/integration/NativeExperimentReactNativeClient.ts +25 -0
  382. package/src/experiment/integration/connector.ts +82 -0
  383. package/src/experiment/integration/default.ts +107 -0
  384. package/src/experiment/logger/ampLogger.ts +76 -0
  385. package/src/experiment/logger/consoleLogger.ts +54 -0
  386. package/src/experiment/storage/cache.ts +271 -0
  387. package/src/experiment/storage/local-storage.ts +23 -0
  388. package/src/experiment/stubClient.ts +61 -0
  389. package/src/experiment/transport/http.ts +105 -0
  390. package/src/experiment/types/client.ts +38 -0
  391. package/src/experiment/types/config.ts +210 -0
  392. package/src/experiment/types/exposure.ts +107 -0
  393. package/src/experiment/types/logger.ts +71 -0
  394. package/src/experiment/types/source.ts +52 -0
  395. package/src/experiment/types/storage.ts +6 -0
  396. package/src/experiment/types/transport.ts +14 -0
  397. package/src/experiment/types/user.ts +132 -0
  398. package/src/experiment/types/variant.ts +36 -0
  399. package/src/experiment/util/backoff.ts +67 -0
  400. package/src/experiment/util/base64.ts +20 -0
  401. package/src/experiment/util/convert.ts +78 -0
  402. package/src/experiment/util/index.ts +23 -0
  403. package/src/experiment/util/platform.ts +9 -0
  404. package/src/experiment/util/randomstring.ts +12 -0
  405. package/src/experiment/util/userSessionExposureTracker.ts +47 -0
  406. package/src/index.ts +66 -0
  407. package/src/index.web.ts +19 -0
  408. package/src/native/context.ts +73 -0
  409. package/src/native/http.ts +77 -0
  410. package/src/native/hybrid.ts +32 -0
  411. package/src/native/storage.ts +107 -0
@@ -0,0 +1,573 @@
1
+ import {
2
+ AppState,
3
+ AppStateStatus,
4
+ NativeEventSubscription,
5
+ } from "react-native";
6
+ import {
7
+ AmplitudeCore,
8
+ Destination,
9
+ UUID,
10
+ returnWrapper,
11
+ debugWrapper,
12
+ getClientLogConfig,
13
+ getClientStates,
14
+ ReactNativeConfig,
15
+ ReactNativeOptions,
16
+ ReactNativeAttributionOptions as AttributionOptions,
17
+ IIdentify,
18
+ EventOptions,
19
+ Event,
20
+ Result,
21
+ ReactNativeClient,
22
+ Campaign,
23
+ IdentityEventSender,
24
+ getAnalyticsConnector,
25
+ setConnectorDeviceId,
26
+ setConnectorUserId,
27
+ SpecialEventType,
28
+ AnalyticsClient,
29
+ } from "@amplitude/analytics-core";
30
+ import { CampaignTracker } from "./campaign/campaign-tracker";
31
+ import { Context } from "./plugins/context";
32
+ import { useReactNativeConfig, createCookieStorage } from "./config";
33
+ import { parseOldCookies } from "./cookie-migration";
34
+ import { isNative } from "./utils/platform";
35
+
36
+ const START_SESSION_EVENT = "session_start";
37
+ const END_SESSION_EVENT = "session_end";
38
+
39
+ type ScheduledDestination = {
40
+ scheduleId?: ReturnType<typeof setTimeout> | null;
41
+ flushId?: ReturnType<typeof setTimeout> | null;
42
+ queue?: unknown[];
43
+ resetSchedule?: () => void;
44
+ };
45
+
46
+ export type AmplitudeReactNativeClient = ReactNativeClient & {
47
+ shutdown: () => void;
48
+ };
49
+
50
+ let nextConnectorOwnerId = 0;
51
+ let activeConnectorOwnerId: number | undefined;
52
+
53
+ export class AmplitudeReactNative
54
+ extends AmplitudeCore
55
+ implements ReactNativeClient, AnalyticsClient
56
+ {
57
+ appState: AppStateStatus = "background";
58
+ private appStateChangeHandler: NativeEventSubscription | undefined;
59
+ private initPromise: Promise<void> | undefined;
60
+ private readonly connectorOwnerId = ++nextConnectorOwnerId;
61
+ explicitSessionId: number | undefined;
62
+
63
+ // @ts-ignore
64
+ config: ReactNativeConfig;
65
+ userProperties: { [key: string]: any } | undefined;
66
+
67
+ init(apiKey = "", userId?: string, options?: ReactNativeOptions) {
68
+ this.initPromise =
69
+ this.initPromise ??
70
+ this._init({ ...options, userId, apiKey }).finally(() => {
71
+ this.initPromise = undefined;
72
+ });
73
+ return returnWrapper(this.initPromise);
74
+ }
75
+ protected async _init(options: ReactNativeOptions & { apiKey: string }) {
76
+ // Step 0: Block concurrent initialization
77
+ if (this.initializing) {
78
+ return;
79
+ }
80
+ this.initializing = true;
81
+ this.explicitSessionId = options.sessionId;
82
+ let appStateHandlerInstalled = false;
83
+
84
+ try {
85
+ // Step 1: Read cookies stored by old SDK
86
+ const oldCookies = await parseOldCookies(options.apiKey, options);
87
+
88
+ // Step 2: Create react native config
89
+ const reactNativeOptions = await useReactNativeConfig(options.apiKey, {
90
+ ...options,
91
+ deviceId: options.deviceId ?? oldCookies.deviceId,
92
+ sessionId: oldCookies.sessionId,
93
+ optOut: options.optOut ?? oldCookies.optOut,
94
+ lastEventTime: oldCookies.lastEventTime,
95
+ userId: options.userId ?? oldCookies.userId,
96
+ });
97
+ await super._init(reactNativeOptions);
98
+
99
+ // Set up the analytics connector to integrate with the experiment SDK.
100
+ // Send events from the experiment SDK and forward identifies to the
101
+ // identity store.
102
+ const connector = getAnalyticsConnector();
103
+ connector.identityStore.setIdentity({
104
+ userId: this.config.userId,
105
+ deviceId: this.config.deviceId,
106
+ });
107
+
108
+ // Step 3: Install plugins
109
+ // Do not track any events before this
110
+ await this.add(new Destination()).promise;
111
+ await this.add(new Context()).promise;
112
+ await this.add(new IdentityEventSender()).promise;
113
+
114
+ // Step 4: Manage session
115
+ this.appState = AppState.currentState;
116
+ const isNewSession = this.startNewSessionIfNeeded(
117
+ this.currentTimeMillis(),
118
+ );
119
+ this.config.loggerProvider?.log(
120
+ `Init: startNewSessionIfNeeded = ${isNewSession ? "yes" : "no"}, sessionId = ${
121
+ this.getSessionId() ?? "undefined"
122
+ }`,
123
+ );
124
+ this.appStateChangeHandler?.remove();
125
+ this.appStateChangeHandler = AppState.addEventListener(
126
+ "change",
127
+ this.handleAppStateChange,
128
+ );
129
+ appStateHandlerInstalled = true;
130
+
131
+ // Step 5: Track attributions
132
+ await this.runAttributionStrategy(options.attribution, isNewSession);
133
+
134
+ // Step 6: Run queued functions
135
+ await this.runQueuedFunctions("dispatchQ");
136
+
137
+ // Step 7: Add the event receiver after running remaining queued functions.
138
+ connector.eventBridge.setEventReceiver((event) => {
139
+ this.handleInternalTrackPromise(
140
+ this.track(event.eventType, event.eventProperties).promise,
141
+ );
142
+ });
143
+ activeConnectorOwnerId = this.connectorOwnerId;
144
+ } catch (error) {
145
+ if (appStateHandlerInstalled) {
146
+ this.appStateChangeHandler?.remove();
147
+ this.appStateChangeHandler = undefined;
148
+ }
149
+ throw error;
150
+ } finally {
151
+ this.initializing = false;
152
+ }
153
+ }
154
+
155
+ shutdown() {
156
+ this.appStateChangeHandler?.remove();
157
+ this.appStateChangeHandler = undefined;
158
+
159
+ this.cancelDestinationFlushes();
160
+ this.timeline.reset(this);
161
+ this.q = [];
162
+ this.dispatchQ = [];
163
+ this.isReady = false;
164
+
165
+ if (activeConnectorOwnerId === this.connectorOwnerId) {
166
+ const connector = getAnalyticsConnector();
167
+ connector.eventBridge.setEventReceiver(() => undefined);
168
+ connector.identityStore.setIdentity({});
169
+ activeConnectorOwnerId = undefined;
170
+ }
171
+ }
172
+
173
+ private handleInternalTrackPromise(promise: Promise<unknown>) {
174
+ void promise.catch((error) => {
175
+ this.config?.loggerProvider?.error(
176
+ `Internal track call failed: ${String(error)}`,
177
+ );
178
+ });
179
+ }
180
+
181
+ private cancelDestinationFlushes() {
182
+ this.timeline.plugins.forEach((plugin) => {
183
+ if (plugin.type !== "destination") {
184
+ return;
185
+ }
186
+
187
+ const destination = plugin as ScheduledDestination;
188
+ if (destination.scheduleId) {
189
+ clearTimeout(destination.scheduleId);
190
+ }
191
+ if (destination.flushId) {
192
+ clearTimeout(destination.flushId);
193
+ }
194
+ destination.resetSchedule?.();
195
+ destination.flushId = null;
196
+ destination.queue = [];
197
+ });
198
+ }
199
+
200
+ async runAttributionStrategy(
201
+ attributionConfig?: AttributionOptions,
202
+ isNewSession = false,
203
+ ) {
204
+ if (isNative()) {
205
+ return;
206
+ }
207
+ const track = (...args: Parameters<typeof this.track>) =>
208
+ this.track(...args).promise;
209
+ const onNewCampaign = this.setSessionId.bind(
210
+ this,
211
+ this.currentTimeMillis(),
212
+ );
213
+
214
+ const storage = await createCookieStorage<Campaign>(this.config);
215
+ const campaignTracker = new CampaignTracker(this.config.apiKey, {
216
+ ...attributionConfig,
217
+ storage,
218
+ track,
219
+ onNewCampaign,
220
+ });
221
+
222
+ await campaignTracker.send(isNewSession);
223
+ }
224
+
225
+ getUserId() {
226
+ return this.config?.userId;
227
+ }
228
+
229
+ setUserId(userId: string | undefined) {
230
+ if (!this.config) {
231
+ this.q.push(this.setUserId.bind(this, userId));
232
+ return;
233
+ }
234
+ this.config.userId = userId;
235
+ setConnectorUserId(userId);
236
+ }
237
+
238
+ getDeviceId() {
239
+ return this.config?.deviceId;
240
+ }
241
+
242
+ setDeviceId(deviceId: string) {
243
+ if (!this.config) {
244
+ this.q.push(this.setDeviceId.bind(this, deviceId));
245
+ return;
246
+ }
247
+ this.config.deviceId = deviceId;
248
+ setConnectorDeviceId(deviceId);
249
+ }
250
+
251
+ identify(identify: IIdentify, eventOptions?: EventOptions) {
252
+ if (eventOptions?.user_id) {
253
+ this.setUserId(eventOptions.user_id);
254
+ }
255
+ if (eventOptions?.device_id) {
256
+ this.setDeviceId(eventOptions.device_id);
257
+ }
258
+ return super.identify(identify, eventOptions);
259
+ }
260
+
261
+ reset() {
262
+ this.setUserId(undefined);
263
+ this.setDeviceId(UUID());
264
+ }
265
+
266
+ getSessionId() {
267
+ return this.config?.sessionId;
268
+ }
269
+
270
+ getIdentity() {
271
+ return {
272
+ userId: this.getUserId(),
273
+ deviceId: this.getDeviceId(),
274
+ userProperties: this.userProperties,
275
+ };
276
+ }
277
+
278
+ getOptOut() {
279
+ return this.config?.optOut;
280
+ }
281
+
282
+ setSessionId(sessionId: number) {
283
+ if (!this.config) {
284
+ this.q.push(this.setSessionId.bind(this, sessionId));
285
+ return;
286
+ }
287
+
288
+ this.explicitSessionId = sessionId;
289
+ this.setSessionIdInternal(sessionId, this.currentTimeMillis());
290
+ }
291
+
292
+ extendSession() {
293
+ if (!this.config) {
294
+ this.q.push(this.extendSession.bind(this));
295
+ return;
296
+ }
297
+ this.config.lastEventTime = this.currentTimeMillis();
298
+ }
299
+
300
+ private setSessionIdInternal(sessionId: number, eventTime: number) {
301
+ const previousSessionId = this.config.sessionId;
302
+ if (previousSessionId === sessionId) {
303
+ return;
304
+ }
305
+
306
+ this.config.sessionId = sessionId;
307
+
308
+ if (this.config.trackingSessionEvents) {
309
+ this.config.loggerProvider?.log(
310
+ `SESSION_END event: previousSessionId = ${previousSessionId ?? "undefined"}`,
311
+ );
312
+
313
+ if (previousSessionId !== undefined) {
314
+ const sessionEndEvent: Event = {
315
+ event_type: END_SESSION_EVENT,
316
+ time:
317
+ this.config.lastEventTime !== undefined
318
+ ? this.config.lastEventTime + 1
319
+ : sessionId, // increment lastEventTime to sort events properly in UI - session_end should be the last event in a session
320
+ session_id: previousSessionId,
321
+ };
322
+ this.handleInternalTrackPromise(this.track(sessionEndEvent).promise);
323
+ }
324
+
325
+ this.config.loggerProvider?.log(
326
+ `SESSION_START event: sessionId = ${sessionId}`,
327
+ );
328
+ const sessionStartEvent: Event = {
329
+ event_type: START_SESSION_EVENT,
330
+ time: eventTime,
331
+ session_id: sessionId,
332
+ };
333
+ this.handleInternalTrackPromise(this.track(sessionStartEvent).promise);
334
+ }
335
+
336
+ this.config.lastEventTime = eventTime;
337
+ }
338
+
339
+ async process(event: Event): Promise<Result> {
340
+ if (!this.config.optOut) {
341
+ const eventTime = event.time ?? this.currentTimeMillis();
342
+ if (event.time === undefined) {
343
+ event = { ...event, time: eventTime };
344
+ }
345
+
346
+ const isSessionEvent =
347
+ event.event_type === START_SESSION_EVENT ||
348
+ event.event_type === END_SESSION_EVENT;
349
+ const isCustomEventSessionId =
350
+ !isSessionEvent &&
351
+ event.session_id != undefined &&
352
+ event.session_id !== this.getSessionId();
353
+ if (!isCustomEventSessionId) {
354
+ if (!isSessionEvent) {
355
+ if (this.appState !== "active") {
356
+ this.startNewSessionIfNeeded(eventTime);
357
+ }
358
+ }
359
+ this.config.lastEventTime = eventTime;
360
+ }
361
+
362
+ if (event.session_id == undefined) {
363
+ event.session_id = this.getSessionId();
364
+ }
365
+
366
+ if (event.event_id === undefined) {
367
+ const eventId = (this.config.lastEventId ?? 0) + 1;
368
+ event = { ...event, event_id: eventId };
369
+ this.config.lastEventId = eventId;
370
+ }
371
+ }
372
+
373
+ // Set user properties
374
+ if (
375
+ event.event_type === SpecialEventType.IDENTIFY &&
376
+ event.user_properties
377
+ ) {
378
+ this.userProperties = this.getOperationAppliedUserProperties(
379
+ event.user_properties,
380
+ );
381
+ }
382
+
383
+ return super.process(event);
384
+ }
385
+
386
+ currentTimeMillis() {
387
+ return Date.now();
388
+ }
389
+
390
+ private startNewSessionIfNeeded(timestamp: number): boolean {
391
+ const sessionId = this.explicitSessionId ?? timestamp;
392
+
393
+ const shouldStartNewSession = this.shouldStartNewSession(timestamp);
394
+ if (shouldStartNewSession) {
395
+ this.setSessionIdInternal(sessionId, timestamp);
396
+ } else {
397
+ this.config.lastEventTime = timestamp;
398
+ }
399
+
400
+ return shouldStartNewSession;
401
+ }
402
+
403
+ private shouldStartNewSession(timestamp: number): boolean {
404
+ const sessionId = this.explicitSessionId ?? timestamp;
405
+
406
+ return (
407
+ !this.inSession() ||
408
+ (this.explicitSessionId !== this.config.sessionId &&
409
+ (this.explicitSessionId !== undefined ||
410
+ !this.isWithinMinTimeBetweenSessions(sessionId)))
411
+ );
412
+ }
413
+
414
+ private isWithinMinTimeBetweenSessions(timestamp: number) {
415
+ return (
416
+ timestamp - (this.config.lastEventTime ?? 0) < this.config.sessionTimeout
417
+ );
418
+ }
419
+
420
+ private inSession() {
421
+ return this.config.sessionId != undefined;
422
+ }
423
+
424
+ private readonly handleAppStateChange = (nextAppState: AppStateStatus) => {
425
+ const currentAppState = this.appState;
426
+ this.appState = nextAppState;
427
+ if (currentAppState !== nextAppState) {
428
+ const timestamp = this.currentTimeMillis();
429
+ if (nextAppState == "active") {
430
+ this.enterForeground(timestamp);
431
+ } else {
432
+ this.exitForeground(timestamp);
433
+ }
434
+ }
435
+ };
436
+
437
+ private enterForeground(timestamp: number) {
438
+ this.config.loggerProvider?.log("App Activated");
439
+ return this.startNewSessionIfNeeded(timestamp);
440
+ }
441
+
442
+ private exitForeground(timestamp: number) {
443
+ this.config.lastEventTime = timestamp;
444
+ }
445
+ }
446
+
447
+ export const createInstance = (): AmplitudeReactNativeClient => {
448
+ const client = new AmplitudeReactNative();
449
+ return {
450
+ init: debugWrapper(
451
+ client.init.bind(client),
452
+ "init",
453
+ getClientLogConfig(client),
454
+ getClientStates(client, ["config"]),
455
+ ),
456
+ add: debugWrapper(
457
+ client.add.bind(client),
458
+ "add",
459
+ getClientLogConfig(client),
460
+ getClientStates(client, ["config.apiKey", "timeline.plugins"]),
461
+ ),
462
+ remove: debugWrapper(
463
+ client.remove.bind(client),
464
+ "remove",
465
+ getClientLogConfig(client),
466
+ getClientStates(client, ["config.apiKey", "timeline.plugins"]),
467
+ ),
468
+ track: debugWrapper(
469
+ client.track.bind(client),
470
+ "track",
471
+ getClientLogConfig(client),
472
+ getClientStates(client, ["config.apiKey", "timeline.queue.length"]),
473
+ ),
474
+ logEvent: debugWrapper(
475
+ client.logEvent.bind(client),
476
+ "logEvent",
477
+ getClientLogConfig(client),
478
+ getClientStates(client, ["config.apiKey", "timeline.queue.length"]),
479
+ ),
480
+ identify: debugWrapper(
481
+ client.identify.bind(client),
482
+ "identify",
483
+ getClientLogConfig(client),
484
+ getClientStates(client, ["config.apiKey", "timeline.queue.length"]),
485
+ ),
486
+ groupIdentify: debugWrapper(
487
+ client.groupIdentify.bind(client),
488
+ "groupIdentify",
489
+ getClientLogConfig(client),
490
+ getClientStates(client, ["config.apiKey", "timeline.queue.length"]),
491
+ ),
492
+ setGroup: debugWrapper(
493
+ client.setGroup.bind(client),
494
+ "setGroup",
495
+ getClientLogConfig(client),
496
+ getClientStates(client, ["config.apiKey", "timeline.queue.length"]),
497
+ ),
498
+ revenue: debugWrapper(
499
+ client.revenue.bind(client),
500
+ "revenue",
501
+ getClientLogConfig(client),
502
+ getClientStates(client, ["config.apiKey", "timeline.queue.length"]),
503
+ ),
504
+ flush: debugWrapper(
505
+ client.flush.bind(client),
506
+ "flush",
507
+ getClientLogConfig(client),
508
+ getClientStates(client, ["config.apiKey", "timeline.queue.length"]),
509
+ ),
510
+ getUserId: debugWrapper(
511
+ client.getUserId.bind(client),
512
+ "getUserId",
513
+ getClientLogConfig(client),
514
+ getClientStates(client, ["config", "config.userId"]),
515
+ ),
516
+ setUserId: debugWrapper(
517
+ client.setUserId.bind(client),
518
+ "setUserId",
519
+ getClientLogConfig(client),
520
+ getClientStates(client, ["config", "config.userId"]),
521
+ ),
522
+ getDeviceId: debugWrapper(
523
+ client.getDeviceId.bind(client),
524
+ "getDeviceId",
525
+ getClientLogConfig(client),
526
+ getClientStates(client, ["config", "config.deviceId"]),
527
+ ),
528
+ setDeviceId: debugWrapper(
529
+ client.setDeviceId.bind(client),
530
+ "setDeviceId",
531
+ getClientLogConfig(client),
532
+ getClientStates(client, ["config", "config.deviceId"]),
533
+ ),
534
+ reset: debugWrapper(
535
+ client.reset.bind(client),
536
+ "reset",
537
+ getClientLogConfig(client),
538
+ getClientStates(client, ["config", "config.userId", "config.deviceId"]),
539
+ ),
540
+ getSessionId: debugWrapper(
541
+ client.getSessionId.bind(client),
542
+ "getSessionId",
543
+ getClientLogConfig(client),
544
+ getClientStates(client, ["config"]),
545
+ ),
546
+ setSessionId: debugWrapper(
547
+ client.setSessionId.bind(client),
548
+ "setSessionId",
549
+ getClientLogConfig(client),
550
+ getClientStates(client, ["config"]),
551
+ ),
552
+ extendSession: debugWrapper(
553
+ client.extendSession.bind(client),
554
+ "extendSession",
555
+ getClientLogConfig(client),
556
+ getClientStates(client, ["config"]),
557
+ ),
558
+ setOptOut: debugWrapper(
559
+ client.setOptOut.bind(client),
560
+ "setOptOut",
561
+ getClientLogConfig(client),
562
+ getClientStates(client, ["config"]),
563
+ ),
564
+ shutdown: debugWrapper(
565
+ client.shutdown.bind(client),
566
+ "shutdown",
567
+ getClientLogConfig(client),
568
+ getClientStates(client, ["config", "timeline.plugins"]),
569
+ ),
570
+ };
571
+ };
572
+
573
+ export default createInstance();
@@ -0,0 +1,76 @@
1
+ import { Storage, getGlobalScope } from "@amplitude/analytics-core";
2
+
3
+ export class MemoryStorage<T> implements Storage<T> {
4
+ private static readonly memoryStorage = new Map<string, unknown>();
5
+
6
+ async isEnabled(): Promise<boolean> {
7
+ /* istanbul ignore if */
8
+ if (!getGlobalScope()) {
9
+ return false;
10
+ }
11
+
12
+ const random = String(Date.now());
13
+ const testStorage = new MemoryStorage<string>();
14
+ const testKey = "AMP_TEST";
15
+ try {
16
+ await testStorage.set(testKey, random);
17
+ const value = await testStorage.get(testKey);
18
+ return value === random;
19
+ } catch {
20
+ /* istanbul ignore next */
21
+ return false;
22
+ } finally {
23
+ await testStorage.remove(testKey);
24
+ }
25
+ }
26
+
27
+ async get(key: string): Promise<T | undefined> {
28
+ try {
29
+ const value = await this.getRaw(key);
30
+ if (!value) {
31
+ return undefined;
32
+ }
33
+
34
+ return JSON.parse(value);
35
+ } catch {
36
+ /* istanbul ignore next */
37
+ return undefined;
38
+ }
39
+ }
40
+
41
+ async getRaw(key: string): Promise<string | undefined> {
42
+ const value = MemoryStorage.memoryStorage.get(key);
43
+ if (typeof value !== "string") {
44
+ return undefined;
45
+ }
46
+ return value;
47
+ }
48
+
49
+ async set(key: string, value: T): Promise<void> {
50
+ try {
51
+ MemoryStorage.memoryStorage.set(key, JSON.stringify(value));
52
+ } catch {
53
+ //
54
+ }
55
+ }
56
+
57
+ async remove(key: string): Promise<void> {
58
+ try {
59
+ MemoryStorage.memoryStorage.delete(key);
60
+ } catch {
61
+ //
62
+ }
63
+ }
64
+
65
+ async reset(): Promise<void> {
66
+ try {
67
+ MemoryStorage.memoryStorage.clear();
68
+ } catch {
69
+ //
70
+ }
71
+ }
72
+ }
73
+
74
+ export class LocalStorage<T> extends MemoryStorage<T> {}
75
+
76
+ export { MemoryStorage as InMemoryStorage };
@@ -0,0 +1,30 @@
1
+ export {
2
+ AmplitudeReturn,
3
+ BaseEvent,
4
+ EventOptions,
5
+ ReactNativeClient,
6
+ ReactNativeAttributionOptions,
7
+ ReactNativeOptions,
8
+ ReactNativeConfig,
9
+ ReactNativeTrackingOptions,
10
+ Event,
11
+ IdentifyEvent,
12
+ GroupIdentifyEvent,
13
+ IdentifyOperation,
14
+ SpecialEventType,
15
+ IIdentify,
16
+ IRevenue,
17
+ RevenueProperty,
18
+ ILogger,
19
+ LogLevel,
20
+ Plugin,
21
+ BeforePlugin,
22
+ EnrichmentPlugin,
23
+ DestinationPlugin,
24
+ Result,
25
+ ServerZoneType,
26
+ ServerZone,
27
+ IdentityStorageType,
28
+ Storage,
29
+ TransportType,
30
+ } from "@amplitude/analytics-core";
@@ -0,0 +1,7 @@
1
+ import { InstanceProxy } from "@amplitude/analytics-core";
2
+
3
+ declare global {
4
+ // globalThis only includes `var` declarations
5
+
6
+ var amplitude: InstanceProxy & { invoked: boolean };
7
+ }
@@ -0,0 +1,4 @@
1
+ declare module "@amplitude/ua-parser-js" {
2
+ import UAParser from "ua-parser-js";
3
+ export = UAParser;
4
+ }
@@ -0,0 +1,9 @@
1
+ import { Platform } from "react-native";
2
+
3
+ export const isWeb = (): boolean => {
4
+ return Platform.OS === "web";
5
+ };
6
+
7
+ export const isNative = (): boolean => {
8
+ return !isWeb();
9
+ };
@@ -0,0 +1 @@
1
+ export const VERSION = "1.6.0";