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.
- package/.watchmanconfig +6 -0
- package/LICENSE +21 -0
- package/README.md +139 -0
- package/android/CMakeLists.txt +34 -0
- package/android/build.gradle +85 -0
- package/android/consumer-rules.pro +35 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/cpp/AndroidAmplitudeAdapterCpp.cpp +126 -0
- package/android/src/main/cpp/AndroidAmplitudeAdapterCpp.hpp +48 -0
- package/android/src/main/cpp/cpp-adapter.cpp +9 -0
- package/android/src/main/java/com/nitroamplitude/AndroidAmplitudeAdapter.kt +147 -0
- package/android/src/main/java/com/nitroamplitude/NitroAmplitudePackage.kt +24 -0
- package/app.plugin.js +36 -0
- package/cpp/bindings/HybridAmplitudeContext.cpp +83 -0
- package/cpp/bindings/HybridAmplitudeContext.hpp +29 -0
- package/cpp/bindings/HybridAmplitudeStorage.cpp +163 -0
- package/cpp/bindings/HybridAmplitudeStorage.hpp +38 -0
- package/cpp/bindings/HybridAmplitudeWorker.cpp +162 -0
- package/cpp/bindings/HybridAmplitudeWorker.hpp +74 -0
- package/cpp/core/NativeAmplitudeAdapter.hpp +44 -0
- package/ios/IOSAmplitudeAdapterCpp.hpp +37 -0
- package/ios/IOSAmplitudeAdapterCpp.mm +155 -0
- package/lib/commonjs/AmplitudeContext.nitro.js +6 -0
- package/lib/commonjs/AmplitudeContext.nitro.js.map +1 -0
- package/lib/commonjs/AmplitudeStorage.nitro.js +6 -0
- package/lib/commonjs/AmplitudeStorage.nitro.js.map +1 -0
- package/lib/commonjs/AmplitudeWorker.nitro.js +6 -0
- package/lib/commonjs/AmplitudeWorker.nitro.js.map +1 -0
- package/lib/commonjs/analytics/campaign/campaign-tracker.js +105 -0
- package/lib/commonjs/analytics/campaign/campaign-tracker.js.map +1 -0
- package/lib/commonjs/analytics/campaign/types.js +6 -0
- package/lib/commonjs/analytics/campaign/types.js.map +1 -0
- package/lib/commonjs/analytics/config.js +283 -0
- package/lib/commonjs/analytics/config.js.map +1 -0
- package/lib/commonjs/analytics/cookie-migration/index.js +59 -0
- package/lib/commonjs/analytics/cookie-migration/index.js.map +1 -0
- package/lib/commonjs/analytics/index.js +95 -0
- package/lib/commonjs/analytics/index.js.map +1 -0
- package/lib/commonjs/analytics/migration/remnant-data-migration.js +177 -0
- package/lib/commonjs/analytics/migration/remnant-data-migration.js.map +1 -0
- package/lib/commonjs/analytics/nitro-transport.js +31 -0
- package/lib/commonjs/analytics/nitro-transport.js.map +1 -0
- package/lib/commonjs/analytics/plugins/context.js +140 -0
- package/lib/commonjs/analytics/plugins/context.js.map +1 -0
- package/lib/commonjs/analytics/react-native-client.js +352 -0
- package/lib/commonjs/analytics/react-native-client.js.map +1 -0
- package/lib/commonjs/analytics/storage/local-storage.js +73 -0
- package/lib/commonjs/analytics/storage/local-storage.js.map +1 -0
- package/lib/commonjs/analytics/types.js +175 -0
- package/lib/commonjs/analytics/types.js.map +1 -0
- package/lib/commonjs/analytics/typings/browser-snippet.d.js +6 -0
- package/lib/commonjs/analytics/typings/browser-snippet.d.js.map +1 -0
- package/lib/commonjs/analytics/typings/ua-parser.d.js +2 -0
- package/lib/commonjs/analytics/typings/ua-parser.d.js.map +1 -0
- package/lib/commonjs/analytics/utils/platform.js +16 -0
- package/lib/commonjs/analytics/utils/platform.js.map +1 -0
- package/lib/commonjs/analytics/version.js +8 -0
- package/lib/commonjs/analytics/version.js.map +1 -0
- package/lib/commonjs/experiment/experimentClient.js +792 -0
- package/lib/commonjs/experiment/experimentClient.js.map +1 -0
- package/lib/commonjs/experiment/factory.js +77 -0
- package/lib/commonjs/experiment/factory.js.map +1 -0
- package/lib/commonjs/experiment/gen/version.js +9 -0
- package/lib/commonjs/experiment/gen/version.js.map +1 -0
- package/lib/commonjs/experiment/index.js +143 -0
- package/lib/commonjs/experiment/index.js.map +1 -0
- package/lib/commonjs/experiment/integration/NativeExperimentReactNativeClient.js +11 -0
- package/lib/commonjs/experiment/integration/NativeExperimentReactNativeClient.js.map +1 -0
- package/lib/commonjs/experiment/integration/connector.js +67 -0
- package/lib/commonjs/experiment/integration/connector.js.map +1 -0
- package/lib/commonjs/experiment/integration/default.js +92 -0
- package/lib/commonjs/experiment/integration/default.js.map +1 -0
- package/lib/commonjs/experiment/logger/ampLogger.js +80 -0
- package/lib/commonjs/experiment/logger/ampLogger.js.map +1 -0
- package/lib/commonjs/experiment/logger/consoleLogger.js +60 -0
- package/lib/commonjs/experiment/logger/consoleLogger.js.map +1 -0
- package/lib/commonjs/experiment/storage/cache.js +197 -0
- package/lib/commonjs/experiment/storage/cache.js.map +1 -0
- package/lib/commonjs/experiment/storage/local-storage.js +25 -0
- package/lib/commonjs/experiment/storage/local-storage.js.map +1 -0
- package/lib/commonjs/experiment/stubClient.js +46 -0
- package/lib/commonjs/experiment/stubClient.js.map +1 -0
- package/lib/commonjs/experiment/transport/http.js +72 -0
- package/lib/commonjs/experiment/transport/http.js.map +1 -0
- package/lib/commonjs/experiment/types/client.js +6 -0
- package/lib/commonjs/experiment/types/client.js.map +1 -0
- package/lib/commonjs/experiment/types/config.js +67 -0
- package/lib/commonjs/experiment/types/config.js.map +1 -0
- package/lib/commonjs/experiment/types/exposure.js +2 -0
- package/lib/commonjs/experiment/types/exposure.js.map +1 -0
- package/lib/commonjs/experiment/types/logger.js +42 -0
- package/lib/commonjs/experiment/types/logger.js.map +1 -0
- package/lib/commonjs/experiment/types/source.js +54 -0
- package/lib/commonjs/experiment/types/source.js.map +1 -0
- package/lib/commonjs/experiment/types/storage.js +2 -0
- package/lib/commonjs/experiment/types/storage.js.map +1 -0
- package/lib/commonjs/experiment/types/transport.js +2 -0
- package/lib/commonjs/experiment/types/transport.js.map +1 -0
- package/lib/commonjs/experiment/types/user.js +2 -0
- package/lib/commonjs/experiment/types/user.js.map +1 -0
- package/lib/commonjs/experiment/types/variant.js +2 -0
- package/lib/commonjs/experiment/types/variant.js.map +1 -0
- package/lib/commonjs/experiment/util/backoff.js +54 -0
- package/lib/commonjs/experiment/util/backoff.js.map +1 -0
- package/lib/commonjs/experiment/util/base64.js +23 -0
- package/lib/commonjs/experiment/util/base64.js.map +1 -0
- package/lib/commonjs/experiment/util/convert.js +78 -0
- package/lib/commonjs/experiment/util/convert.js.map +1 -0
- package/lib/commonjs/experiment/util/index.js +25 -0
- package/lib/commonjs/experiment/util/index.js.map +1 -0
- package/lib/commonjs/experiment/util/platform.js +16 -0
- package/lib/commonjs/experiment/util/platform.js.map +1 -0
- package/lib/commonjs/experiment/util/randomstring.js +16 -0
- package/lib/commonjs/experiment/util/randomstring.js.map +1 -0
- package/lib/commonjs/experiment/util/userSessionExposureTracker.js +40 -0
- package/lib/commonjs/experiment/util/userSessionExposureTracker.js.map +1 -0
- package/lib/commonjs/index.js +298 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/index.web.js +22 -0
- package/lib/commonjs/index.web.js.map +1 -0
- package/lib/commonjs/native/context.js +43 -0
- package/lib/commonjs/native/context.js.map +1 -0
- package/lib/commonjs/native/http.js +62 -0
- package/lib/commonjs/native/http.js.map +1 -0
- package/lib/commonjs/native/hybrid.js +31 -0
- package/lib/commonjs/native/hybrid.js.map +1 -0
- package/lib/commonjs/native/storage.js +93 -0
- package/lib/commonjs/native/storage.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/AmplitudeContext.nitro.js +4 -0
- package/lib/module/AmplitudeContext.nitro.js.map +1 -0
- package/lib/module/AmplitudeStorage.nitro.js +4 -0
- package/lib/module/AmplitudeStorage.nitro.js.map +1 -0
- package/lib/module/AmplitudeWorker.nitro.js +4 -0
- package/lib/module/AmplitudeWorker.nitro.js.map +1 -0
- package/lib/module/analytics/campaign/campaign-tracker.js +100 -0
- package/lib/module/analytics/campaign/campaign-tracker.js.map +1 -0
- package/lib/module/analytics/campaign/types.js +4 -0
- package/lib/module/analytics/campaign/types.js.map +1 -0
- package/lib/module/analytics/config.js +272 -0
- package/lib/module/analytics/config.js.map +1 -0
- package/lib/module/analytics/cookie-migration/index.js +51 -0
- package/lib/module/analytics/cookie-migration/index.js.map +1 -0
- package/lib/module/analytics/index.js +34 -0
- package/lib/module/analytics/index.js.map +1 -0
- package/lib/module/analytics/migration/remnant-data-migration.js +172 -0
- package/lib/module/analytics/migration/remnant-data-migration.js.map +1 -0
- package/lib/module/analytics/nitro-transport.js +26 -0
- package/lib/module/analytics/nitro-transport.js.map +1 -0
- package/lib/module/analytics/plugins/context.js +134 -0
- package/lib/module/analytics/plugins/context.js.map +1 -0
- package/lib/module/analytics/react-native-client.js +346 -0
- package/lib/module/analytics/react-native-client.js.map +1 -0
- package/lib/module/analytics/storage/local-storage.js +68 -0
- package/lib/module/analytics/storage/local-storage.js.map +1 -0
- package/lib/module/analytics/types.js +4 -0
- package/lib/module/analytics/types.js.map +1 -0
- package/lib/module/analytics/typings/browser-snippet.d.js +4 -0
- package/lib/module/analytics/typings/browser-snippet.d.js.map +1 -0
- package/lib/module/analytics/typings/ua-parser.d.js +2 -0
- package/lib/module/analytics/typings/ua-parser.d.js.map +1 -0
- package/lib/module/analytics/utils/platform.js +10 -0
- package/lib/module/analytics/utils/platform.js.map +1 -0
- package/lib/module/analytics/version.js +4 -0
- package/lib/module/analytics/version.js.map +1 -0
- package/lib/module/experiment/experimentClient.js +788 -0
- package/lib/module/experiment/experimentClient.js.map +1 -0
- package/lib/module/experiment/factory.js +73 -0
- package/lib/module/experiment/factory.js.map +1 -0
- package/lib/module/experiment/gen/version.js +5 -0
- package/lib/module/experiment/gen/version.js.map +1 -0
- package/lib/module/experiment/index.js +16 -0
- package/lib/module/experiment/index.js.map +1 -0
- package/lib/module/experiment/integration/NativeExperimentReactNativeClient.js +7 -0
- package/lib/module/experiment/integration/NativeExperimentReactNativeClient.js.map +1 -0
- package/lib/module/experiment/integration/connector.js +61 -0
- package/lib/module/experiment/integration/connector.js.map +1 -0
- package/lib/module/experiment/integration/default.js +87 -0
- package/lib/module/experiment/integration/default.js.map +1 -0
- package/lib/module/experiment/logger/ampLogger.js +76 -0
- package/lib/module/experiment/logger/ampLogger.js.map +1 -0
- package/lib/module/experiment/logger/consoleLogger.js +55 -0
- package/lib/module/experiment/logger/consoleLogger.js.map +1 -0
- package/lib/module/experiment/storage/cache.js +187 -0
- package/lib/module/experiment/storage/cache.js.map +1 -0
- package/lib/module/experiment/storage/local-storage.js +19 -0
- package/lib/module/experiment/storage/local-storage.js.map +1 -0
- package/lib/module/experiment/stubClient.js +41 -0
- package/lib/module/experiment/stubClient.js.map +1 -0
- package/lib/module/experiment/transport/http.js +66 -0
- package/lib/module/experiment/transport/http.js.map +1 -0
- package/lib/module/experiment/types/client.js +4 -0
- package/lib/module/experiment/types/client.js.map +1 -0
- package/lib/module/experiment/types/config.js +64 -0
- package/lib/module/experiment/types/config.js.map +1 -0
- package/lib/module/experiment/types/exposure.js +2 -0
- package/lib/module/experiment/types/exposure.js.map +1 -0
- package/lib/module/experiment/types/logger.js +39 -0
- package/lib/module/experiment/types/logger.js.map +1 -0
- package/lib/module/experiment/types/source.js +51 -0
- package/lib/module/experiment/types/source.js.map +1 -0
- package/lib/module/experiment/types/storage.js +2 -0
- package/lib/module/experiment/types/storage.js.map +1 -0
- package/lib/module/experiment/types/transport.js +2 -0
- package/lib/module/experiment/types/transport.js.map +1 -0
- package/lib/module/experiment/types/user.js +2 -0
- package/lib/module/experiment/types/user.js.map +1 -0
- package/lib/module/experiment/types/variant.js +2 -0
- package/lib/module/experiment/types/variant.js.map +1 -0
- package/lib/module/experiment/util/backoff.js +49 -0
- package/lib/module/experiment/util/backoff.js.map +1 -0
- package/lib/module/experiment/util/base64.js +16 -0
- package/lib/module/experiment/util/base64.js.map +1 -0
- package/lib/module/experiment/util/convert.js +71 -0
- package/lib/module/experiment/util/convert.js.map +1 -0
- package/lib/module/experiment/util/index.js +17 -0
- package/lib/module/experiment/util/index.js.map +1 -0
- package/lib/module/experiment/util/platform.js +10 -0
- package/lib/module/experiment/util/platform.js.map +1 -0
- package/lib/module/experiment/util/randomstring.js +11 -0
- package/lib/module/experiment/util/randomstring.js.map +1 -0
- package/lib/module/experiment/util/userSessionExposureTracker.js +35 -0
- package/lib/module/experiment/util/userSessionExposureTracker.js.map +1 -0
- package/lib/module/index.js +50 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/index.web.js +14 -0
- package/lib/module/index.web.js.map +1 -0
- package/lib/module/native/context.js +35 -0
- package/lib/module/native/context.js.map +1 -0
- package/lib/module/native/http.js +57 -0
- package/lib/module/native/http.js.map +1 -0
- package/lib/module/native/hybrid.js +24 -0
- package/lib/module/native/hybrid.js.map +1 -0
- package/lib/module/native/storage.js +86 -0
- package/lib/module/native/storage.js.map +1 -0
- package/lib/typescript/AmplitudeContext.nitro.d.ts +17 -0
- package/lib/typescript/AmplitudeContext.nitro.d.ts.map +1 -0
- package/lib/typescript/AmplitudeStorage.nitro.d.ts +17 -0
- package/lib/typescript/AmplitudeStorage.nitro.d.ts.map +1 -0
- package/lib/typescript/AmplitudeWorker.nitro.d.ts +11 -0
- package/lib/typescript/AmplitudeWorker.nitro.d.ts.map +1 -0
- package/lib/typescript/analytics/campaign/campaign-tracker.d.ts +85 -0
- package/lib/typescript/analytics/campaign/campaign-tracker.d.ts.map +1 -0
- package/lib/typescript/analytics/campaign/types.d.ts +11 -0
- package/lib/typescript/analytics/campaign/types.d.ts.map +1 -0
- package/lib/typescript/analytics/config.d.ts +68 -0
- package/lib/typescript/analytics/config.d.ts.map +1 -0
- package/lib/typescript/analytics/cookie-migration/index.d.ts +6 -0
- package/lib/typescript/analytics/cookie-migration/index.d.ts.map +1 -0
- package/lib/typescript/analytics/index.d.ts +7 -0
- package/lib/typescript/analytics/index.d.ts.map +1 -0
- package/lib/typescript/analytics/migration/remnant-data-migration.d.ts +20 -0
- package/lib/typescript/analytics/migration/remnant-data-migration.d.ts.map +1 -0
- package/lib/typescript/analytics/nitro-transport.d.ts +9 -0
- package/lib/typescript/analytics/nitro-transport.d.ts.map +1 -0
- package/lib/typescript/analytics/plugins/context.d.ts +14 -0
- package/lib/typescript/analytics/plugins/context.d.ts.map +1 -0
- package/lib/typescript/analytics/react-native-client.d.ts +55 -0
- package/lib/typescript/analytics/react-native-client.d.ts.map +1 -0
- package/lib/typescript/analytics/storage/local-storage.d.ts +14 -0
- package/lib/typescript/analytics/storage/local-storage.d.ts.map +1 -0
- package/lib/typescript/analytics/types.d.ts +2 -0
- package/lib/typescript/analytics/types.d.ts.map +1 -0
- package/lib/typescript/analytics/utils/platform.d.ts +3 -0
- package/lib/typescript/analytics/utils/platform.d.ts.map +1 -0
- package/lib/typescript/analytics/version.d.ts +2 -0
- package/lib/typescript/analytics/version.d.ts.map +1 -0
- package/lib/typescript/experiment/experimentClient.d.ts +234 -0
- package/lib/typescript/experiment/experimentClient.d.ts.map +1 -0
- package/lib/typescript/experiment/factory.d.ts +11 -0
- package/lib/typescript/experiment/factory.d.ts.map +1 -0
- package/lib/typescript/experiment/gen/version.d.ts +2 -0
- package/lib/typescript/experiment/gen/version.d.ts.map +1 -0
- package/lib/typescript/experiment/index.d.ts +15 -0
- package/lib/typescript/experiment/index.d.ts.map +1 -0
- package/lib/typescript/experiment/integration/NativeExperimentReactNativeClient.d.ts +16 -0
- package/lib/typescript/experiment/integration/NativeExperimentReactNativeClient.d.ts.map +1 -0
- package/lib/typescript/experiment/integration/connector.d.ts +16 -0
- package/lib/typescript/experiment/integration/connector.d.ts.map +1 -0
- package/lib/typescript/experiment/integration/default.d.ts +20 -0
- package/lib/typescript/experiment/integration/default.d.ts.map +1 -0
- package/lib/typescript/experiment/logger/ampLogger.d.ts +47 -0
- package/lib/typescript/experiment/logger/ampLogger.d.ts.map +1 -0
- package/lib/typescript/experiment/logger/consoleLogger.d.ts +40 -0
- package/lib/typescript/experiment/logger/consoleLogger.d.ts.map +1 -0
- package/lib/typescript/experiment/storage/cache.d.ts +35 -0
- package/lib/typescript/experiment/storage/cache.d.ts.map +1 -0
- package/lib/typescript/experiment/storage/local-storage.d.ts +11 -0
- package/lib/typescript/experiment/storage/local-storage.d.ts.map +1 -0
- package/lib/typescript/experiment/stubClient.d.ts +21 -0
- package/lib/typescript/experiment/stubClient.d.ts.map +1 -0
- package/lib/typescript/experiment/transport/http.d.ts +17 -0
- package/lib/typescript/experiment/transport/http.d.ts.map +1 -0
- package/lib/typescript/experiment/types/client.d.ts +36 -0
- package/lib/typescript/experiment/types/client.d.ts.map +1 -0
- package/lib/typescript/experiment/types/config.d.ts +164 -0
- package/lib/typescript/experiment/types/config.d.ts.map +1 -0
- package/lib/typescript/experiment/types/exposure.d.ts +107 -0
- package/lib/typescript/experiment/types/exposure.d.ts.map +1 -0
- package/lib/typescript/experiment/types/logger.d.ts +67 -0
- package/lib/typescript/experiment/types/logger.d.ts.map +1 -0
- package/lib/typescript/experiment/types/source.d.ts +43 -0
- package/lib/typescript/experiment/types/source.d.ts.map +1 -0
- package/lib/typescript/experiment/types/storage.d.ts +7 -0
- package/lib/typescript/experiment/types/storage.d.ts.map +1 -0
- package/lib/typescript/experiment/types/transport.d.ts +8 -0
- package/lib/typescript/experiment/types/transport.d.ts.map +1 -0
- package/lib/typescript/experiment/types/user.d.ts +106 -0
- package/lib/typescript/experiment/types/user.d.ts.map +1 -0
- package/lib/typescript/experiment/types/variant.d.ts +33 -0
- package/lib/typescript/experiment/types/variant.d.ts.map +1 -0
- package/lib/typescript/experiment/util/backoff.d.ts +14 -0
- package/lib/typescript/experiment/util/backoff.d.ts.map +1 -0
- package/lib/typescript/experiment/util/base64.d.ts +3 -0
- package/lib/typescript/experiment/util/base64.d.ts.map +1 -0
- package/lib/typescript/experiment/util/convert.d.ts +7 -0
- package/lib/typescript/experiment/util/convert.d.ts.map +1 -0
- package/lib/typescript/experiment/util/index.d.ts +6 -0
- package/lib/typescript/experiment/util/index.d.ts.map +1 -0
- package/lib/typescript/experiment/util/platform.d.ts +3 -0
- package/lib/typescript/experiment/util/platform.d.ts.map +1 -0
- package/lib/typescript/experiment/util/randomstring.d.ts +2 -0
- package/lib/typescript/experiment/util/randomstring.d.ts.map +1 -0
- package/lib/typescript/experiment/util/userSessionExposureTracker.d.ts +16 -0
- package/lib/typescript/experiment/util/userSessionExposureTracker.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +31 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/index.web.d.ts +12 -0
- package/lib/typescript/index.web.d.ts.map +1 -0
- package/lib/typescript/native/context.d.ts +29 -0
- package/lib/typescript/native/context.d.ts.map +1 -0
- package/lib/typescript/native/http.d.ts +6 -0
- package/lib/typescript/native/http.d.ts.map +1 -0
- package/lib/typescript/native/hybrid.d.ts +8 -0
- package/lib/typescript/native/hybrid.d.ts.map +1 -0
- package/lib/typescript/native/storage.d.ts +29 -0
- package/lib/typescript/native/storage.d.ts.map +1 -0
- package/nitro.json +33 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroAmplitude+autolinking.cmake +83 -0
- package/nitrogen/generated/android/NitroAmplitude+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroAmplitudeOnLoad.cpp +69 -0
- package/nitrogen/generated/android/NitroAmplitudeOnLoad.hpp +34 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/com/nitroamplitude/NitroAmplitudeOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroAmplitude+autolinking.rb +62 -0
- package/nitrogen/generated/ios/NitroAmplitude-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/NitroAmplitude-Swift-Cxx-Bridge.hpp +27 -0
- package/nitrogen/generated/ios/NitroAmplitude-Swift-Cxx-Umbrella.hpp +38 -0
- package/nitrogen/generated/ios/NitroAmplitudeAutolinking.mm +55 -0
- package/nitrogen/generated/ios/NitroAmplitudeAutolinking.swift +16 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeContextSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeContextSpec.hpp +67 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeStorageSpec.cpp +30 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeStorageSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeWorkerSpec.cpp +24 -0
- package/nitrogen/generated/shared/c++/HybridAmplitudeWorkerSpec.hpp +66 -0
- package/package.json +130 -0
- package/react-native-nitro-amplitude.podspec +36 -0
- package/src/AmplitudeContext.nitro.ts +21 -0
- package/src/AmplitudeStorage.nitro.ts +17 -0
- package/src/AmplitudeWorker.nitro.ts +25 -0
- package/src/analytics/campaign/campaign-tracker.ts +162 -0
- package/src/analytics/campaign/types.ts +18 -0
- package/src/analytics/config.ts +373 -0
- package/src/analytics/cookie-migration/index.ts +69 -0
- package/src/analytics/index.ts +36 -0
- package/src/analytics/migration/remnant-data-migration.ts +206 -0
- package/src/analytics/nitro-transport.ts +35 -0
- package/src/analytics/plugins/context.ts +166 -0
- package/src/analytics/react-native-client.ts +573 -0
- package/src/analytics/storage/local-storage.ts +76 -0
- package/src/analytics/types.ts +30 -0
- package/src/analytics/typings/browser-snippet.d.ts +7 -0
- package/src/analytics/typings/ua-parser.d.ts +4 -0
- package/src/analytics/utils/platform.ts +9 -0
- package/src/analytics/version.ts +1 -0
- package/src/experiment/experimentClient.ts +987 -0
- package/src/experiment/factory.ts +86 -0
- package/src/experiment/gen/version.ts +2 -0
- package/src/experiment/index.ts +14 -0
- package/src/experiment/integration/NativeExperimentReactNativeClient.ts +25 -0
- package/src/experiment/integration/connector.ts +82 -0
- package/src/experiment/integration/default.ts +107 -0
- package/src/experiment/logger/ampLogger.ts +76 -0
- package/src/experiment/logger/consoleLogger.ts +54 -0
- package/src/experiment/storage/cache.ts +271 -0
- package/src/experiment/storage/local-storage.ts +23 -0
- package/src/experiment/stubClient.ts +61 -0
- package/src/experiment/transport/http.ts +105 -0
- package/src/experiment/types/client.ts +38 -0
- package/src/experiment/types/config.ts +210 -0
- package/src/experiment/types/exposure.ts +107 -0
- package/src/experiment/types/logger.ts +71 -0
- package/src/experiment/types/source.ts +52 -0
- package/src/experiment/types/storage.ts +6 -0
- package/src/experiment/types/transport.ts +14 -0
- package/src/experiment/types/user.ts +132 -0
- package/src/experiment/types/variant.ts +36 -0
- package/src/experiment/util/backoff.ts +67 -0
- package/src/experiment/util/base64.ts +20 -0
- package/src/experiment/util/convert.ts +78 -0
- package/src/experiment/util/index.ts +23 -0
- package/src/experiment/util/platform.ts +9 -0
- package/src/experiment/util/randomstring.ts +12 -0
- package/src/experiment/util/userSessionExposureTracker.ts +47 -0
- package/src/index.ts +66 -0
- package/src/index.web.ts +19 -0
- package/src/native/context.ts +73 -0
- package/src/native/http.ts +77 -0
- package/src/native/hybrid.ts +32 -0
- package/src/native/storage.ts +107 -0
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Config,
|
|
3
|
+
MemoryStorage,
|
|
4
|
+
UUID,
|
|
5
|
+
ReactNativeConfig as IReactNativeConfig,
|
|
6
|
+
ReactNativeTrackingOptions,
|
|
7
|
+
Event,
|
|
8
|
+
ReactNativeOptions,
|
|
9
|
+
Storage,
|
|
10
|
+
UserSession,
|
|
11
|
+
CookieStorage,
|
|
12
|
+
getCookieName,
|
|
13
|
+
getQueryParams,
|
|
14
|
+
FetchTransport,
|
|
15
|
+
} from "@amplitude/analytics-core";
|
|
16
|
+
|
|
17
|
+
import { LocalStorage } from "./storage/local-storage";
|
|
18
|
+
import RemnantDataMigration from "./migration/remnant-data-migration";
|
|
19
|
+
import { NitroAnalyticsStorage } from "../native/storage";
|
|
20
|
+
import { nitroTransport } from "./nitro-transport";
|
|
21
|
+
|
|
22
|
+
export const getDefaultConfig = () => {
|
|
23
|
+
const cookieStorage = new MemoryStorage<UserSession>();
|
|
24
|
+
const trackingOptions: Required<ReactNativeTrackingOptions> = {
|
|
25
|
+
adid: true,
|
|
26
|
+
carrier: true,
|
|
27
|
+
deviceManufacturer: true,
|
|
28
|
+
deviceModel: true,
|
|
29
|
+
ipAddress: true,
|
|
30
|
+
language: true,
|
|
31
|
+
osName: true,
|
|
32
|
+
osVersion: true,
|
|
33
|
+
platform: true,
|
|
34
|
+
appSetId: true,
|
|
35
|
+
idfv: true,
|
|
36
|
+
country: false, // NOTE: tracking country information would disable server-side IP address lookup to fill other information like region, city, dma, etc.
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
cookieExpiration: 365,
|
|
40
|
+
cookieSameSite: "Lax",
|
|
41
|
+
cookieSecure: false,
|
|
42
|
+
cookieStorage,
|
|
43
|
+
cookieUpgrade: true,
|
|
44
|
+
disableCookies: true,
|
|
45
|
+
domain: "",
|
|
46
|
+
sessionTimeout: 5 * 60 * 1000,
|
|
47
|
+
storageProvider: new NitroAnalyticsStorage<Event[]>("analytics-events"),
|
|
48
|
+
trackingSessionEvents: false,
|
|
49
|
+
trackingOptions,
|
|
50
|
+
transportProvider: nitroTransport,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export class ReactNativeConfig extends Config implements IReactNativeConfig {
|
|
55
|
+
appVersion?: string;
|
|
56
|
+
cookieExpiration: number;
|
|
57
|
+
cookieSameSite: string;
|
|
58
|
+
cookieSecure: boolean;
|
|
59
|
+
cookieStorage: Storage<UserSession>;
|
|
60
|
+
cookieUpgrade: boolean;
|
|
61
|
+
disableCookies: boolean;
|
|
62
|
+
domain: string;
|
|
63
|
+
partnerId?: string;
|
|
64
|
+
sessionTimeout: number;
|
|
65
|
+
trackingSessionEvents: boolean;
|
|
66
|
+
trackingOptions: ReactNativeTrackingOptions;
|
|
67
|
+
|
|
68
|
+
// NOTE: These protected properties cache user session values in the configured session storage
|
|
69
|
+
protected _deviceId?: string;
|
|
70
|
+
protected _lastEventId?: number;
|
|
71
|
+
protected _lastEventTime?: number;
|
|
72
|
+
protected _optOut = false;
|
|
73
|
+
protected _sessionId?: number;
|
|
74
|
+
protected _userId?: string;
|
|
75
|
+
|
|
76
|
+
constructor(apiKey: string, options?: ReactNativeOptions) {
|
|
77
|
+
const defaultConfig = getDefaultConfig();
|
|
78
|
+
super({
|
|
79
|
+
flushIntervalMillis: 1000,
|
|
80
|
+
flushMaxRetries: 5,
|
|
81
|
+
flushQueueSize: 30,
|
|
82
|
+
transportProvider: defaultConfig.transportProvider,
|
|
83
|
+
...options,
|
|
84
|
+
apiKey,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// NOTE: Define `cookieStorage` first to persist user session
|
|
88
|
+
// user session properties expect `cookieStorage` to be defined
|
|
89
|
+
this.cookieStorage = options?.cookieStorage ?? defaultConfig.cookieStorage;
|
|
90
|
+
this.deviceId = options?.deviceId;
|
|
91
|
+
this.lastEventTime = options?.lastEventTime;
|
|
92
|
+
this.optOut = Boolean(options?.optOut);
|
|
93
|
+
this.sessionId = options?.sessionId;
|
|
94
|
+
this.userId = options?.userId;
|
|
95
|
+
|
|
96
|
+
this.appVersion = options?.appVersion;
|
|
97
|
+
this.cookieExpiration =
|
|
98
|
+
options?.cookieExpiration ?? defaultConfig.cookieExpiration;
|
|
99
|
+
this.cookieSameSite =
|
|
100
|
+
options?.cookieSameSite ?? defaultConfig.cookieSameSite;
|
|
101
|
+
this.cookieSecure = options?.cookieSecure ?? defaultConfig.cookieSecure;
|
|
102
|
+
this.cookieUpgrade = options?.cookieUpgrade ?? defaultConfig.cookieUpgrade;
|
|
103
|
+
this.disableCookies =
|
|
104
|
+
options?.disableCookies ?? defaultConfig.disableCookies;
|
|
105
|
+
this.domain = options?.domain ?? defaultConfig.domain;
|
|
106
|
+
this.partnerId = options?.partnerId;
|
|
107
|
+
this.sessionTimeout =
|
|
108
|
+
options?.sessionTimeout ?? defaultConfig.sessionTimeout;
|
|
109
|
+
this.trackingOptions =
|
|
110
|
+
options?.trackingOptions ?? defaultConfig.trackingOptions;
|
|
111
|
+
this.trackingSessionEvents =
|
|
112
|
+
options?.trackingSessionEvents ?? defaultConfig.trackingSessionEvents;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
get deviceId() {
|
|
116
|
+
return this._deviceId;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
set deviceId(deviceId: string | undefined) {
|
|
120
|
+
if (this._deviceId !== deviceId) {
|
|
121
|
+
this._deviceId = deviceId;
|
|
122
|
+
this.updateStorage();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get userId() {
|
|
127
|
+
return this._userId;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
set userId(userId: string | undefined) {
|
|
131
|
+
if (this._userId !== userId) {
|
|
132
|
+
this._userId = userId;
|
|
133
|
+
this.updateStorage();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
get sessionId() {
|
|
138
|
+
return this._sessionId;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
set sessionId(sessionId: number | undefined) {
|
|
142
|
+
if (this._sessionId !== sessionId) {
|
|
143
|
+
this._sessionId = sessionId;
|
|
144
|
+
this.updateStorage();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
get optOut() {
|
|
149
|
+
return this._optOut;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
set optOut(optOut: boolean) {
|
|
153
|
+
if (this._optOut !== optOut) {
|
|
154
|
+
this._optOut = optOut;
|
|
155
|
+
this.updateStorage();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
get lastEventTime() {
|
|
160
|
+
return this._lastEventTime;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
set lastEventTime(lastEventTime: number | undefined) {
|
|
164
|
+
if (this._lastEventTime !== lastEventTime) {
|
|
165
|
+
this._lastEventTime = lastEventTime;
|
|
166
|
+
this.updateStorage();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
get lastEventId() {
|
|
171
|
+
return this._lastEventId;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
set lastEventId(lastEventId: number | undefined) {
|
|
175
|
+
if (this._lastEventId !== lastEventId) {
|
|
176
|
+
this._lastEventId = lastEventId;
|
|
177
|
+
this.updateStorage();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private updateStorage() {
|
|
182
|
+
const cache = {
|
|
183
|
+
deviceId: this._deviceId,
|
|
184
|
+
userId: this._userId,
|
|
185
|
+
sessionId: this._sessionId,
|
|
186
|
+
optOut: this._optOut,
|
|
187
|
+
lastEventTime: this._lastEventTime,
|
|
188
|
+
lastEventId: this._lastEventId,
|
|
189
|
+
};
|
|
190
|
+
try {
|
|
191
|
+
void this.cookieStorage
|
|
192
|
+
?.set(getCookieName(this.apiKey), cache)
|
|
193
|
+
.catch((error) => {
|
|
194
|
+
this.loggerProvider?.error(
|
|
195
|
+
`Failed to persist user session: ${String(error)}`,
|
|
196
|
+
);
|
|
197
|
+
});
|
|
198
|
+
} catch (error) {
|
|
199
|
+
this.loggerProvider?.error(
|
|
200
|
+
`Failed to persist user session: ${String(error)}`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export const useReactNativeConfig = async (
|
|
207
|
+
apiKey: string,
|
|
208
|
+
options?: ReactNativeOptions,
|
|
209
|
+
): Promise<IReactNativeConfig> => {
|
|
210
|
+
const defaultConfig = getDefaultConfig();
|
|
211
|
+
|
|
212
|
+
// create cookie storage
|
|
213
|
+
const disableCookies =
|
|
214
|
+
options?.disableCookies ?? defaultConfig.disableCookies;
|
|
215
|
+
const domain = disableCookies
|
|
216
|
+
? ""
|
|
217
|
+
: (options?.domain ?? (await getTopLevelDomain()));
|
|
218
|
+
const cookieStorage = await createCookieStorage<UserSession>({
|
|
219
|
+
...options,
|
|
220
|
+
disableCookies,
|
|
221
|
+
domain,
|
|
222
|
+
});
|
|
223
|
+
const previousCookies = await cookieStorage.get(getCookieName(apiKey));
|
|
224
|
+
const queryParams = getQueryParams();
|
|
225
|
+
|
|
226
|
+
// reconcile user session
|
|
227
|
+
let deviceId =
|
|
228
|
+
options?.deviceId ?? queryParams.deviceId ?? previousCookies?.deviceId;
|
|
229
|
+
let lastEventTime = options?.lastEventTime ?? previousCookies?.lastEventTime;
|
|
230
|
+
const optOut = options?.optOut ?? Boolean(previousCookies?.optOut);
|
|
231
|
+
let sessionId = options?.sessionId ?? previousCookies?.sessionId;
|
|
232
|
+
let userId = options?.userId ?? previousCookies?.userId;
|
|
233
|
+
let lastEventId = previousCookies?.lastEventId;
|
|
234
|
+
|
|
235
|
+
const storageProvider =
|
|
236
|
+
options?.storageProvider ?? (await createEventsStorage(options));
|
|
237
|
+
|
|
238
|
+
if (options?.migrateLegacyData !== false) {
|
|
239
|
+
const legacySessionData = await new RemnantDataMigration(
|
|
240
|
+
apiKey,
|
|
241
|
+
options?.instanceName,
|
|
242
|
+
storageProvider,
|
|
243
|
+
previousCookies?.lastEventTime === undefined,
|
|
244
|
+
options?.loggerProvider,
|
|
245
|
+
).execute();
|
|
246
|
+
deviceId = deviceId ?? legacySessionData.deviceId;
|
|
247
|
+
userId = userId ?? legacySessionData.userId;
|
|
248
|
+
sessionId = sessionId ?? legacySessionData.sessionId;
|
|
249
|
+
lastEventTime = lastEventTime ?? legacySessionData.lastEventTime;
|
|
250
|
+
lastEventId = lastEventId ?? legacySessionData.lastEventId;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const config = new ReactNativeConfig(apiKey, {
|
|
254
|
+
...options,
|
|
255
|
+
cookieStorage,
|
|
256
|
+
deviceId: deviceId ?? UUID(),
|
|
257
|
+
domain,
|
|
258
|
+
lastEventTime,
|
|
259
|
+
optOut,
|
|
260
|
+
sessionId,
|
|
261
|
+
storageProvider,
|
|
262
|
+
trackingOptions: {
|
|
263
|
+
...defaultConfig.trackingOptions,
|
|
264
|
+
...options?.trackingOptions,
|
|
265
|
+
},
|
|
266
|
+
transportProvider: options?.transportProvider ?? new FetchTransport(),
|
|
267
|
+
userId,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
config.lastEventId = lastEventId;
|
|
271
|
+
|
|
272
|
+
config.loggerProvider?.log(
|
|
273
|
+
`Init: storage=${cookieStorage.constructor.name} restoredSessionId = ${
|
|
274
|
+
previousCookies?.sessionId ?? "undefined"
|
|
275
|
+
}, optionsSessionId = ${options?.sessionId ?? "undefined"}`,
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
return config;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
export const createCookieStorage = async <T>(
|
|
282
|
+
overrides?: ReactNativeOptions,
|
|
283
|
+
baseConfig = getDefaultConfig(),
|
|
284
|
+
): Promise<Storage<T>> => {
|
|
285
|
+
const options = { ...baseConfig, ...overrides };
|
|
286
|
+
const cookieStorage = overrides?.cookieStorage as Storage<T>;
|
|
287
|
+
if (!cookieStorage || !(await cookieStorage.isEnabled())) {
|
|
288
|
+
return createFlexibleStorage<T>(options);
|
|
289
|
+
}
|
|
290
|
+
return cookieStorage;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const createFlexibleStorage = async <T>(
|
|
294
|
+
options: ReactNativeOptions,
|
|
295
|
+
): Promise<Storage<T>> => {
|
|
296
|
+
let storage: Storage<T>;
|
|
297
|
+
if (options.disableCookies) {
|
|
298
|
+
storage = new LocalStorage();
|
|
299
|
+
if (!(await storage.isEnabled())) {
|
|
300
|
+
storage = new MemoryStorage();
|
|
301
|
+
}
|
|
302
|
+
return storage;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
storage = new CookieStorage({
|
|
306
|
+
domain: options.domain,
|
|
307
|
+
expirationDays: options.cookieExpiration,
|
|
308
|
+
sameSite: options.cookieSameSite,
|
|
309
|
+
secure: options.cookieSecure,
|
|
310
|
+
});
|
|
311
|
+
if (!(await storage.isEnabled())) {
|
|
312
|
+
storage = new LocalStorage();
|
|
313
|
+
if (!(await storage.isEnabled())) {
|
|
314
|
+
storage = new MemoryStorage();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return storage;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
export const createEventsStorage = async (
|
|
321
|
+
overrides?: ReactNativeOptions,
|
|
322
|
+
): Promise<Storage<Event[]> | undefined> => {
|
|
323
|
+
const hasStorageProviderProperty =
|
|
324
|
+
overrides &&
|
|
325
|
+
Object.prototype.hasOwnProperty.call(overrides, "storageProvider");
|
|
326
|
+
// If storageProperty is explicitly undefined like `{ storageProperty: undefined }`
|
|
327
|
+
// then storageProvider is undefined
|
|
328
|
+
// If storageProvider is implicitly undefined like `{ }`
|
|
329
|
+
// then storageProvider uses the built-in memory storage
|
|
330
|
+
// Otherwise storageProvider is overriden
|
|
331
|
+
if (!hasStorageProviderProperty || overrides.storageProvider) {
|
|
332
|
+
for (const storage of [
|
|
333
|
+
overrides?.storageProvider,
|
|
334
|
+
new LocalStorage<Event[]>(),
|
|
335
|
+
]) {
|
|
336
|
+
if (storage && (await storage.isEnabled())) {
|
|
337
|
+
return storage;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return undefined;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export const getTopLevelDomain = async (url?: string) => {
|
|
345
|
+
if (
|
|
346
|
+
!(await new CookieStorage<number>().isEnabled()) ||
|
|
347
|
+
(!url && (typeof location === "undefined" || !location.hostname))
|
|
348
|
+
) {
|
|
349
|
+
return "";
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const host = url ?? location.hostname;
|
|
353
|
+
const parts = host.split(".");
|
|
354
|
+
const levels = [];
|
|
355
|
+
const storageKey = "AMP_TLDTEST";
|
|
356
|
+
|
|
357
|
+
for (let i = parts.length - 2; i >= 0; --i) {
|
|
358
|
+
levels.push(parts.slice(i).join("."));
|
|
359
|
+
}
|
|
360
|
+
for (let i = 0; i < levels.length; i++) {
|
|
361
|
+
const domain = levels[i];
|
|
362
|
+
const options = { domain: "." + domain };
|
|
363
|
+
const storage = new CookieStorage<number>(options);
|
|
364
|
+
await storage.set(storageKey, 1);
|
|
365
|
+
const value = await storage.get(storageKey);
|
|
366
|
+
if (value) {
|
|
367
|
+
await storage.remove(storageKey);
|
|
368
|
+
return "." + domain;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return "";
|
|
373
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UserSession,
|
|
3
|
+
ReactNativeOptions,
|
|
4
|
+
getOldCookieName,
|
|
5
|
+
} from "@amplitude/analytics-core";
|
|
6
|
+
import {
|
|
7
|
+
createCookieStorage,
|
|
8
|
+
getDefaultConfig,
|
|
9
|
+
getTopLevelDomain,
|
|
10
|
+
} from "../config";
|
|
11
|
+
|
|
12
|
+
export const parseOldCookies = async (
|
|
13
|
+
apiKey: string,
|
|
14
|
+
options?: ReactNativeOptions,
|
|
15
|
+
): Promise<UserSession> => {
|
|
16
|
+
const disableCookies =
|
|
17
|
+
options?.disableCookies ?? getDefaultConfig().disableCookies;
|
|
18
|
+
const storage = await createCookieStorage<string>({
|
|
19
|
+
...options,
|
|
20
|
+
disableCookies,
|
|
21
|
+
domain: disableCookies
|
|
22
|
+
? ""
|
|
23
|
+
: (options?.domain ?? (await getTopLevelDomain())),
|
|
24
|
+
});
|
|
25
|
+
const oldCookieName = getOldCookieName(apiKey);
|
|
26
|
+
const cookies = await storage.getRaw(oldCookieName);
|
|
27
|
+
|
|
28
|
+
if (!cookies) {
|
|
29
|
+
return {
|
|
30
|
+
optOut: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (options?.cookieUpgrade ?? getDefaultConfig().cookieUpgrade) {
|
|
35
|
+
await storage.remove(oldCookieName);
|
|
36
|
+
}
|
|
37
|
+
const [deviceId, userId, optOut, sessionId, lastEventTime] =
|
|
38
|
+
cookies.split(".");
|
|
39
|
+
return {
|
|
40
|
+
deviceId,
|
|
41
|
+
userId: decode(userId ?? ""),
|
|
42
|
+
sessionId: parseTime(sessionId),
|
|
43
|
+
lastEventTime: parseTime(lastEventTime),
|
|
44
|
+
optOut: parseOptOut(optOut),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const parseTime = (num: string) => {
|
|
49
|
+
const integer = parseInt(num, 32);
|
|
50
|
+
if (isNaN(integer)) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return integer;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const decode = (value?: string): string | undefined => {
|
|
57
|
+
if (typeof atob !== "function" || typeof escape !== "function" || !value) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
return decodeURIComponent(escape(atob(value)));
|
|
62
|
+
} catch {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const parseOptOut = (value?: string): boolean => {
|
|
68
|
+
return value === "1" || value === "true";
|
|
69
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import client from "./react-native-client";
|
|
2
|
+
|
|
3
|
+
// Export types to maintain backward compatibility with `analytics-types`.
|
|
4
|
+
// In the next major version, only export customer-facing types to reduce the public API surface.
|
|
5
|
+
import * as Types from "./types";
|
|
6
|
+
export { createInstance } from "./react-native-client";
|
|
7
|
+
export const {
|
|
8
|
+
add,
|
|
9
|
+
flush,
|
|
10
|
+
getDeviceId,
|
|
11
|
+
getSessionId,
|
|
12
|
+
getUserId,
|
|
13
|
+
groupIdentify,
|
|
14
|
+
identify,
|
|
15
|
+
init,
|
|
16
|
+
logEvent,
|
|
17
|
+
remove,
|
|
18
|
+
reset,
|
|
19
|
+
revenue,
|
|
20
|
+
setDeviceId,
|
|
21
|
+
setGroup,
|
|
22
|
+
setOptOut,
|
|
23
|
+
setSessionId,
|
|
24
|
+
setUserId,
|
|
25
|
+
shutdown,
|
|
26
|
+
track,
|
|
27
|
+
extendSession,
|
|
28
|
+
} = client;
|
|
29
|
+
|
|
30
|
+
export { Revenue, Identify } from "@amplitude/analytics-core";
|
|
31
|
+
export {
|
|
32
|
+
InMemoryStorage,
|
|
33
|
+
LocalStorage,
|
|
34
|
+
MemoryStorage,
|
|
35
|
+
} from "./storage/local-storage";
|
|
36
|
+
export { Types };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Event,
|
|
3
|
+
ILogger,
|
|
4
|
+
STORAGE_PREFIX,
|
|
5
|
+
Storage,
|
|
6
|
+
UserSession,
|
|
7
|
+
} from "@amplitude/analytics-core";
|
|
8
|
+
import {
|
|
9
|
+
getLegacyEvents,
|
|
10
|
+
getLegacySessionData,
|
|
11
|
+
removeLegacyEvent,
|
|
12
|
+
} from "../../native/context";
|
|
13
|
+
|
|
14
|
+
type LegacyEventKind = "event" | "identify" | "interceptedIdentify";
|
|
15
|
+
|
|
16
|
+
export default class RemnantDataMigration {
|
|
17
|
+
eventsStorageKey: string;
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
private readonly apiKey: string,
|
|
21
|
+
private readonly instanceName: string | undefined,
|
|
22
|
+
private readonly storage: Storage<Event[]> | undefined,
|
|
23
|
+
private readonly firstRunSinceUpgrade: boolean,
|
|
24
|
+
private readonly logger: ILogger | undefined,
|
|
25
|
+
) {
|
|
26
|
+
this.eventsStorageKey = `${STORAGE_PREFIX}_${this.apiKey.substring(0, 10)}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async execute(): Promise<Omit<UserSession, "optOut">> {
|
|
30
|
+
if (this.firstRunSinceUpgrade) {
|
|
31
|
+
await this.moveIdentifies();
|
|
32
|
+
await this.moveInterceptedIdentifies();
|
|
33
|
+
}
|
|
34
|
+
await this.moveEvents();
|
|
35
|
+
|
|
36
|
+
return this.callNativeFunction(() =>
|
|
37
|
+
Promise.resolve(getLegacySessionData(this.instanceName ?? "")),
|
|
38
|
+
).then((sessionData) => sessionData ?? {});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private async moveEvents() {
|
|
42
|
+
await this.moveLegacyEvents("event");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private async moveIdentifies() {
|
|
46
|
+
await this.moveLegacyEvents("identify");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private async moveInterceptedIdentifies() {
|
|
50
|
+
await this.moveLegacyEvents("interceptedIdentify");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private async callNativeFunction<T>(
|
|
54
|
+
action: () => Promise<T>,
|
|
55
|
+
): Promise<T | undefined> {
|
|
56
|
+
try {
|
|
57
|
+
return await action();
|
|
58
|
+
} catch (e) {
|
|
59
|
+
this.logger?.error(`can't call native function: ${String(e)}`);
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private callNativeAction(action: () => void) {
|
|
65
|
+
try {
|
|
66
|
+
action();
|
|
67
|
+
} catch (e) {
|
|
68
|
+
this.logger?.error(`can't call native function: ${String(e)}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private async callStorageFunction<T>(
|
|
73
|
+
action: () => Promise<T>,
|
|
74
|
+
): Promise<{ value: T } | undefined> {
|
|
75
|
+
try {
|
|
76
|
+
return { value: await action() };
|
|
77
|
+
} catch (e) {
|
|
78
|
+
this.logger?.error(`can't call storage function: ${String(e)}`);
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private async moveLegacyEvents(eventKind: LegacyEventKind) {
|
|
84
|
+
const legacyJsonEvents = await this.callNativeFunction(() =>
|
|
85
|
+
Promise.resolve(getLegacyEvents(this.instanceName ?? "", eventKind)),
|
|
86
|
+
);
|
|
87
|
+
if (!this.storage || !legacyJsonEvents || legacyJsonEvents.length === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const existingEvents = await this.callStorageFunction<Event[] | undefined>(
|
|
92
|
+
async () => {
|
|
93
|
+
return this.storage?.get(this.eventsStorageKey);
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
if (!existingEvents) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const events: Event[] = existingEvents.value ?? [];
|
|
100
|
+
const eventIds: number[] = [];
|
|
101
|
+
|
|
102
|
+
legacyJsonEvents.forEach((jsonEvent) => {
|
|
103
|
+
const event = this.convertLegacyEvent(jsonEvent);
|
|
104
|
+
if (event) {
|
|
105
|
+
events.push(event);
|
|
106
|
+
if (event.event_id !== undefined) {
|
|
107
|
+
eventIds.push(event.event_id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const writeSucceeded = await this.callStorageFunction(async () => {
|
|
113
|
+
await this.storage?.set(this.eventsStorageKey, events);
|
|
114
|
+
return true;
|
|
115
|
+
});
|
|
116
|
+
if (!writeSucceeded?.value) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
eventIds.forEach((eventId) =>
|
|
120
|
+
this.callNativeAction(() =>
|
|
121
|
+
removeLegacyEvent(this.instanceName ?? "", eventKind, eventId),
|
|
122
|
+
),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private convertLegacyEvent(legacyJsonEvent: string): Event | null {
|
|
127
|
+
try {
|
|
128
|
+
const event = JSON.parse(legacyJsonEvent) as Event;
|
|
129
|
+
|
|
130
|
+
const { library, timestamp, uuid, api_properties } = event as any;
|
|
131
|
+
if (library !== undefined) {
|
|
132
|
+
event.library = `${library.name}/${library.version}`;
|
|
133
|
+
}
|
|
134
|
+
if (timestamp !== undefined) {
|
|
135
|
+
event.time = timestamp;
|
|
136
|
+
}
|
|
137
|
+
if (uuid !== undefined) {
|
|
138
|
+
event.insert_id = uuid;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (api_properties) {
|
|
142
|
+
const {
|
|
143
|
+
androidADID,
|
|
144
|
+
android_app_set_id,
|
|
145
|
+
ios_idfa,
|
|
146
|
+
ios_idfv,
|
|
147
|
+
productId,
|
|
148
|
+
quantity,
|
|
149
|
+
price,
|
|
150
|
+
location,
|
|
151
|
+
} = api_properties;
|
|
152
|
+
if (androidADID !== undefined) {
|
|
153
|
+
event.adid = androidADID;
|
|
154
|
+
}
|
|
155
|
+
if (android_app_set_id !== undefined) {
|
|
156
|
+
event.android_app_set_id = android_app_set_id;
|
|
157
|
+
}
|
|
158
|
+
if (ios_idfa !== undefined) {
|
|
159
|
+
event.idfa = ios_idfa;
|
|
160
|
+
}
|
|
161
|
+
if (ios_idfv !== undefined) {
|
|
162
|
+
event.idfv = ios_idfv;
|
|
163
|
+
}
|
|
164
|
+
if (productId !== undefined) {
|
|
165
|
+
event.productId = productId;
|
|
166
|
+
}
|
|
167
|
+
if (quantity !== undefined) {
|
|
168
|
+
event.quantity = quantity;
|
|
169
|
+
}
|
|
170
|
+
if (price !== undefined) {
|
|
171
|
+
event.price = price;
|
|
172
|
+
}
|
|
173
|
+
if (location !== undefined) {
|
|
174
|
+
const { lat, lng } = location;
|
|
175
|
+
event.location_lat = lat;
|
|
176
|
+
event.location_lng = lng;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const {
|
|
181
|
+
$productId: productId,
|
|
182
|
+
$quantity: quantity,
|
|
183
|
+
$price: price,
|
|
184
|
+
$revenueType: revenueType,
|
|
185
|
+
} = event as any;
|
|
186
|
+
if (productId !== undefined) {
|
|
187
|
+
event.productId = productId;
|
|
188
|
+
}
|
|
189
|
+
if (quantity !== undefined) {
|
|
190
|
+
event.quantity = quantity;
|
|
191
|
+
}
|
|
192
|
+
if (price !== undefined) {
|
|
193
|
+
event.price = price;
|
|
194
|
+
}
|
|
195
|
+
if (revenueType !== undefined) {
|
|
196
|
+
event.revenueType = revenueType;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return event;
|
|
200
|
+
} catch {
|
|
201
|
+
// skip invalid events
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
206
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BaseTransport } from "@amplitude/analytics-core";
|
|
2
|
+
import type { Payload, Response, Transport } from "@amplitude/analytics-core";
|
|
3
|
+
import { nitroHttpClient } from "../native/http";
|
|
4
|
+
|
|
5
|
+
export class NitroTransport extends BaseTransport implements Transport {
|
|
6
|
+
private readonly customHeaders: Record<string, string>;
|
|
7
|
+
|
|
8
|
+
constructor(customHeaders: Record<string, string> = {}) {
|
|
9
|
+
super();
|
|
10
|
+
this.customHeaders = customHeaders;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async send(serverUrl: string, payload: Payload): Promise<Response | null> {
|
|
14
|
+
const response = await nitroHttpClient.request(
|
|
15
|
+
serverUrl,
|
|
16
|
+
"POST",
|
|
17
|
+
{
|
|
18
|
+
"Content-Type": "application/json",
|
|
19
|
+
Accept: "*/*",
|
|
20
|
+
...this.customHeaders,
|
|
21
|
+
},
|
|
22
|
+
JSON.stringify(payload),
|
|
23
|
+
30000,
|
|
24
|
+
);
|
|
25
|
+
try {
|
|
26
|
+
return this.buildResponse(
|
|
27
|
+
JSON.parse(response.body) as Record<string, unknown>,
|
|
28
|
+
);
|
|
29
|
+
} catch {
|
|
30
|
+
return this.buildResponse({ code: response.status });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const nitroTransport = new NitroTransport();
|