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,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 @@
|
|
|
1
|
+
export const VERSION = "1.6.0";
|