@amplitude/plugin-engagement-react-native 0.1.1-alpha.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.
Files changed (44) hide show
  1. package/LICENSE +20 -0
  2. package/PluginEngagementReactNative.podspec +22 -0
  3. package/README.md +68 -0
  4. package/android/build.gradle +83 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/amplitude/pluginengagementreactnative/PluginEngagementReactNativeModule.kt +18 -0
  8. package/android/src/main/java/com/amplitude/pluginengagementreactnative/PluginEngagementReactNativePackage.kt +33 -0
  9. package/ios/AmplitudeEngagementAdapter.swift +121 -0
  10. package/ios/PluginEngagementReactNative.h +5 -0
  11. package/ios/PluginEngagementReactNative.mm +87 -0
  12. package/lib/module/AmplitudeEngagement.js +42 -0
  13. package/lib/module/AmplitudeEngagement.js.map +1 -0
  14. package/lib/module/AmplitudeEngagementPlugin.js +29 -0
  15. package/lib/module/AmplitudeEngagementPlugin.js.map +1 -0
  16. package/lib/module/NativePluginEngagementReactNative.js +5 -0
  17. package/lib/module/NativePluginEngagementReactNative.js.map +1 -0
  18. package/lib/module/index.js +64 -0
  19. package/lib/module/index.js.map +1 -0
  20. package/lib/module/logger.js +53 -0
  21. package/lib/module/logger.js.map +1 -0
  22. package/lib/module/package.json +1 -0
  23. package/lib/module/types.js +2 -0
  24. package/lib/module/types.js.map +1 -0
  25. package/lib/typescript/package.json +1 -0
  26. package/lib/typescript/src/AmplitudeEngagement.d.ts +17 -0
  27. package/lib/typescript/src/AmplitudeEngagement.d.ts.map +1 -0
  28. package/lib/typescript/src/AmplitudeEngagementPlugin.d.ts +10 -0
  29. package/lib/typescript/src/AmplitudeEngagementPlugin.d.ts.map +1 -0
  30. package/lib/typescript/src/NativePluginEngagementReactNative.d.ts +18 -0
  31. package/lib/typescript/src/NativePluginEngagementReactNative.d.ts.map +1 -0
  32. package/lib/typescript/src/index.d.ts +13 -0
  33. package/lib/typescript/src/index.d.ts.map +1 -0
  34. package/lib/typescript/src/logger.d.ts +28 -0
  35. package/lib/typescript/src/logger.d.ts.map +1 -0
  36. package/lib/typescript/src/types.d.ts +7 -0
  37. package/lib/typescript/src/types.d.ts.map +1 -0
  38. package/package.json +169 -0
  39. package/src/AmplitudeEngagement.ts +62 -0
  40. package/src/AmplitudeEngagementPlugin.ts +47 -0
  41. package/src/NativePluginEngagementReactNative.ts +28 -0
  42. package/src/index.tsx +78 -0
  43. package/src/logger.ts +72 -0
  44. package/src/types.ts +7 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Amplitude, Inc.
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "PluginEngagementReactNative"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://amplitude.com.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
17
+ s.private_header_files = "ios/**/*.h"
18
+ #s.dependency "AmplitudeEngagementSwift"
19
+ s.dependency "AmplitudeEngagementSwift"
20
+
21
+ install_modules_dependencies(s)
22
+ end
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @amplitude/plugin-engagement-react-native
2
+
3
+ Amplitude Engagement plugin for React Native
4
+
5
+ ## Installation
6
+
7
+ To install:
8
+ - Add `@amplitude/analytics-react-native` and `@amplitude/plugin-engagement-react-native`
9
+ - Also, add `@react-native-async-storage/async-storage`
10
+ - Why? This is used by the `engagement` native module, but the CLI only auto links native modules which you directly depend on in your app’s `package.json`
11
+
12
+
13
+ ```sh
14
+ npm install @amplitude/analytics-react-native
15
+ npm install @amplitude/plugin-engagement-react-native
16
+ npm install @react-native-async-storage/async-storage
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Setup by adding the plugin and calling “init” as usual:
22
+
23
+ ```
24
+ // index.js
25
+
26
+ import {Linking} from 'react-native';
27
+
28
+ import { init, add } from '@amplitude/analytics-react-native';
29
+ import { getPlugin, handleURL } from '@amplitude/plugin-engagement-react-native';
30
+
31
+ init('<<< YOUR API KEY HERE >>>');
32
+ add(getPlugin());
33
+
34
+ Linking.getInitialURL().then(async (url) => {
35
+ if (url) {
36
+ const didHandleURL = await handleURL(url);
37
+ if (didHandleURL) { return; }
38
+
39
+ // Handle a non-Amplitude SDK URL
40
+ }
41
+ });
42
+
43
+ Linking.addEventListener('url', async ({ url }) => {
44
+ const didHandleURL = await handleURL(url);
45
+ if (didHandleURL) { return; }
46
+
47
+ // Handle a non-Amplitude SDK URL
48
+ });
49
+ ```
50
+
51
+ Finally, “boot” with the user’s ID:
52
+
53
+ ```
54
+ import {
55
+ boot
56
+ } from '@amplitude/plugin-engagement-react-native';
57
+
58
+ export default function App() {
59
+ useEffect(() => {
60
+ boot('rn-test-user-1', 'test-device-1');
61
+ }, []);
62
+
63
+ ```
64
+
65
+
66
+ ## License
67
+
68
+ MIT
@@ -0,0 +1,83 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['PluginEngagementReactNative_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+
19
+ apply plugin: "com.android.library"
20
+ apply plugin: "kotlin-android"
21
+
22
+ apply plugin: "com.facebook.react"
23
+
24
+ def getExtOrIntegerDefault(name) {
25
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["PluginEngagementReactNative_" + name]).toInteger()
26
+ }
27
+
28
+ android {
29
+ namespace "com.amplitude.pluginengagementreactnative"
30
+
31
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
+
33
+ defaultConfig {
34
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
+ }
37
+
38
+ buildFeatures {
39
+ buildConfig true
40
+ }
41
+
42
+ buildTypes {
43
+ release {
44
+ minifyEnabled false
45
+ }
46
+ }
47
+
48
+ lintOptions {
49
+ disable "GradleCompatible"
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_1_8
54
+ targetCompatibility JavaVersion.VERSION_1_8
55
+ }
56
+
57
+ sourceSets {
58
+ main {
59
+ java.srcDirs += [
60
+ "generated/java",
61
+ "generated/jni"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+
67
+ repositories {
68
+ mavenCentral()
69
+ google()
70
+ }
71
+
72
+ def kotlin_version = getExtOrDefault("kotlinVersion")
73
+
74
+ dependencies {
75
+ implementation "com.facebook.react:react-android"
76
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
+ }
78
+
79
+ react {
80
+ jsRootDir = file("../src/")
81
+ libraryName = "PluginEngagementReactNative"
82
+ codegenJavaPackageName = "com.amplitude.pluginengagementreactnative"
83
+ }
@@ -0,0 +1,5 @@
1
+ PluginEngagementReactNative_kotlinVersion=2.0.21
2
+ PluginEngagementReactNative_minSdkVersion=24
3
+ PluginEngagementReactNative_targetSdkVersion=34
4
+ PluginEngagementReactNative_compileSdkVersion=35
5
+ PluginEngagementReactNative_ndkVersion=27.1.12297006
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,18 @@
1
+ package com.amplitude.pluginengagementreactnative
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.module.annotations.ReactModule
5
+
6
+ @ReactModule(name = PluginEngagementReactNativeModule.NAME)
7
+ class PluginEngagementReactNativeModule(reactContext: ReactApplicationContext) :
8
+ NativePluginEngagementReactNativeSpec(reactContext) {
9
+
10
+ override fun getName(): String {
11
+ return NAME
12
+ }
13
+
14
+
15
+ companion object {
16
+ const val NAME = "PluginEngagementReactNative"
17
+ }
18
+ }
@@ -0,0 +1,33 @@
1
+ package com.amplitude.pluginengagementreactnative
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import java.util.HashMap
9
+
10
+ class PluginEngagementReactNativePackage : BaseReactPackage() {
11
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
+ return if (name == PluginEngagementReactNativeModule.NAME) {
13
+ PluginEngagementReactNativeModule(reactContext)
14
+ } else {
15
+ null
16
+ }
17
+ }
18
+
19
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20
+ return ReactModuleInfoProvider {
21
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
+ moduleInfos[PluginEngagementReactNativeModule.NAME] = ReactModuleInfo(
23
+ PluginEngagementReactNativeModule.NAME,
24
+ PluginEngagementReactNativeModule.NAME,
25
+ false, // canOverrideExistingModule
26
+ false, // needsEagerInit
27
+ false, // isCxxModule
28
+ true // isTurboModule
29
+ )
30
+ moduleInfos
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,121 @@
1
+ //
2
+ // AmplitudeEngagementAdapter.swift
3
+ // PluginEngagementReactNative
4
+ //
5
+ // Created by Jared Luxenberg on 5/19/25.
6
+ //
7
+
8
+ import Foundation
9
+ import AmplitudeEngagementSwift
10
+
11
+
12
+ extension Encodable {
13
+ /// Converting object to postable dictionary
14
+ func toDictionary(_ encoder: JSONEncoder = JSONEncoder()) throws -> [String: Any] {
15
+ let data = try encoder.encode(self)
16
+ let object = try JSONSerialization.jsonObject(with: data)
17
+ if let json = object as? [String: Any] { return json }
18
+
19
+ let context = DecodingError.Context(codingPath: [], debugDescription: "Deserialized object is not a dictionary")
20
+ throw DecodingError.typeMismatch(type(of: object), context)
21
+ }
22
+ }
23
+
24
+ // id -> (api_key, amplitude engagement instance)
25
+ var instances: [Int: (String, AmplitudeEngagement)] = [:]
26
+ var _id = 0
27
+
28
+ /** `@objc` attribute exposes Swift methods to the Objective-C runtime**/
29
+ @objc public class AmplitudeEngagementAdapter: NSObject {
30
+ @objc public func newInstance(_ apiKey: String) -> Int {
31
+ if let existingId = instances.first(where: { $0.value.0 == apiKey })?.key {
32
+ return existingId
33
+ }
34
+
35
+ return DispatchQueue.main.sync {
36
+ _id += 1;
37
+ let id = _id + 1;
38
+ instances[id] = (apiKey, AmplitudeEngagement(apiKey, AmplitudeInitOptions(logLevel: AmplitudeLogLevel.verbose)))
39
+ return id
40
+ }
41
+ }
42
+
43
+
44
+ @objc public func boot(_ instanceId: Int, _ user_id: String, device_id: String? = nil) {
45
+ DispatchQueue.main.sync {
46
+ guard let (_, instance) = instances[instanceId] else { return }
47
+
48
+ return instance.boot(user_id, device_id: device_id)
49
+ }
50
+ }
51
+
52
+ @objc public func setThemeMode(_ instanceId: Int, themeMode: String) {
53
+ DispatchQueue.main.sync {
54
+ guard let (_, instance) = instances[instanceId] else { fatalError("🚨 Runtime exception: no instance found for id “\(instanceId)”") }
55
+ guard let themeModeParsed = ThemeMode(rawValue: themeMode) else { return }
56
+
57
+ return instance.setThemeMode(themeMode: themeModeParsed)
58
+ }
59
+ }
60
+
61
+ @objc public func reset(_ instanceId: Int, key: String, stepIndex: Int = 0) {
62
+ DispatchQueue.main.sync {
63
+ guard let (_, instance) = instances[instanceId] else { fatalError("🚨 Runtime exception: no instance found for id “\(instanceId)”") }
64
+
65
+ return instance.reset(key: key, stepIndex: stepIndex)
66
+ }
67
+ }
68
+
69
+ @objc public func list(_ instanceId: Int) -> [[String: Any]] {
70
+ DispatchQueue.main.sync {
71
+ guard let (_, instance) = instances[instanceId] else { fatalError("🚨 Runtime exception: no instance found for id “\(instanceId)”") }
72
+
73
+ return instance.list().compactMap { x in try? x.toDictionary() }
74
+ }
75
+ }
76
+
77
+ @objc public func handleUrl(_ instanceId: Int, _ url: String) -> Bool {
78
+ DispatchQueue.main.sync {
79
+ guard let (_, instance) = instances[instanceId] else { fatalError("🚨 Runtime exception: no instance found for id “\(instanceId)”") }
80
+ guard let url = URL(string: url) else { return false; }
81
+
82
+ return instance.handleUrl(url)
83
+ }
84
+ }
85
+
86
+ @objc public func show(_ instanceId: Int, key: String, stepIndex: Int = 0) {
87
+ DispatchQueue.main.sync {
88
+ guard let (_, instance) = instances[instanceId] else { fatalError("🚨 Runtime exception: no instance found for id “\(instanceId)”") }
89
+ return instance.show(key: key, stepIndex: stepIndex)
90
+ }
91
+ }
92
+
93
+ @objc public func screen(_ instanceId: Int, _ screenName: String) {
94
+ DispatchQueue.main.sync {
95
+ guard let (_, instance) = instances[instanceId] else { fatalError("🚨 Runtime exception: no instance found for id “\(instanceId)”") }
96
+ return instance.screen(screenName)
97
+ }
98
+ }
99
+
100
+ @objc public func closeAll(_ instanceId: Int) {
101
+ DispatchQueue.main.sync {
102
+ guard let (_, instance) = instances[instanceId] else { fatalError("🚨 Runtime exception: no instance found for id “\(instanceId)”") }
103
+ return instance.closeAll()
104
+ }
105
+ }
106
+
107
+ @objc public func forwardEvent(_ instanceId: Int, _ event: [String: Any]) {
108
+ DispatchQueue.main.sync {
109
+ guard let (_, instance) = instances[instanceId] else { fatalError("🚨 Runtime exception: no instance found for id “\(instanceId)”") }
110
+ return instance.forwardEvent(event)
111
+ }
112
+ }
113
+
114
+ @objc(addCallback:::) public func addCallback(_ instanceId: Int, _ key: String, _ function: @escaping () -> Void) {
115
+ DispatchQueue.main.sync {
116
+ guard let (_, instance) = instances[instanceId] else { fatalError("🚨 Runtime exception: no instance found for id “\(instanceId)”") }
117
+ return instance.addCallback(key, function)
118
+ }
119
+ }
120
+
121
+ }
@@ -0,0 +1,5 @@
1
+ #import <PluginEngagementReactNativeSpec/PluginEngagementReactNativeSpec.h>
2
+
3
+ @interface PluginEngagementReactNative : NSObject <NativePluginEngagementReactNativeSpec>
4
+
5
+ @end
@@ -0,0 +1,87 @@
1
+ #import "PluginEngagementReactNative.h"
2
+ #import "PluginEngagementReactNative-Swift.h"
3
+
4
+ //@interface RCT_EXTERN_MODULE(AmplitudeEngagementAdapter, NSObject)
5
+
6
+ @implementation PluginEngagementReactNative {
7
+ AmplitudeEngagementAdapter *adapter;
8
+ }
9
+ //RCT_EXPORT_MODULE()
10
+
11
+
12
+ - (id) init {
13
+ if (self = [super init]) {
14
+ adapter = [AmplitudeEngagementAdapter new];
15
+ }
16
+ return self;
17
+ }
18
+
19
+ // TODO: binding for AmplitudeEngagement here
20
+
21
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
22
+ (const facebook::react::ObjCTurboModule::InitParams &)params
23
+ {
24
+ return std::make_shared<facebook::react::NativePluginEngagementReactNativeSpecJSI>(params);
25
+ }
26
+
27
+ + (NSString *)moduleName {
28
+ return @"PluginEngagementReactNative";
29
+ }
30
+
31
+ - (void)boot:(double)id user_id:(nonnull NSString *)user_id device_id:(nonnull NSString *)device_id {
32
+ [adapter boot:id :user_id device_id:device_id];
33
+ }
34
+
35
+ - (nonnull NSArray<NSDictionary *> *)list:(double)id {
36
+ return [adapter list:id];
37
+ }
38
+
39
+ - (NSNumber *)newInstance:(nonnull NSString *)apiKey {
40
+ return @([adapter newInstance:apiKey]);
41
+ }
42
+
43
+ - (NSNumber*)handleURL:(double)id url:(NSString *)url {
44
+ BOOL success = [adapter handleUrl:id :url];
45
+ return @(success);
46
+ }
47
+
48
+ - (void)addCallback:(double)id key:(nonnull NSString *)key func:(nonnull RCTResponseSenderBlock)func {
49
+ RCTResponseSenderBlock jsCallback = func;
50
+ void (^callback)(void) = ^{
51
+ jsCallback(@[]); // or pass whatever args you need
52
+ };
53
+
54
+ [adapter addCallback:id :key :callback];
55
+ }
56
+
57
+
58
+ - (void)closeAll:(double)id {
59
+ [adapter closeAll:id];
60
+ }
61
+
62
+
63
+ - (void)forwardEvent:(double)id event:(nonnull NSDictionary *)event {
64
+ [adapter forwardEvent:id :event];
65
+ }
66
+
67
+
68
+ - (void)reset:(double)id key:(nonnull NSString *)key stepIndex:(double)stepIndex {
69
+ [adapter reset:id key:key stepIndex:stepIndex];
70
+ }
71
+
72
+
73
+ - (void)screen:(double)id screenName:(nonnull NSString *)screenName {
74
+ [adapter screen:id :screenName];
75
+ }
76
+
77
+
78
+ - (void)setThemeMode:(double)id themeMode:(nonnull NSString *)themeMode {
79
+ [adapter setThemeMode:id themeMode:themeMode];
80
+ }
81
+
82
+
83
+ - (void)show:(double)id key:(nonnull NSString *)key stepIndex:(double)stepIndex {
84
+ [adapter show:id key:key stepIndex:stepIndex];
85
+ }
86
+
87
+ @end
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ import { NativeModules } from 'react-native';
4
+ const isTurboModuleEnabled = global.__turboModuleProxy != null;
5
+ const PluginEngagementReactNative = isTurboModuleEnabled ? require('./NativePluginEngagementReactNative').default : NativeModules.PluginEngagementReactNative;
6
+ export class AmplitudeEngagement {
7
+ constructor(apiKey) {
8
+ // Initialize the plugin with the API key
9
+ this.id = PluginEngagementReactNative.newInstance(apiKey);
10
+ }
11
+ boot(user_id, device_id) {
12
+ PluginEngagementReactNative.boot(this.id, user_id, device_id);
13
+ }
14
+ setThemeMode(themeMode) {
15
+ return PluginEngagementReactNative.setThemeMode(this.id, themeMode);
16
+ }
17
+ reset(key, stepIndex) {
18
+ return PluginEngagementReactNative.reset(this.id, key, stepIndex);
19
+ }
20
+ list() {
21
+ return PluginEngagementReactNative.list(this.id);
22
+ }
23
+ show(key, stepIndex) {
24
+ return PluginEngagementReactNative.show(this.id, key, stepIndex);
25
+ }
26
+ screen(screenName) {
27
+ return PluginEngagementReactNative.screen(this.id, screenName);
28
+ }
29
+ closeAll() {
30
+ return PluginEngagementReactNative.closeAll(this.id);
31
+ }
32
+ forwardEvent(event) {
33
+ return PluginEngagementReactNative.forwardEvent(this.id, event);
34
+ }
35
+ addCallback(key, func) {
36
+ return PluginEngagementReactNative.addCallback(this.id, key, func);
37
+ }
38
+ handleURL(url) {
39
+ return PluginEngagementReactNative.handleURL(this.id, url);
40
+ }
41
+ }
42
+ //# sourceMappingURL=AmplitudeEngagement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeModules","isTurboModuleEnabled","global","__turboModuleProxy","PluginEngagementReactNative","require","default","AmplitudeEngagement","constructor","apiKey","id","newInstance","boot","user_id","device_id","setThemeMode","themeMode","reset","key","stepIndex","list","show","screen","screenName","closeAll","forwardEvent","event","addCallback","func","handleURL","url"],"sourceRoot":"../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AAC,IAAI,CAACd,EAAE,CAAC;EACtD;EAEAe,YAAYA,CAACC,KAAgB,EAAQ;IACnC,OAAOtB,2BAA2B,CAACqB,YAAY,CAAC,IAAI,CAACf,EAAE,EAAEgB,KAAK,CAAC;EACjE;EAEAC,WAAWA,CAACT,GAAW,EAAEU,IAAgB,EAAQ;IAC/C,OAAOxB,2BAA2B,CAACuB,WAAW,CAAC,IAAI,CAACjB,EAAE,EAAEQ,GAAG,EAAEU,IAAI,CAAC;EACpE;EAEAC,SAASA,CAACC,GAAW,EAAW;IAC9B,OAAO1B,2BAA2B,CAACyB,SAAS,CAAC,IAAI,CAACnB,EAAE,EAAEoB,GAAG,CAAC;EAC5D;AACF","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ import { forwardEvent, init, screen } from "./index.js";
4
+ import { Logger } from "./logger.js";
5
+ export class AmplitudeEngagementPlugin {
6
+ name = 'AmplitudeEngagementPlugin';
7
+ type = 'enrichment';
8
+ logger = new Logger('AmplitudeEngagementPlugin');
9
+ async setup(config, _client) {
10
+ try {
11
+ console.log('initializing with apiKey', config.apiKey);
12
+ init(config.apiKey);
13
+ } catch (error) {
14
+ this.logger.error('AmplitudeEngagementPlugin#setup failed to initialize', error);
15
+ }
16
+
17
+ // TODO: call "boot" here -- but we don't have the user_id and device_id yet so we cannot
18
+ }
19
+ async execute(context) {
20
+ console.log(`AmplitudeEngagement#execute event=${JSON.stringify(context)}`);
21
+ if (context.event_type === '[Amplitude] Screen Viewed' && typeof context.event_properties?.['[Amplitude] Screen Name'] === 'string') {
22
+ const screenName = context.event_properties['[Amplitude] Screen Name'];
23
+ screen(screenName);
24
+ }
25
+ forwardEvent(context);
26
+ return context;
27
+ }
28
+ }
29
+ //# sourceMappingURL=AmplitudeEngagementPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["forwardEvent","init","screen","Logger","AmplitudeEngagementPlugin","name","type","logger","setup","config","_client","console","log","apiKey","error","execute","context","JSON","stringify","event_type","event_properties","screenName"],"sourceRoot":"../../src","sources":["AmplitudeEngagementPlugin.ts"],"mappings":";;AAMA,SAASA,YAAY,EAAEC,IAAI,EAAEC,MAAM,QAAQ,YAAG;AAC9C,SAASC,MAAM,QAA8B,aAAU;AAEvD,OAAO,MAAMC,yBAAyB,CAA6B;EACjEC,IAAI,GAAG,2BAA2B;EAClCC,IAAI,GAAG,YAAY;EAEnBC,MAAM,GAAoB,IAAIJ,MAAM,CAAC,2BAA2B,CAAC;EAEjE,MAAMK,KAAKA,CAACC,MAAc,EAAEC,OAAmB,EAAiB;IAC9D,IAAI;MACFC,OAAO,CAACC,GAAG,CAAC,0BAA0B,EAAEH,MAAM,CAACI,MAAM,CAAC;MACtDZ,IAAI,CAACQ,MAAM,CAACI,MAAM,CAAC;IACrB,CAAC,CAAC,OAAOC,KAAK,EAAE;MACd,IAAI,CAACP,MAAM,CAACO,KAAK,CACf,sDAAsD,EACtDA,KACF,CAAC;IACH;;IAEA;EACF;EAEA,MAAMC,OAAOA,CAACC,OAAc,EAAyB;IACnDL,OAAO,CAACC,GAAG,CAAC,qCAAqCK,IAAI,CAACC,SAAS,CAACF,OAAO,CAAC,EAAE,CAAC;IAE3E,IACEA,OAAO,CAACG,UAAU,KAAK,2BAA2B,IAClD,OAAOH,OAAO,CAACI,gBAAgB,GAAG,yBAAyB,CAAC,KAAK,QAAQ,EACzE;MACA,MAAMC,UAAU,GAAGL,OAAO,CAACI,gBAAgB,CACzC,yBAAyB,CAChB;MACXlB,MAAM,CAACmB,UAAU,CAAC;IACpB;IAEArB,YAAY,CAACgB,OAAO,CAAC;IAErB,OAAOA,OAAO;EAChB;AACF","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('PluginEngagementReactNative');
5
+ //# sourceMappingURL=NativePluginEngagementReactNative.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativePluginEngagementReactNative.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAwBlD,eAAeA,mBAAmB,CAACC,YAAY,CAC7C,6BACF,CAAC","ignoreList":[]}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ import { AmplitudeEngagement } from "./AmplitudeEngagement.js";
4
+ import { AmplitudeEngagementPlugin } from "./AmplitudeEngagementPlugin.js";
5
+ let globalEngagement = null;
6
+ let toNotify = [];
7
+ async function getGlobalEngagement() {
8
+ if (globalEngagement) {
9
+ return globalEngagement;
10
+ } else {
11
+ return await new Promise((resolve, _reject) => {
12
+ toNotify.push(engagement => {
13
+ resolve(engagement);
14
+ });
15
+ });
16
+ }
17
+ }
18
+ export function init(apiKey) {
19
+ // Initialize the plugin with the API key
20
+ if (globalEngagement) {
21
+ throw new Error('AmplitudeEngagement already initialized');
22
+ }
23
+ globalEngagement = new AmplitudeEngagement(apiKey);
24
+ toNotify.forEach(callback => {
25
+ callback(globalEngagement);
26
+ });
27
+ toNotify = [];
28
+ }
29
+ export async function boot(user_id, device_id) {
30
+ const e = await getGlobalEngagement();
31
+ return e.boot(user_id, device_id);
32
+ }
33
+ export async function list() {
34
+ const e = await getGlobalEngagement();
35
+ return e.list();
36
+ }
37
+ export async function show(key, stepIndex) {
38
+ const e = await getGlobalEngagement();
39
+ return e.show(key, stepIndex);
40
+ }
41
+ export async function screen(screenName) {
42
+ const e = await getGlobalEngagement();
43
+ return e.screen(screenName);
44
+ }
45
+ export async function closeAll() {
46
+ const e = await getGlobalEngagement();
47
+ return e.closeAll();
48
+ }
49
+ export async function forwardEvent(event) {
50
+ const e = await getGlobalEngagement();
51
+ return e.forwardEvent(event);
52
+ }
53
+ export async function addCallback(key, func) {
54
+ const e = await getGlobalEngagement();
55
+ return e.addCallback(key, func);
56
+ }
57
+ export async function handleURL(url) {
58
+ const e = await getGlobalEngagement();
59
+ return e.handleURL(url);
60
+ }
61
+ export function getPlugin() {
62
+ return new AmplitudeEngagementPlugin();
63
+ }
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AmplitudeEngagement","AmplitudeEngagementPlugin","globalEngagement","toNotify","getGlobalEngagement","Promise","resolve","_reject","push","engagement","init","apiKey","Error","forEach","callback","boot","user_id","device_id","e","list","show","key","stepIndex","screen","screenName","closeAll","forwardEvent","event","addCallback","func","handleURL","url","getPlugin"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,mBAAmB,QAAQ,0BAAuB;AAC3D,SAASC,yBAAyB,QAAQ,gCAA6B;AAIvE,IAAIC,gBAAqC,GAAG,IAAW;AACvD,IAAIC,QAAuD,GAAG,EAAE;AAEhE,eAAeC,mBAAmBA,CAAA,EAAiC;EACjE,IAAIF,gBAAgB,EAAE;IACpB,OAAOA,gBAAgB;EACzB,CAAC,MAAM;IACL,OAAO,MAAM,IAAIG,OAAO,CAAC,CAACC,OAAO,EAAEC,OAAO,KAAK;MAC7CJ,QAAQ,CAACK,IAAI,CAAEC,UAAU,IAAK;QAC5BH,OAAO,CAACG,UAAU,CAAC;MACrB,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ;AACF;AAEA,OAAO,SAASC,IAAIA,CAACC,MAAc,EAAQ;EACzC;EACA,IAAIT,gBAAgB,EAAE;IACpB,MAAM,IAAIU,KAAK,CAAC,yCAAyC,CAAC;EAC5D;EACAV,gBAAgB,GAAG,IAAIF,mBAAmB,CAACW,MAAM,CAAC;EAClDR,QAAQ,CAACU,OAAO,CAAEC,QAAQ,IAAK;IAC7BA,QAAQ,CAACZ,gBAAgB,CAAC;EAC5B,CAAC,CAAC;EACFC,QAAQ,GAAG,EAAE;AACf;AAEA,OAAO,eAAeY,IAAIA,CAACC,OAAe,EAAEC,SAAiB,EAAiB;EAC5E,MAAMC,CAAC,GAAG,MAAMd,mBAAmB,CAAC,CAAC;EACrC,OAAOc,CAAC,CAACH,IAAI,CAAC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