@jmartins-tillster/analytics-react-native 2.21.3
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/.editorconfig +10 -0
- package/.eslintignore +11 -0
- package/.eslintrc.js +60 -0
- package/.gitattributes +4 -0
- package/.github/ISSUE_TEMPLATE/BUG_REPORT.md +23 -0
- package/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +18 -0
- package/.github/workflows/ci.yml +158 -0
- package/.github/workflows/create_jira.yml +41 -0
- package/.github/workflows/publish.yml +57 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.prettierrc.js +7 -0
- package/.yarnrc.yml +2 -0
- package/CODE_OF_CONDUCT.md +84 -0
- package/CONTRIBUTING.md +141 -0
- package/LICENSE +21 -0
- package/MIGRATION_GUIDE.md +185 -0
- package/README.md +944 -0
- package/babel.config.js +3 -0
- package/commitlint.config.js +13 -0
- package/examples/AnalyticsReactNativeExample/.bundle/config +2 -0
- package/examples/AnalyticsReactNativeExample/.eslintrc.js +4 -0
- package/examples/AnalyticsReactNativeExample/.prettierrc.js +7 -0
- package/examples/AnalyticsReactNativeExample/.watchmanconfig +1 -0
- package/examples/AnalyticsReactNativeExample/App.tsx +164 -0
- package/examples/AnalyticsReactNativeExample/Gemfile +9 -0
- package/examples/AnalyticsReactNativeExample/Gemfile.lock +106 -0
- package/examples/AnalyticsReactNativeExample/Home.tsx +206 -0
- package/examples/AnalyticsReactNativeExample/Modal.tsx +25 -0
- package/examples/AnalyticsReactNativeExample/README.md +79 -0
- package/examples/AnalyticsReactNativeExample/SecondPage.tsx +25 -0
- package/examples/AnalyticsReactNativeExample/android/app/build.gradle +119 -0
- package/examples/AnalyticsReactNativeExample/android/app/debug.keystore +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/proguard-rules.pro +10 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/debug/AndroidManifest.xml +9 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/AndroidManifest.xml +26 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/java/com/analyticsreactnativeexample/MainActivity.kt +22 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/java/com/analyticsreactnativeexample/MainApplication.kt +44 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/drawable/rn_edit_text_material.xml +37 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/values/strings.xml +3 -0
- package/examples/AnalyticsReactNativeExample/android/app/src/main/res/values/styles.xml +9 -0
- package/examples/AnalyticsReactNativeExample/android/build.gradle +21 -0
- package/examples/AnalyticsReactNativeExample/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/examples/AnalyticsReactNativeExample/android/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/examples/AnalyticsReactNativeExample/android/gradle.properties +39 -0
- package/examples/AnalyticsReactNativeExample/android/gradlew +252 -0
- package/examples/AnalyticsReactNativeExample/android/gradlew.bat +94 -0
- package/examples/AnalyticsReactNativeExample/android/settings.gradle +6 -0
- package/examples/AnalyticsReactNativeExample/app.json +4 -0
- package/examples/AnalyticsReactNativeExample/babel.config.js +3 -0
- package/examples/AnalyticsReactNativeExample/index.js +9 -0
- package/examples/AnalyticsReactNativeExample/ios/.xcode.env +11 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/AppDelegate.h +6 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/AppDelegate.mm +31 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/Images.xcassets/Contents.json +6 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/Info.plist +52 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/LaunchScreen.storyboard +47 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/PrivacyInfo.xcprivacy +37 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample/main.m +10 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample.xcodeproj/project.pbxproj +705 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample.xcodeproj/xcshareddata/xcschemes/AnalyticsReactNativeExample.xcscheme +88 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample.xcworkspace/contents.xcworkspacedata +10 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExampleTests/AnalyticsReactNativeExampleTests.m +66 -0
- package/examples/AnalyticsReactNativeExample/ios/AnalyticsReactNativeExampleTests/Info.plist +24 -0
- package/examples/AnalyticsReactNativeExample/ios/Podfile +40 -0
- package/examples/AnalyticsReactNativeExample/ios/Podfile.lock +1961 -0
- package/examples/AnalyticsReactNativeExample/metro.config.js +11 -0
- package/examples/AnalyticsReactNativeExample/package.json +55 -0
- package/examples/AnalyticsReactNativeExample/plugins/ConsentManager.tsx +75 -0
- package/examples/AnalyticsReactNativeExample/plugins/Logger.ts +16 -0
- package/examples/AnalyticsReactNativeExample/react-native.config.js +9 -0
- package/examples/AnalyticsReactNativeExample/tsconfig.json +3 -0
- package/examples/AnalyticsReactNativeExample/workspace.js +5 -0
- package/examples/AnalyticsReactNativeExample/yarn.lock +11110 -0
- package/examples/E2E/.bundle/config +2 -0
- package/examples/E2E/.detoxrc.js +96 -0
- package/examples/E2E/.mise.toml +5 -0
- package/examples/E2E/.prettierrc.js +7 -0
- package/examples/E2E/.watchmanconfig +1 -0
- package/examples/E2E/App.tsx +176 -0
- package/examples/E2E/Gemfile +7 -0
- package/examples/E2E/Gemfile.lock +101 -0
- package/examples/E2E/Home.tsx +206 -0
- package/examples/E2E/Modal.tsx +25 -0
- package/examples/E2E/README.md +79 -0
- package/examples/E2E/SecondPage.tsx +25 -0
- package/examples/E2E/android/app/build.gradle +128 -0
- package/examples/E2E/android/app/debug.keystore +0 -0
- package/examples/E2E/android/app/proguard-rules.pro +10 -0
- package/examples/E2E/android/app/src/androidTest/java/com/segmentanalyticsreactnativeexample/DetoxTest.java +29 -0
- package/examples/E2E/android/app/src/debug/AndroidManifest.xml +13 -0
- package/examples/E2E/android/app/src/debug/java/com/analyticsreactnativeexample/ReactNativeFlipper.java +75 -0
- package/examples/E2E/android/app/src/main/AndroidManifest.xml +26 -0
- package/examples/E2E/android/app/src/main/java/com/analyticsreactnativeexample/MainActivity.java +32 -0
- package/examples/E2E/android/app/src/main/java/com/analyticsreactnativeexample/MainApplication.java +62 -0
- package/examples/E2E/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
- package/examples/E2E/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/examples/E2E/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E/android/app/src/main/res/values/strings.xml +3 -0
- package/examples/E2E/android/app/src/main/res/values/styles.xml +9 -0
- package/examples/E2E/android/app/src/main/res/xml/network_security_config.xml +7 -0
- package/examples/E2E/android/app/src/release/java/com/analyticsreactnativeexample/ReactNativeFlipper.java +20 -0
- package/examples/E2E/android/build.gradle +37 -0
- package/examples/E2E/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/examples/E2E/android/gradle/wrapper/gradle-wrapper.properties +6 -0
- package/examples/E2E/android/gradle.properties +44 -0
- package/examples/E2E/android/gradlew +244 -0
- package/examples/E2E/android/gradlew.bat +92 -0
- package/examples/E2E/android/settings.gradle +4 -0
- package/examples/E2E/app.json +4 -0
- package/examples/E2E/babel.config.js +14 -0
- package/examples/E2E/e2e/jest.config.js +13 -0
- package/examples/E2E/e2e/main.e2e.js +192 -0
- package/examples/E2E/e2e/matchers.js +34 -0
- package/examples/E2E/e2e/mockServer.js +56 -0
- package/examples/E2E/index.js +11 -0
- package/examples/E2E/ios/.xcode.env +11 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/AppDelegate.h +6 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/AppDelegate.mm +26 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/Images.xcassets/Contents.json +6 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/Info.plist +55 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/LaunchScreen.storyboard +47 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E/main.m +10 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E.xcodeproj/project.pbxproj +721 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E.xcworkspace/contents.xcworkspacedata +10 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2E.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2ETests/AnalyticsReactNativeExampleTests.m +66 -0
- package/examples/E2E/ios/AnalyticsReactNativeE2ETests/Info.plist +24 -0
- package/examples/E2E/ios/Podfile +62 -0
- package/examples/E2E/ios/Podfile.lock +763 -0
- package/examples/E2E/jest.config.js +3 -0
- package/examples/E2E/metro.config.js +45 -0
- package/examples/E2E/package.json +65 -0
- package/examples/E2E/plugins/Logger.ts +16 -0
- package/examples/E2E/react-native.config.js +7 -0
- package/examples/E2E/workspace.js +5 -0
- package/examples/E2E/yarn.lock +10898 -0
- package/examples/E2E-73/.bundle/config +2 -0
- package/examples/E2E-73/.detoxrc.js +96 -0
- package/examples/E2E-73/.eslintrc.js +4 -0
- package/examples/E2E-73/.mise.toml +5 -0
- package/examples/E2E-73/.prettierrc.js +7 -0
- package/examples/E2E-73/.watchmanconfig +1 -0
- package/examples/E2E-73/App.tsx +175 -0
- package/examples/E2E-73/Gemfile +7 -0
- package/examples/E2E-73/Gemfile.lock +99 -0
- package/examples/E2E-73/Home.tsx +206 -0
- package/examples/E2E-73/Modal.tsx +25 -0
- package/examples/E2E-73/README.md +79 -0
- package/examples/E2E-73/SecondPage.tsx +25 -0
- package/examples/E2E-73/android/app/build.gradle +119 -0
- package/examples/E2E-73/android/app/debug.keystore +0 -0
- package/examples/E2E-73/android/app/proguard-rules.pro +10 -0
- package/examples/E2E-73/android/app/src/debug/AndroidManifest.xml +9 -0
- package/examples/E2E-73/android/app/src/main/AndroidManifest.xml +25 -0
- package/examples/E2E-73/android/app/src/main/java/com/analyticsreactnativee2e73/MainActivity.kt +22 -0
- package/examples/E2E-73/android/app/src/main/java/com/analyticsreactnativee2e73/MainApplication.kt +45 -0
- package/examples/E2E-73/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/examples/E2E-73/android/app/src/main/res/values/strings.xml +3 -0
- package/examples/E2E-73/android/app/src/main/res/values/styles.xml +9 -0
- package/examples/E2E-73/android/build.gradle +21 -0
- package/examples/E2E-73/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/examples/E2E-73/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/examples/E2E-73/android/gradle.properties +41 -0
- package/examples/E2E-73/android/gradlew +249 -0
- package/examples/E2E-73/android/gradlew.bat +92 -0
- package/examples/E2E-73/android/settings.gradle +4 -0
- package/examples/E2E-73/app.json +4 -0
- package/examples/E2E-73/babel.config.js +14 -0
- package/examples/E2E-73/e2e/jest.config.js +13 -0
- package/examples/E2E-73/e2e/main.e2e.js +192 -0
- package/examples/E2E-73/e2e/matchers.js +34 -0
- package/examples/E2E-73/e2e/mockServer.js +56 -0
- package/examples/E2E-73/index.js +9 -0
- package/examples/E2E-73/ios/.xcode.env +11 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/AppDelegate.h +6 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/AppDelegate.mm +31 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/Images.xcassets/Contents.json +6 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/Info.plist +51 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/LaunchScreen.storyboard +47 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73/main.m +10 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73.xcodeproj/project.pbxproj +700 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73.xcodeproj/xcshareddata/xcschemes/AnalyticsReactNativeE2E73.xcscheme +88 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73.xcworkspace/contents.xcworkspacedata +10 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73Tests/AnalyticsReactNativeE2E73Tests.m +66 -0
- package/examples/E2E-73/ios/AnalyticsReactNativeE2E73Tests/Info.plist +24 -0
- package/examples/E2E-73/ios/Podfile +55 -0
- package/examples/E2E-73/ios/Podfile.lock +1425 -0
- package/examples/E2E-73/jest.config.js +3 -0
- package/examples/E2E-73/metro.config.js +45 -0
- package/examples/E2E-73/package.json +62 -0
- package/examples/E2E-73/plugins/Logger.ts +16 -0
- package/examples/E2E-73/react-native.config.js +12 -0
- package/examples/E2E-73/tsconfig.json +3 -0
- package/examples/E2E-73/workspace.js +5 -0
- package/examples/E2E-73/yarn.lock +10789 -0
- package/examples/README.md +142 -0
- package/examples/linkHelper.js +45 -0
- package/jest.config.js +7 -0
- package/multi-release.config.js +7 -0
- package/package.json +79 -0
- package/packages/core/CHANGELOG.md +274 -0
- package/packages/core/LICENSE +21 -0
- package/packages/core/README.md +3 -0
- package/packages/core/android/build.gradle +96 -0
- package/packages/core/android/gradle.properties +5 -0
- package/packages/core/android/src/main/AndroidManifest.xml +4 -0
- package/packages/core/android/src/main/AndroidManifestNew.xml +3 -0
- package/packages/core/android/src/main/java/com/segmentanalyticsreactnative/AnalyticsReactNativeModule.kt +265 -0
- package/packages/core/android/src/main/java/com/segmentanalyticsreactnative/AnalyticsReactNativePackage.kt +43 -0
- package/packages/core/babel.config.js +3 -0
- package/packages/core/constants-generator.js +17 -0
- package/packages/core/ios/AnalyticsReactNative-Bridging-Header.h +1 -0
- package/packages/core/ios/AnalyticsReactNative.m +7 -0
- package/packages/core/ios/AnalyticsReactNative.swift +142 -0
- package/packages/core/ios/AnalyticsReactNative.xcodeproj/project.pbxproj +281 -0
- package/packages/core/ios/PrivacyInfo.xcprivacy +70 -0
- package/packages/core/jest.config.js +5 -0
- package/packages/core/package.json +85 -0
- package/packages/core/release.config.js +3 -0
- package/packages/core/segment-analytics-react-native.podspec +35 -0
- package/packages/core/src/__tests__/__snapshots__/mapTransform.test.ts.snap +20 -0
- package/packages/core/src/__tests__/analytics.test.ts +252 -0
- package/packages/core/src/__tests__/api.test.ts +91 -0
- package/packages/core/src/__tests__/client.test.ts +27 -0
- package/packages/core/src/__tests__/context.test.ts +122 -0
- package/packages/core/src/__tests__/events.test.ts +234 -0
- package/packages/core/src/__tests__/internal/checkInstalledVersion.test.ts +221 -0
- package/packages/core/src/__tests__/internal/fetchSettings.test.ts +438 -0
- package/packages/core/src/__tests__/internal/handleAppStateChange.test.ts +178 -0
- package/packages/core/src/__tests__/internal/trackDeepLinks.test.ts +121 -0
- package/packages/core/src/__tests__/logger.test.ts +83 -0
- package/packages/core/src/__tests__/mapTransform.test.ts +63 -0
- package/packages/core/src/__tests__/methods/alias.test.ts +89 -0
- package/packages/core/src/__tests__/methods/flush.test.ts +120 -0
- package/packages/core/src/__tests__/methods/group.test.ts +48 -0
- package/packages/core/src/__tests__/methods/identify.test.ts +132 -0
- package/packages/core/src/__tests__/methods/process.test.ts +162 -0
- package/packages/core/src/__tests__/methods/screen.test.ts +48 -0
- package/packages/core/src/__tests__/methods/track.test.ts +49 -0
- package/packages/core/src/__tests__/timeline.test.ts +130 -0
- package/packages/core/src/__tests__/util.test.ts +200 -0
- package/packages/core/src/analytics.ts +1030 -0
- package/packages/core/src/api.ts +23 -0
- package/packages/core/src/client.tsx +76 -0
- package/packages/core/src/constants.ts +18 -0
- package/packages/core/src/context.ts +107 -0
- package/packages/core/src/errors.ts +123 -0
- package/packages/core/src/events.ts +75 -0
- package/packages/core/src/flushPolicies/__tests__/background-flush-policy.test.ts +39 -0
- package/packages/core/src/flushPolicies/__tests__/count-flush-policy.test.ts +28 -0
- package/packages/core/src/flushPolicies/__tests__/flush-policy-executer.test.ts +85 -0
- package/packages/core/src/flushPolicies/__tests__/timer-flush-policy.test.ts +30 -0
- package/packages/core/src/flushPolicies/background-flush-policy.ts +21 -0
- package/packages/core/src/flushPolicies/count-flush-policy.ts +31 -0
- package/packages/core/src/flushPolicies/flush-policy-executer.ts +100 -0
- package/packages/core/src/flushPolicies/index.ts +5 -0
- package/packages/core/src/flushPolicies/startup-flush-policy.ts +20 -0
- package/packages/core/src/flushPolicies/timer-flush-policy.ts +45 -0
- package/packages/core/src/flushPolicies/types.ts +93 -0
- package/packages/core/src/index.ts +28 -0
- package/packages/core/src/logger.ts +37 -0
- package/packages/core/src/mapTransform.ts +48 -0
- package/packages/core/src/plugin.ts +212 -0
- package/packages/core/src/plugins/ConsentPlugin.ts +200 -0
- package/packages/core/src/plugins/DestinationMetadataEnrichment.ts +67 -0
- package/packages/core/src/plugins/QueueFlushingPlugin.ts +149 -0
- package/packages/core/src/plugins/SegmentDestination.ts +153 -0
- package/packages/core/src/plugins/__tests__/QueueFlushingPlugin.test.ts +143 -0
- package/packages/core/src/plugins/__tests__/SegmentDestination.test.ts +549 -0
- package/packages/core/src/plugins/__tests__/consent/consentNotEnabledAtSegment.test.ts +123 -0
- package/packages/core/src/plugins/__tests__/consent/destinationMultipleCategories.test.ts +147 -0
- package/packages/core/src/plugins/__tests__/consent/idfa.test.ts +101 -0
- package/packages/core/src/plugins/__tests__/consent/mockSettings/ConsentNotEnabledAtSegment.json +70 -0
- package/packages/core/src/plugins/__tests__/consent/mockSettings/DestinationsMultipleCategories.json +73 -0
- package/packages/core/src/plugins/__tests__/consent/mockSettings/NoUnmappedDestinations.json +105 -0
- package/packages/core/src/plugins/__tests__/consent/mockSettings/UnmappedDestinations.json +101 -0
- package/packages/core/src/plugins/__tests__/consent/noUnmapped.test.ts +234 -0
- package/packages/core/src/plugins/__tests__/consent/unmapped.test.ts +265 -0
- package/packages/core/src/plugins/__tests__/consent/utils.ts +75 -0
- package/packages/core/src/storage/__tests__/sovranStorage.test.ts +153 -0
- package/packages/core/src/storage/helpers.ts +25 -0
- package/packages/core/src/storage/index.ts +3 -0
- package/packages/core/src/storage/sovranStorage.ts +558 -0
- package/packages/core/src/storage/types.ts +106 -0
- package/packages/core/src/test-helpers/index.ts +7 -0
- package/packages/core/src/test-helpers/mockDestinationPlugin.ts +7 -0
- package/packages/core/src/test-helpers/mockEventStore.ts +35 -0
- package/packages/core/src/test-helpers/mockLogger.ts +10 -0
- package/packages/core/src/test-helpers/mockSegmentStore.ts +266 -0
- package/packages/core/src/test-helpers/mockTimeline.ts +9 -0
- package/packages/core/src/test-helpers/setupSegmentClient.ts +59 -0
- package/packages/core/src/test-helpers/utils.ts +23 -0
- package/packages/core/src/timeline.ts +136 -0
- package/packages/core/src/types.ts +392 -0
- package/packages/core/src/util.ts +288 -0
- package/packages/core/src/uuid.ts +7 -0
- package/packages/core/tsconfig.json +10 -0
- package/packages/core/tsconfig.linter.json +11 -0
- package/packages/plugins/plugin-adjust/CHANGELOG.md +60 -0
- package/packages/plugins/plugin-adjust/LICENSE +21 -0
- package/packages/plugins/plugin-adjust/README.md +72 -0
- package/packages/plugins/plugin-adjust/babel.config.js +3 -0
- package/packages/plugins/plugin-adjust/jest.config.js +5 -0
- package/packages/plugins/plugin-adjust/package.json +72 -0
- package/packages/plugins/plugin-adjust/release.config.js +3 -0
- package/packages/plugins/plugin-adjust/src/AdjustPlugin.tsx +92 -0
- package/packages/plugins/plugin-adjust/src/index.ts +1 -0
- package/packages/plugins/plugin-adjust/src/methods/__mocks__/react-native-adjust.ts +19 -0
- package/packages/plugins/plugin-adjust/src/methods/__tests__/identify.test.ts +34 -0
- package/packages/plugins/plugin-adjust/src/methods/__tests__/reset.test.ts +15 -0
- package/packages/plugins/plugin-adjust/src/methods/__tests__/track.test.ts +148 -0
- package/packages/plugins/plugin-adjust/src/methods/identify.ts +14 -0
- package/packages/plugins/plugin-adjust/src/methods/reset.ts +9 -0
- package/packages/plugins/plugin-adjust/src/methods/track.ts +47 -0
- package/packages/plugins/plugin-adjust/src/util.ts +29 -0
- package/packages/plugins/plugin-adjust/tsconfig.json +10 -0
- package/packages/plugins/plugin-advertising-id/CHANGELOG.md +101 -0
- package/packages/plugins/plugin-advertising-id/CONTRIBUTING.md +196 -0
- package/packages/plugins/plugin-advertising-id/LICENSE +21 -0
- package/packages/plugins/plugin-advertising-id/README.md +40 -0
- package/packages/plugins/plugin-advertising-id/android/build.gradle +96 -0
- package/packages/plugins/plugin-advertising-id/android/gradle.properties +5 -0
- package/packages/plugins/plugin-advertising-id/android/src/main/AndroidManifest.xml +4 -0
- package/packages/plugins/plugin-advertising-id/android/src/main/AndroidManifestNew.xml +3 -0
- package/packages/plugins/plugin-advertising-id/android/src/main/java/com/reactnativeanalyticsreactnativepluginadvertisingid/AnalyticsReactNativePluginAdvertisingIdModule.kt +64 -0
- package/packages/plugins/plugin-advertising-id/android/src/main/java/com/reactnativeanalyticsreactnativepluginadvertisingid/AnalyticsReactNativePluginAdvertisingIdPackage.kt +17 -0
- package/packages/plugins/plugin-advertising-id/babel.config.js +3 -0
- package/packages/plugins/plugin-advertising-id/jest.config.js +5 -0
- package/packages/plugins/plugin-advertising-id/package.json +70 -0
- package/packages/plugins/plugin-advertising-id/release.config.js +3 -0
- package/packages/plugins/plugin-advertising-id/src/AdvertisingIdPlugin.ts +172 -0
- package/packages/plugins/plugin-advertising-id/src/index.ts +1 -0
- package/packages/plugins/plugin-advertising-id/src/types.ts +3 -0
- package/packages/plugins/plugin-advertising-id/tsconfig.json +10 -0
- package/packages/plugins/plugin-amplitudeSession/CHANGELOG.md +46 -0
- package/packages/plugins/plugin-amplitudeSession/LICENSE +21 -0
- package/packages/plugins/plugin-amplitudeSession/README.md +66 -0
- package/packages/plugins/plugin-amplitudeSession/babel.config.js +3 -0
- package/packages/plugins/plugin-amplitudeSession/jest.config.js +5 -0
- package/packages/plugins/plugin-amplitudeSession/package.json +71 -0
- package/packages/plugins/plugin-amplitudeSession/release.config.js +3 -0
- package/packages/plugins/plugin-amplitudeSession/src/AmplitudeSessionPlugin.tsx +327 -0
- package/packages/plugins/plugin-amplitudeSession/src/__tests__/AmplitudeSessionPlugin.test.ts +769 -0
- package/packages/plugins/plugin-amplitudeSession/src/index.ts +1 -0
- package/packages/plugins/plugin-amplitudeSession/tsconfig.json +10 -0
- package/packages/plugins/plugin-appsflyer/CHANGELOG.md +64 -0
- package/packages/plugins/plugin-appsflyer/LICENSE +21 -0
- package/packages/plugins/plugin-appsflyer/README.md +90 -0
- package/packages/plugins/plugin-appsflyer/babel.config.js +3 -0
- package/packages/plugins/plugin-appsflyer/jest.config.js +5 -0
- package/packages/plugins/plugin-appsflyer/package.json +74 -0
- package/packages/plugins/plugin-appsflyer/release.config.js +3 -0
- package/packages/plugins/plugin-appsflyer/src/AppsflyerPlugin.tsx +218 -0
- package/packages/plugins/plugin-appsflyer/src/__tests__/AppsflyerPlugin.test.ts +20 -0
- package/packages/plugins/plugin-appsflyer/src/index.ts +1 -0
- package/packages/plugins/plugin-appsflyer/src/methods/__mocks__/react-native-appsflyer.ts +11 -0
- package/packages/plugins/plugin-appsflyer/src/methods/__tests__/identify.test.ts +57 -0
- package/packages/plugins/plugin-appsflyer/src/methods/__tests__/track.test.ts +99 -0
- package/packages/plugins/plugin-appsflyer/src/methods/identify.ts +42 -0
- package/packages/plugins/plugin-appsflyer/src/methods/track.ts +61 -0
- package/packages/plugins/plugin-appsflyer/src/types.ts +9 -0
- package/packages/plugins/plugin-appsflyer/tsconfig.json +10 -0
- package/packages/plugins/plugin-branch/CHANGELOG.md +51 -0
- package/packages/plugins/plugin-branch/LICENSE +21 -0
- package/packages/plugins/plugin-branch/README.md +71 -0
- package/packages/plugins/plugin-branch/babel.config.js +3 -0
- package/packages/plugins/plugin-branch/jest.config.js +5 -0
- package/packages/plugins/plugin-branch/package.json +74 -0
- package/packages/plugins/plugin-branch/release.config.js +3 -0
- package/packages/plugins/plugin-branch/src/BranchPlugin.ts +42 -0
- package/packages/plugins/plugin-branch/src/index.ts +1 -0
- package/packages/plugins/plugin-branch/src/methods/__mocks__/react-native-branch.ts +16 -0
- package/packages/plugins/plugin-branch/src/methods/__tests__/alias.test.ts +23 -0
- package/packages/plugins/plugin-branch/src/methods/__tests__/identify.test.ts +23 -0
- package/packages/plugins/plugin-branch/src/methods/__tests__/screen.test.ts +38 -0
- package/packages/plugins/plugin-branch/src/methods/__tests__/track.test.ts +73 -0
- package/packages/plugins/plugin-branch/src/methods/alias.ts +9 -0
- package/packages/plugins/plugin-branch/src/methods/identify.ts +9 -0
- package/packages/plugins/plugin-branch/src/methods/parameterMapping.ts +109 -0
- package/packages/plugins/plugin-branch/src/methods/reset.ts +5 -0
- package/packages/plugins/plugin-branch/src/methods/screen.ts +17 -0
- package/packages/plugins/plugin-branch/src/methods/track.ts +18 -0
- package/packages/plugins/plugin-branch/src/methods/util.ts +64 -0
- package/packages/plugins/plugin-branch/tsconfig.json +10 -0
- package/packages/plugins/plugin-braze/CHANGELOG.md +101 -0
- package/packages/plugins/plugin-braze/LICENSE +21 -0
- package/packages/plugins/plugin-braze/README.md +72 -0
- package/packages/plugins/plugin-braze/babel.config.js +3 -0
- package/packages/plugins/plugin-braze/jest.config.js +5 -0
- package/packages/plugins/plugin-braze/package.json +74 -0
- package/packages/plugins/plugin-braze/release.config.js +3 -0
- package/packages/plugins/plugin-braze/src/BrazePlugin.tsx +346 -0
- package/packages/plugins/plugin-braze/src/index.ts +1 -0
- package/packages/plugins/plugin-braze/src/methods/__mocks__/@braze/react-native-sdk.ts +31 -0
- package/packages/plugins/plugin-braze/src/methods/__tests__/flush.test.ts +15 -0
- package/packages/plugins/plugin-braze/src/methods/__tests__/identify.test.ts +114 -0
- package/packages/plugins/plugin-braze/src/methods/__tests__/track.test.ts +321 -0
- package/packages/plugins/plugin-braze/src/methods/flush.ts +5 -0
- package/packages/plugins/plugin-braze/tsconfig.json +10 -0
- package/packages/plugins/plugin-braze-middleware/CHANGELOG.md +32 -0
- package/packages/plugins/plugin-braze-middleware/LICENSE +21 -0
- package/packages/plugins/plugin-braze-middleware/README.md +67 -0
- package/packages/plugins/plugin-braze-middleware/babel.config.js +3 -0
- package/packages/plugins/plugin-braze-middleware/jest.config.js +5 -0
- package/packages/plugins/plugin-braze-middleware/package.json +72 -0
- package/packages/plugins/plugin-braze-middleware/release.config.js +3 -0
- package/packages/plugins/plugin-braze-middleware/src/BrazeMiddlewarePlugin.tsx +38 -0
- package/packages/plugins/plugin-braze-middleware/src/index.ts +1 -0
- package/packages/plugins/plugin-braze-middleware/tsconfig.json +10 -0
- package/packages/plugins/plugin-clevertap/CHANGELOG.md +32 -0
- package/packages/plugins/plugin-clevertap/LICENSE +21 -0
- package/packages/plugins/plugin-clevertap/README.md +71 -0
- package/packages/plugins/plugin-clevertap/babel.config.js +3 -0
- package/packages/plugins/plugin-clevertap/jest.config.js +5 -0
- package/packages/plugins/plugin-clevertap/package.json +72 -0
- package/packages/plugins/plugin-clevertap/release.config.js +3 -0
- package/packages/plugins/plugin-clevertap/src/ClevertapPlugin.ts +75 -0
- package/packages/plugins/plugin-clevertap/src/__mocks__/clevertap-react-native.ts +5 -0
- package/packages/plugins/plugin-clevertap/src/__tests__/ClevertapPlugin.test.ts +164 -0
- package/packages/plugins/plugin-clevertap/src/index.ts +1 -0
- package/packages/plugins/plugin-clevertap/src/parameterMapping.ts +19 -0
- package/packages/plugins/plugin-clevertap/tsconfig.json +10 -0
- package/packages/plugins/plugin-destination-filters/CHANGELOG.md +39 -0
- package/packages/plugins/plugin-destination-filters/LICENSE +21 -0
- package/packages/plugins/plugin-destination-filters/README.md +71 -0
- package/packages/plugins/plugin-destination-filters/babel.config.js +3 -0
- package/packages/plugins/plugin-destination-filters/jest.config.js +5 -0
- package/packages/plugins/plugin-destination-filters/package.json +77 -0
- package/packages/plugins/plugin-destination-filters/release.config.js +3 -0
- package/packages/plugins/plugin-destination-filters/src/DestinationFilters.ts +90 -0
- package/packages/plugins/plugin-destination-filters/src/__tests__/DestinationFilters.test.ts +102 -0
- package/packages/plugins/plugin-destination-filters/src/index.tsx +1 -0
- package/packages/plugins/plugin-destination-filters/tsconfig.json +10 -0
- package/packages/plugins/plugin-device-token/CHANGELOG.md +71 -0
- package/packages/plugins/plugin-device-token/LICENSE +21 -0
- package/packages/plugins/plugin-device-token/README.md +98 -0
- package/packages/plugins/plugin-device-token/babel.config.js +3 -0
- package/packages/plugins/plugin-device-token/jest.config.js +5 -0
- package/packages/plugins/plugin-device-token/package.json +76 -0
- package/packages/plugins/plugin-device-token/release.config.js +3 -0
- package/packages/plugins/plugin-device-token/src/DeviceTokenPlugin.tsx +94 -0
- package/packages/plugins/plugin-device-token/src/index.ts +1 -0
- package/packages/plugins/plugin-device-token/src/methods/___tests__/DeviceTokenPlugin.test.ts +94 -0
- package/packages/plugins/plugin-device-token/tsconfig.json +10 -0
- package/packages/plugins/plugin-facebook-app-events/CHANGELOG.md +78 -0
- package/packages/plugins/plugin-facebook-app-events/LICENSE +21 -0
- package/packages/plugins/plugin-facebook-app-events/README.md +73 -0
- package/packages/plugins/plugin-facebook-app-events/babel.config.js +3 -0
- package/packages/plugins/plugin-facebook-app-events/jest.config.js +5 -0
- package/packages/plugins/plugin-facebook-app-events/package.json +72 -0
- package/packages/plugins/plugin-facebook-app-events/release.config.js +3 -0
- package/packages/plugins/plugin-facebook-app-events/src/FacebookAppEventsPlugin.ts +192 -0
- package/packages/plugins/plugin-facebook-app-events/src/__tests__/FacebookAppEventsPlugin.test.ts +284 -0
- package/packages/plugins/plugin-facebook-app-events/src/index.ts +1 -0
- package/packages/plugins/plugin-facebook-app-events/src/methods/__tests__/screen.test.ts +33 -0
- package/packages/plugins/plugin-facebook-app-events/src/methods/screen.ts +35 -0
- package/packages/plugins/plugin-facebook-app-events/src/parameterMapping.ts +46 -0
- package/packages/plugins/plugin-facebook-app-events/src/utils.ts +12 -0
- package/packages/plugins/plugin-facebook-app-events/tsconfig.json +10 -0
- package/packages/plugins/plugin-firebase/CHANGELOG.md +102 -0
- package/packages/plugins/plugin-firebase/LICENSE +21 -0
- package/packages/plugins/plugin-firebase/README.md +72 -0
- package/packages/plugins/plugin-firebase/babel.config.js +3 -0
- package/packages/plugins/plugin-firebase/jest.config.js +5 -0
- package/packages/plugins/plugin-firebase/package.json +74 -0
- package/packages/plugins/plugin-firebase/release.config.js +3 -0
- package/packages/plugins/plugin-firebase/src/FirebasePlugin.tsx +96 -0
- package/packages/plugins/plugin-firebase/src/index.ts +1 -0
- package/packages/plugins/plugin-firebase/src/methods/___tests__/identify.test.ts +73 -0
- package/packages/plugins/plugin-firebase/src/methods/___tests__/reset.test.ts +20 -0
- package/packages/plugins/plugin-firebase/src/methods/___tests__/screen.test.ts +33 -0
- package/packages/plugins/plugin-firebase/src/methods/___tests__/track.test.ts +85 -0
- package/packages/plugins/plugin-firebase/src/methods/parameterMapping.ts +45 -0
- package/packages/plugins/plugin-firebase/src/methods/reset.ts +5 -0
- package/packages/plugins/plugin-firebase/src/methods/screen.ts +12 -0
- package/packages/plugins/plugin-firebase/src/methods/track.ts +26 -0
- package/packages/plugins/plugin-firebase/tsconfig.json +10 -0
- package/packages/plugins/plugin-idfa/CHANGELOG.md +62 -0
- package/packages/plugins/plugin-idfa/LICENSE +21 -0
- package/packages/plugins/plugin-idfa/README.md +105 -0
- package/packages/plugins/plugin-idfa/babel.config.js +3 -0
- package/packages/plugins/plugin-idfa/ios/AnalyticsReactNativePluginIdfa-Bridging-Header.h +2 -0
- package/packages/plugins/plugin-idfa/ios/AnalyticsReactNativePluginIdfa.m +11 -0
- package/packages/plugins/plugin-idfa/ios/AnalyticsReactNativePluginIdfa.swift +68 -0
- package/packages/plugins/plugin-idfa/ios/AnalyticsReactNativePluginIdfa.xcodeproj/project.pbxproj +293 -0
- package/packages/plugins/plugin-idfa/jest.config.js +5 -0
- package/packages/plugins/plugin-idfa/package.json +70 -0
- package/packages/plugins/plugin-idfa/release.config.js +3 -0
- package/packages/plugins/plugin-idfa/segment-analytics-react-native-plugin-idfa.podspec +19 -0
- package/packages/plugins/plugin-idfa/src/AnalyticsReactNativePluginIdfa.e2e.mock.ts +12 -0
- package/packages/plugins/plugin-idfa/src/AnalyticsReactNativePluginIdfa.ts +18 -0
- package/packages/plugins/plugin-idfa/src/IdfaPlugin.tsx +80 -0
- package/packages/plugins/plugin-idfa/src/index.ts +1 -0
- package/packages/plugins/plugin-idfa/src/types.ts +13 -0
- package/packages/plugins/plugin-idfa/tsconfig.json +10 -0
- package/packages/plugins/plugin-mixpanel/CHANGELOG.md +73 -0
- package/packages/plugins/plugin-mixpanel/LICENSE +21 -0
- package/packages/plugins/plugin-mixpanel/README.md +71 -0
- package/packages/plugins/plugin-mixpanel/babel.config.js +3 -0
- package/packages/plugins/plugin-mixpanel/jest.config.js +5 -0
- package/packages/plugins/plugin-mixpanel/package.json +72 -0
- package/packages/plugins/plugin-mixpanel/release.config.js +3 -0
- package/packages/plugins/plugin-mixpanel/src/MixpanelPlugin.ts +106 -0
- package/packages/plugins/plugin-mixpanel/src/index.ts +1 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__mocks__/mixpanel-react-native.ts +67 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/MixpanelPlugin.test.ts +57 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/__helpers__/constants.ts +18 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/alias.test.ts +47 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/group.test.ts +49 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/identify.test.ts +103 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/screen.test.ts +119 -0
- package/packages/plugins/plugin-mixpanel/src/methods/__tests__/track.test.ts +110 -0
- package/packages/plugins/plugin-mixpanel/src/methods/alias.ts +28 -0
- package/packages/plugins/plugin-mixpanel/src/methods/group.ts +26 -0
- package/packages/plugins/plugin-mixpanel/src/methods/identify.ts +72 -0
- package/packages/plugins/plugin-mixpanel/src/methods/screen.ts +43 -0
- package/packages/plugins/plugin-mixpanel/src/methods/track.ts +60 -0
- package/packages/plugins/plugin-mixpanel/src/types.ts +15 -0
- package/packages/plugins/plugin-mixpanel/tsconfig.json +10 -0
- package/packages/plugins/plugin-onetrust/CHANGELOG.md +16 -0
- package/packages/plugins/plugin-onetrust/LICENSE +21 -0
- package/packages/plugins/plugin-onetrust/README.md +155 -0
- package/packages/plugins/plugin-onetrust/babel.config.js +3 -0
- package/packages/plugins/plugin-onetrust/jest.config.js +6 -0
- package/packages/plugins/plugin-onetrust/package.json +75 -0
- package/packages/plugins/plugin-onetrust/release.config.js +3 -0
- package/packages/plugins/plugin-onetrust/src/OneTrustProvider.ts +71 -0
- package/packages/plugins/plugin-onetrust/src/index.tsx +1 -0
- package/packages/plugins/plugin-onetrust/tsconfig.json +10 -0
- package/packages/shared/__mocks__/context.ts +35 -0
- package/packages/shared/__mocks__/react-native-get-random-values.ts +1 -0
- package/packages/shared/__mocks__/react-native.ts +53 -0
- package/packages/shared/__mocks__/uuid.ts +3 -0
- package/packages/shared/jest.config.base.js +38 -0
- package/packages/shared/package.json +19 -0
- package/packages/shared/src/setup.ts +7 -0
- package/packages/shared/tsconfig.json +15 -0
- package/packages/sovran/CHANGELOG.md +42 -0
- package/packages/sovran/CONTRIBUTING.md +196 -0
- package/packages/sovran/LICENSE +21 -0
- package/packages/sovran/README.md +174 -0
- package/packages/sovran/android/build.gradle +94 -0
- package/packages/sovran/android/gradle.properties +5 -0
- package/packages/sovran/android/src/main/AndroidManifest.xml +4 -0
- package/packages/sovran/android/src/main/AndroidManifestNew.xml +3 -0
- package/packages/sovran/android/src/main/java/com/reactnativesovran/Sovran.kt +45 -0
- package/packages/sovran/android/src/main/java/com/reactnativesovran/SovranModule.kt +55 -0
- package/packages/sovran/babel.config.js +3 -0
- package/packages/sovran/ios/Sovran-Bridging-Header.h +3 -0
- package/packages/sovran/ios/Sovran.m +8 -0
- package/packages/sovran/ios/Sovran.swift +67 -0
- package/packages/sovran/ios/Sovran.xcodeproj/project.pbxproj +279 -0
- package/packages/sovran/jest.config.js +5 -0
- package/packages/sovran/package.json +89 -0
- package/packages/sovran/release.config.js +3 -0
- package/packages/sovran/sovran-react-native.podspec +33 -0
- package/packages/sovran/src/__tests__/bridge.test.ts +39 -0
- package/packages/sovran/src/__tests__/index.test.tsx +1 -0
- package/packages/sovran/src/__tests__/store.test.ts +397 -0
- package/packages/sovran/src/bridge.ts +48 -0
- package/packages/sovran/src/index.tsx +52 -0
- package/packages/sovran/src/persistor/async-storage-persistor.ts +63 -0
- package/packages/sovran/src/persistor/index.ts +2 -0
- package/packages/sovran/src/persistor/persistor.ts +31 -0
- package/packages/sovran/src/store.ts +232 -0
- package/packages/sovran/tsconfig.json +9 -0
- package/release.config.js +13 -0
- package/tsconfig.json +44 -0
- package/tsconfig.linter.json +36 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Plugin } from '../plugin';
|
|
2
|
+
import { PluginType } from '../types';
|
|
3
|
+
import type {
|
|
4
|
+
IntegrationSettings,
|
|
5
|
+
SegmentAPIIntegration,
|
|
6
|
+
SegmentEvent,
|
|
7
|
+
TrackEventType,
|
|
8
|
+
UpdateType,
|
|
9
|
+
SegmentAPISettings,
|
|
10
|
+
} from '../types';
|
|
11
|
+
import type { DestinationPlugin } from '../plugin';
|
|
12
|
+
import type { SegmentClient } from '../analytics';
|
|
13
|
+
|
|
14
|
+
import { SEGMENT_DESTINATION_KEY } from './SegmentDestination';
|
|
15
|
+
|
|
16
|
+
const CONSENT_PREF_UPDATE_EVENT = 'Segment Consent Preference';
|
|
17
|
+
|
|
18
|
+
export interface CategoryConsentStatusProvider {
|
|
19
|
+
setApplicableCategories(categories: string[]): void;
|
|
20
|
+
getConsentStatus(): Promise<Record<string, boolean>>;
|
|
21
|
+
onConsentChange(cb: (updConsent: Record<string, boolean>) => void): void;
|
|
22
|
+
shutdown?(): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* This plugin interfaces with the consent provider and it:
|
|
27
|
+
*
|
|
28
|
+
* - stamps all events with the consent metadata.
|
|
29
|
+
* - augments all destinations with a consent filter plugin that prevents events from reaching them if
|
|
30
|
+
* they are not compliant current consent setup
|
|
31
|
+
* - listens for consent change from the provider and notifies Segment
|
|
32
|
+
*/
|
|
33
|
+
export class ConsentPlugin extends Plugin {
|
|
34
|
+
type = PluginType.before;
|
|
35
|
+
private consentCategoryProvider: CategoryConsentStatusProvider;
|
|
36
|
+
private categories: string[] = [];
|
|
37
|
+
queuedEvents: SegmentEvent[] = [];
|
|
38
|
+
consentStarted = false;
|
|
39
|
+
|
|
40
|
+
constructor(consentCategoryProvider: CategoryConsentStatusProvider) {
|
|
41
|
+
super();
|
|
42
|
+
this.consentCategoryProvider = consentCategoryProvider;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
update(_settings: SegmentAPISettings, _type: UpdateType): void {
|
|
46
|
+
const consentSettings = this.analytics?.consentSettings.get();
|
|
47
|
+
this.categories = consentSettings?.allCategories || [];
|
|
48
|
+
this.consentCategoryProvider.setApplicableCategories(this.categories);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
configure(analytics: SegmentClient): void {
|
|
52
|
+
super.configure(analytics);
|
|
53
|
+
analytics.getPlugins().forEach(this.injectConsentFilterIfApplicable);
|
|
54
|
+
analytics.onPluginLoaded(this.injectConsentFilterIfApplicable);
|
|
55
|
+
this.consentCategoryProvider.onConsentChange(() => {
|
|
56
|
+
this.notifyConsentChange();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
let lastDeviceAttrs = analytics.context.get()?.device;
|
|
60
|
+
analytics.context.onChange((c) => {
|
|
61
|
+
const newAttrs = c?.device;
|
|
62
|
+
if (
|
|
63
|
+
newAttrs?.adTrackingEnabled !== lastDeviceAttrs?.adTrackingEnabled ||
|
|
64
|
+
newAttrs?.advertisingId !== lastDeviceAttrs?.advertisingId ||
|
|
65
|
+
newAttrs?.trackingStatus !== lastDeviceAttrs?.trackingStatus
|
|
66
|
+
) {
|
|
67
|
+
this.notifyConsentChange();
|
|
68
|
+
}
|
|
69
|
+
lastDeviceAttrs = newAttrs;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async execute(event: SegmentEvent): Promise<SegmentEvent | undefined> {
|
|
74
|
+
if (this.consentStarted === true) {
|
|
75
|
+
event.context = {
|
|
76
|
+
...event.context,
|
|
77
|
+
consent: {
|
|
78
|
+
categoryPreferences:
|
|
79
|
+
await this.consentCategoryProvider.getConsentStatus(),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
return event;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (this.consentStarted === false) {
|
|
86
|
+
// constrain the queue to avoid running out of memory if consent is never started
|
|
87
|
+
if (this.queuedEvents.length <= 1000) {
|
|
88
|
+
this.queuedEvents.push(event);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
shutdown(): void {
|
|
97
|
+
this.consentCategoryProvider.shutdown?.();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private injectConsentFilterIfApplicable = (plugin: Plugin) => {
|
|
101
|
+
if (this.isDestinationPlugin(plugin)) {
|
|
102
|
+
plugin.add(
|
|
103
|
+
new ConsentFilterPlugin((event) => {
|
|
104
|
+
const allCategories =
|
|
105
|
+
this.analytics?.consentSettings.get()?.allCategories || [];
|
|
106
|
+
const settings = this.analytics?.settings.get() || {};
|
|
107
|
+
const preferences = event.context?.consent?.categoryPreferences || {};
|
|
108
|
+
|
|
109
|
+
if (plugin.key === SEGMENT_DESTINATION_KEY) {
|
|
110
|
+
const noneConsented = allCategories.every(
|
|
111
|
+
(category) => !preferences[category]
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
this.isConsentUpdateEvent(event) ||
|
|
116
|
+
!this.isConsentFeatureSetup() ||
|
|
117
|
+
!(noneConsented && !this.hasUnmappedDestinations())
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const integrationSettings = settings?.[plugin.key];
|
|
122
|
+
if (this.containsConsentSettings(integrationSettings)) {
|
|
123
|
+
const categories = integrationSettings.consentSettings.categories;
|
|
124
|
+
return (
|
|
125
|
+
!this.isConsentUpdateEvent(event) &&
|
|
126
|
+
categories.every((category) => preferences?.[category])
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return true;
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
private isDestinationPlugin(plugin: Plugin): plugin is DestinationPlugin {
|
|
137
|
+
return plugin.type === PluginType.destination;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private containsConsentSettings = (
|
|
141
|
+
settings: IntegrationSettings | undefined
|
|
142
|
+
): settings is Required<Pick<SegmentAPIIntegration, 'consentSettings'>> => {
|
|
143
|
+
return (
|
|
144
|
+
typeof (settings as SegmentAPIIntegration)?.consentSettings
|
|
145
|
+
?.categories === 'object'
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
private isConsentUpdateEvent(event: SegmentEvent): boolean {
|
|
150
|
+
return (event as TrackEventType).event === CONSENT_PREF_UPDATE_EVENT;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private hasUnmappedDestinations(): boolean {
|
|
154
|
+
return (
|
|
155
|
+
this.analytics?.consentSettings.get()?.hasUnmappedDestinations === true
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private isConsentFeatureSetup(): boolean {
|
|
160
|
+
return typeof this.analytics?.consentSettings.get() === 'object';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private notifyConsentChange() {
|
|
164
|
+
// actual preferences will be attached in the execute method
|
|
165
|
+
this.analytics?.track(CONSENT_PREF_UPDATE_EVENT).catch((e) => {
|
|
166
|
+
throw e;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public start() {
|
|
171
|
+
this.consentStarted = true;
|
|
172
|
+
|
|
173
|
+
this.sendQueuedEvents();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
sendQueuedEvents() {
|
|
177
|
+
this.queuedEvents.forEach((event) => {
|
|
178
|
+
this.analytics?.process(event);
|
|
179
|
+
});
|
|
180
|
+
this.queuedEvents = [];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* This plugin reads the consent metadata set on the context object and then drops the events
|
|
186
|
+
* if they are going into a destination which violates's set consent preferences
|
|
187
|
+
*/
|
|
188
|
+
class ConsentFilterPlugin extends Plugin {
|
|
189
|
+
type = PluginType.before;
|
|
190
|
+
private shouldAllowEvent: (event: SegmentEvent) => boolean;
|
|
191
|
+
|
|
192
|
+
constructor(shouldAllowEvent: (event: SegmentEvent) => boolean) {
|
|
193
|
+
super();
|
|
194
|
+
this.shouldAllowEvent = shouldAllowEvent;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
execute(event: SegmentEvent): SegmentEvent | undefined {
|
|
198
|
+
return this.shouldAllowEvent(event) ? event : undefined;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DestinationPlugin, UtilityPlugin } from '../plugin';
|
|
2
|
+
import { PluginType, SegmentEvent } from '../types';
|
|
3
|
+
|
|
4
|
+
export class DestinationMetadataEnrichment extends UtilityPlugin {
|
|
5
|
+
type = PluginType.enrichment;
|
|
6
|
+
|
|
7
|
+
private destinationKey: string;
|
|
8
|
+
|
|
9
|
+
constructor(destinationKey: string) {
|
|
10
|
+
super();
|
|
11
|
+
this.destinationKey = destinationKey;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
execute(event: SegmentEvent): SegmentEvent {
|
|
15
|
+
const pluginSettings = this.analytics?.settings.get();
|
|
16
|
+
const plugins = this.analytics?.getPlugins(PluginType.destination);
|
|
17
|
+
|
|
18
|
+
if (pluginSettings === undefined) {
|
|
19
|
+
return event;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Disable all destinations that have a device mode plugin
|
|
23
|
+
const destinations =
|
|
24
|
+
plugins?.map((plugin) => (plugin as DestinationPlugin).key) ?? [];
|
|
25
|
+
const bundled = new Set<string>();
|
|
26
|
+
|
|
27
|
+
for (const key of destinations) {
|
|
28
|
+
if (key === this.destinationKey) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (Object.keys(pluginSettings).includes(key)) {
|
|
33
|
+
bundled.add(key);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const unbundled = new Set<string>();
|
|
38
|
+
const segmentInfo =
|
|
39
|
+
(pluginSettings[this.destinationKey] as Record<string, unknown>) ?? {};
|
|
40
|
+
const unbundledIntegrations: string[] =
|
|
41
|
+
(segmentInfo.unbundledIntegrations as string[]) ?? [];
|
|
42
|
+
|
|
43
|
+
// All active integrations, not in `bundled` are put in `unbundled`
|
|
44
|
+
// All unbundledIntegrations not in `bundled` are put in `unbundled`
|
|
45
|
+
for (const integration in pluginSettings) {
|
|
46
|
+
if (integration !== this.destinationKey && !bundled.has(integration)) {
|
|
47
|
+
unbundled.add(integration);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const integration of unbundledIntegrations) {
|
|
51
|
+
if (!bundled.has(integration)) {
|
|
52
|
+
unbundled.add(integration);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// User/event defined integrations override the cloud/device mode merge
|
|
57
|
+
const enrichedEvent: SegmentEvent = {
|
|
58
|
+
...event,
|
|
59
|
+
_metadata: {
|
|
60
|
+
bundled: Array.from(bundled),
|
|
61
|
+
unbundled: Array.from(unbundled),
|
|
62
|
+
bundledIds: [],
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
return enrichedEvent;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { createStore, Store } from '@segment/sovran-react-native';
|
|
2
|
+
import type { SegmentClient } from '../analytics';
|
|
3
|
+
import { defaultConfig } from '../constants';
|
|
4
|
+
import { UtilityPlugin } from '../plugin';
|
|
5
|
+
import { PluginType, SegmentEvent } from '../types';
|
|
6
|
+
import { createPromise } from '../util';
|
|
7
|
+
import { ErrorType, SegmentError } from '../errors';
|
|
8
|
+
/**
|
|
9
|
+
* This plugin manages a queue where all events get added to after timeline processing.
|
|
10
|
+
* It takes a onFlush callback to trigger any action particular to your destination sending events.
|
|
11
|
+
* It can autotrigger a flush of the queue when it reaches the config flushAt limit.
|
|
12
|
+
*/
|
|
13
|
+
export class QueueFlushingPlugin extends UtilityPlugin {
|
|
14
|
+
// Gets executed last to keep the queue after all timeline processing is done
|
|
15
|
+
type = PluginType.after;
|
|
16
|
+
|
|
17
|
+
private storeKey: string;
|
|
18
|
+
private isPendingUpload = false;
|
|
19
|
+
private queueStore: Store<{ events: SegmentEvent[] }> | undefined;
|
|
20
|
+
private onFlush: (events: SegmentEvent[]) => Promise<void>;
|
|
21
|
+
private isRestoredResolve: () => void;
|
|
22
|
+
private isRestored: Promise<void>;
|
|
23
|
+
private timeoutWarned = false;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param onFlush callback to execute when the queue is flushed (either by reaching the limit or manually) e.g. code to upload events to your destination
|
|
27
|
+
* @param storeKey key to store the queue in the store. Must be unique per destination instance
|
|
28
|
+
* @param restoreTimeout time in ms to wait for the queue to be restored from the store before uploading events (default: 500ms)
|
|
29
|
+
*/
|
|
30
|
+
constructor(
|
|
31
|
+
onFlush: (events: SegmentEvent[]) => Promise<void>,
|
|
32
|
+
storeKey = 'events',
|
|
33
|
+
restoreTimeout = 1000
|
|
34
|
+
) {
|
|
35
|
+
super();
|
|
36
|
+
this.onFlush = onFlush;
|
|
37
|
+
this.storeKey = storeKey;
|
|
38
|
+
const { promise, resolve } = createPromise<void>(restoreTimeout);
|
|
39
|
+
this.isRestored = promise;
|
|
40
|
+
this.isRestoredResolve = resolve;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
configure(analytics: SegmentClient): void {
|
|
44
|
+
super.configure(analytics);
|
|
45
|
+
|
|
46
|
+
const config = analytics?.getConfig() ?? defaultConfig;
|
|
47
|
+
|
|
48
|
+
// Create its own storage per SegmentDestination instance to support multiple instances
|
|
49
|
+
this.queueStore = createStore(
|
|
50
|
+
{ events: [] as SegmentEvent[] },
|
|
51
|
+
{
|
|
52
|
+
persist: {
|
|
53
|
+
storeId: `${config.writeKey}-${this.storeKey}`,
|
|
54
|
+
persistor: config.storePersistor,
|
|
55
|
+
saveDelay: config.storePersistorSaveDelay ?? 0,
|
|
56
|
+
onInitialized: () => {
|
|
57
|
+
this.isRestoredResolve();
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async execute(event: SegmentEvent): Promise<SegmentEvent | undefined> {
|
|
65
|
+
await this.queueStore?.dispatch((state) => {
|
|
66
|
+
const events = [...state.events, event];
|
|
67
|
+
return { events };
|
|
68
|
+
});
|
|
69
|
+
return event;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Calls the onFlush callback with the events in the queue
|
|
74
|
+
*/
|
|
75
|
+
async flush() {
|
|
76
|
+
// Wait for the queue to be restored
|
|
77
|
+
try {
|
|
78
|
+
await this.isRestored;
|
|
79
|
+
|
|
80
|
+
if (this.timeoutWarned === true) {
|
|
81
|
+
this.analytics?.logger.info('Flush triggered successfully.');
|
|
82
|
+
|
|
83
|
+
this.timeoutWarned = false;
|
|
84
|
+
}
|
|
85
|
+
} catch (e) {
|
|
86
|
+
// If the queue is not restored before the timeout, we will notify but not block flushing events
|
|
87
|
+
if (this.timeoutWarned === false) {
|
|
88
|
+
this.analytics?.reportInternalError(
|
|
89
|
+
new SegmentError(
|
|
90
|
+
ErrorType.InitializationError,
|
|
91
|
+
'Queue restoration timeout',
|
|
92
|
+
e
|
|
93
|
+
)
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
this.analytics?.logger.warn(
|
|
97
|
+
'Flush triggered but queue restoration and settings loading not complete. Flush will be retried.',
|
|
98
|
+
e
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
this.timeoutWarned = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const events = (await this.queueStore?.getState(true))?.events ?? [];
|
|
106
|
+
if (!this.isPendingUpload) {
|
|
107
|
+
try {
|
|
108
|
+
this.isPendingUpload = true;
|
|
109
|
+
await this.onFlush(events);
|
|
110
|
+
} finally {
|
|
111
|
+
this.isPendingUpload = false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Removes one or multiple events from the queue
|
|
118
|
+
* @param events events to remove
|
|
119
|
+
*/
|
|
120
|
+
async dequeue(events: SegmentEvent | SegmentEvent[]) {
|
|
121
|
+
await this.queueStore?.dispatch((state) => {
|
|
122
|
+
const eventsToRemove = Array.isArray(events) ? events : [events];
|
|
123
|
+
|
|
124
|
+
if (eventsToRemove.length === 0 || state.events.length === 0) {
|
|
125
|
+
return state;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const setToRemove = new Set(eventsToRemove);
|
|
129
|
+
const filteredEvents = state.events.filter((e) => !setToRemove.has(e));
|
|
130
|
+
return { events: filteredEvents };
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Clear all events from the queue
|
|
135
|
+
*/
|
|
136
|
+
async dequeueEvents() {
|
|
137
|
+
await this.queueStore?.dispatch(() => {
|
|
138
|
+
return { events: [] };
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* * Returns the count of items in the queue
|
|
144
|
+
*/
|
|
145
|
+
async pendingEvents() {
|
|
146
|
+
const events = (await this.queueStore?.getState(true))?.events ?? [];
|
|
147
|
+
return events.length;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { DestinationPlugin } from '../plugin';
|
|
2
|
+
import {
|
|
3
|
+
PluginType,
|
|
4
|
+
SegmentAPIIntegration,
|
|
5
|
+
SegmentAPISettings,
|
|
6
|
+
SegmentEvent,
|
|
7
|
+
UpdateType,
|
|
8
|
+
} from '../types';
|
|
9
|
+
import { chunk, createPromise, getURL } from '../util';
|
|
10
|
+
import { uploadEvents } from '../api';
|
|
11
|
+
import type { SegmentClient } from '../analytics';
|
|
12
|
+
import { DestinationMetadataEnrichment } from './DestinationMetadataEnrichment';
|
|
13
|
+
import { QueueFlushingPlugin } from './QueueFlushingPlugin';
|
|
14
|
+
import { defaultApiHost } from '../constants';
|
|
15
|
+
import { checkResponseForErrors, translateHTTPError } from '../errors';
|
|
16
|
+
import { defaultConfig } from '../constants';
|
|
17
|
+
|
|
18
|
+
const MAX_EVENTS_PER_BATCH = 100;
|
|
19
|
+
const MAX_PAYLOAD_SIZE_IN_KB = 500;
|
|
20
|
+
export const SEGMENT_DESTINATION_KEY = 'Segment.io';
|
|
21
|
+
|
|
22
|
+
export class SegmentDestination extends DestinationPlugin {
|
|
23
|
+
type = PluginType.destination;
|
|
24
|
+
key = SEGMENT_DESTINATION_KEY;
|
|
25
|
+
private apiHost?: string;
|
|
26
|
+
private settingsResolve: () => void;
|
|
27
|
+
private settingsPromise: Promise<void>;
|
|
28
|
+
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
// We don't timeout this promise. We strictly need the response from Segment before sending things
|
|
32
|
+
const { promise, resolve } = createPromise<void>();
|
|
33
|
+
this.settingsPromise = promise;
|
|
34
|
+
this.settingsResolve = resolve;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private sendEvents = async (events: SegmentEvent[]): Promise<void> => {
|
|
38
|
+
if (events.length === 0) {
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// We're not sending events until Segment has loaded all settings
|
|
43
|
+
await this.settingsPromise;
|
|
44
|
+
|
|
45
|
+
const config = this.analytics?.getConfig() ?? defaultConfig;
|
|
46
|
+
|
|
47
|
+
const chunkedEvents: SegmentEvent[][] = chunk(
|
|
48
|
+
events,
|
|
49
|
+
config.maxBatchSize ?? MAX_EVENTS_PER_BATCH,
|
|
50
|
+
MAX_PAYLOAD_SIZE_IN_KB
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
let sentEvents: SegmentEvent[] = [];
|
|
54
|
+
let numFailedEvents = 0;
|
|
55
|
+
|
|
56
|
+
await Promise.all(
|
|
57
|
+
chunkedEvents.map(async (batch: SegmentEvent[]) => {
|
|
58
|
+
try {
|
|
59
|
+
const res = await uploadEvents({
|
|
60
|
+
writeKey: config.writeKey,
|
|
61
|
+
url: this.getEndpoint(),
|
|
62
|
+
events: batch,
|
|
63
|
+
});
|
|
64
|
+
checkResponseForErrors(res);
|
|
65
|
+
sentEvents = sentEvents.concat(batch);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
this.analytics?.reportInternalError(translateHTTPError(e));
|
|
68
|
+
this.analytics?.logger.warn(e);
|
|
69
|
+
numFailedEvents += batch.length;
|
|
70
|
+
} finally {
|
|
71
|
+
await this.queuePlugin.dequeue(sentEvents);
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
if (sentEvents.length) {
|
|
77
|
+
if (config.debug === true) {
|
|
78
|
+
this.analytics?.logger.info(`Sent ${sentEvents.length} events`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (numFailedEvents) {
|
|
83
|
+
this.analytics?.logger.error(`Failed to send ${numFailedEvents} events.`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return Promise.resolve();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
private readonly queuePlugin = new QueueFlushingPlugin(this.sendEvents);
|
|
90
|
+
|
|
91
|
+
private getEndpoint(): string {
|
|
92
|
+
const config = this.analytics?.getConfig();
|
|
93
|
+
const hasProxy = !!(config?.proxy ?? '');
|
|
94
|
+
const useSegmentEndpoints = Boolean(config?.useSegmentEndpoints);
|
|
95
|
+
let baseURL = '';
|
|
96
|
+
let endpoint = '';
|
|
97
|
+
if (hasProxy) {
|
|
98
|
+
//baseURL is always config?.proxy if hasProxy
|
|
99
|
+
baseURL = config?.proxy ?? '';
|
|
100
|
+
if (useSegmentEndpoints) {
|
|
101
|
+
const isProxyEndsWithSlash = baseURL.endsWith('/');
|
|
102
|
+
endpoint = isProxyEndsWithSlash ? 'b' : '/b';
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
baseURL = this.apiHost ?? defaultApiHost;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
return getURL(baseURL, endpoint);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error('Error in getEndpoint:', `fallback to ${defaultApiHost}`);
|
|
111
|
+
return defaultApiHost;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
configure(analytics: SegmentClient): void {
|
|
115
|
+
super.configure(analytics);
|
|
116
|
+
|
|
117
|
+
// If the client has a proxy we don't need to await for settings apiHost, we can send events directly
|
|
118
|
+
// Important! If new settings are required in the future you probably want to change this!
|
|
119
|
+
if (analytics.getConfig().proxy !== undefined) {
|
|
120
|
+
this.settingsResolve();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Enrich events with the Destination metadata
|
|
124
|
+
this.add(new DestinationMetadataEnrichment(SEGMENT_DESTINATION_KEY));
|
|
125
|
+
this.add(this.queuePlugin);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// We block sending stuff to segment until we get the settings
|
|
129
|
+
update(settings: SegmentAPISettings, _type: UpdateType): void {
|
|
130
|
+
const segmentSettings = settings.integrations[
|
|
131
|
+
this.key
|
|
132
|
+
] as SegmentAPIIntegration;
|
|
133
|
+
if (
|
|
134
|
+
segmentSettings?.apiHost !== undefined &&
|
|
135
|
+
segmentSettings?.apiHost !== null
|
|
136
|
+
) {
|
|
137
|
+
//assign the api host from segment settings (domain/v1)
|
|
138
|
+
this.apiHost = `https://${segmentSettings.apiHost}/b`;
|
|
139
|
+
}
|
|
140
|
+
this.settingsResolve();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
execute(event: SegmentEvent): Promise<SegmentEvent | undefined> {
|
|
144
|
+
// Execute the internal timeline here, the queue plugin will pick up the event and add it to the queue automatically
|
|
145
|
+
const enrichedEvent = super.execute(event);
|
|
146
|
+
return enrichedEvent;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async flush() {
|
|
150
|
+
// Wait until the queue is done restoring before flushing
|
|
151
|
+
return this.queuePlugin.flush();
|
|
152
|
+
}
|
|
153
|
+
}
|