From 45c071bbaea0ff0d235d16d4ba5ebaa939ba3c6d Mon Sep 17 00:00:00 2001 From: Ulrich GIBERNE Date: Thu, 28 Mar 2024 12:51:31 -0400 Subject: [PATCH 1/7] replace actionRun Object type with JsonValue --- .../urbanairship/reactnative/AirshipModule.kt | 4 +-- .../urbanairship/reactnative/AirshipSpec.kt | 2 +- example/ios/Podfile.lock | 4 +-- example/src/App.tsx | 29 +++++++++++++++++++ package-lock.json | 4 +-- src/NativeRTNAirship.ts | 3 +- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt b/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt index 76e01645..16d6878f 100644 --- a/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt +++ b/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt @@ -455,9 +455,9 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) : } @ReactMethod - override fun actionRun(name: String?, value: ReadableMap?, promise: Promise) { + override fun actionRun(name: String?, value: Dynamic?, promise: Promise) { promise.resolveDeferred { callback -> - proxy.actions.runAction(requireNotNull(name), Utils.convertMap(value).toJsonValue()) + proxy.actions.runAction(requireNotNull(name), Utils.convertDynamic(value)) .addResultCallback { actionResult -> if (actionResult != null && actionResult.status == ActionResult.STATUS_COMPLETED) { callback(actionResult.value, null) diff --git a/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt b/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt index cb6454e0..960c766d 100644 --- a/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt +++ b/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt @@ -241,7 +241,7 @@ abstract class AirshipSpec internal constructor(context: ReactApplicationContext @com.facebook.proguard.annotations.DoNotStrip abstract fun actionRun( name: String?, - value: ReadableMap?, + value: Dynamic?, promise: Promise ) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index d4d83fb0..ab9ed198 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -964,7 +964,7 @@ PODS: - React-Mapbuffer (0.73.4): - glog - React-debug - - react-native-airship (17.2.0): + - react-native-airship (17.2.1): - AirshipFrameworkProxy (= 5.1.1) - glog - RCT-Folly (= 2022.05.16.00) @@ -1407,7 +1407,7 @@ SPEC CHECKSUMS: React-jsinspector: 9ac353eccf6ab54d1e0a33862ba91221d1e88460 React-logger: 0a57b68dd2aec7ff738195f081f0520724b35dab React-Mapbuffer: 63913773ed7f96b814a2521e13e6d010282096ad - react-native-airship: ba50cd2630247d4896f65d6aeb9d7e94ec93ee08 + react-native-airship: 876b0976076f1f85a8dc3722669db2702accfe68 react-native-safe-area-context: b97eb6f9e3b7f437806c2ce5983f479f8eb5de4b React-nativeconfig: d7af5bae6da70fa15ce44f045621cf99ed24087c React-NativeModulesApple: 0123905d5699853ac68519607555a9a4f5c7b3ac diff --git a/example/src/App.tsx b/example/src/App.tsx index d31cf057..c3cce7d2 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -8,11 +8,40 @@ import MessageCenterScreen from './screens/MessageCenterScreen'; import MessageScreen from './screens/MessageScreen'; import PreferenceCenterScreen from './screens/PreferenceCenterScreen'; import Airship, { EventType } from '@ua/react-native-airship'; +import { CustomEvent } from '@ua/react-native-airship'; import MaterialIcons from 'react-native-vector-icons/MaterialIcons'; const Tab = createBottomTabNavigator(); const MessageCenterStack = createStackNavigator(); +Airship.takeOff({ + default: { + appKey: "VWDwdOFjRTKLRxCeXTVP6g", + appSecret: "5Ifi5rYgTm2QHey9JkP0WA", + logLevel: "verbose" + }, + site: "us", // use "eu" for EU cloud projects + urlAllowList: ["*"], + android: { + notificationConfig: { + icon: "ic_notification", + accentColor: "#00ff00" + } + } +}); + +var customEvent = new CustomEvent("event_name", 123.12); +customEvent.addProperty("my_custom_property", "some custom value"); +customEvent.addProperty("is_neat", true); +customEvent.addProperty("any_json", { + "foo": "bar" +}); +Airship.analytics.addCustomEvent(customEvent); + + +var url: string = "ulrich://some-deep-link" +Airship.actions.run("deep_link_action", url); + Airship.addListener(EventType.NotificationResponse, (event) => { console.log('NotificationResponse:', JSON.stringify(event)); }); diff --git a/package-lock.json b/package-lock.json index 774ba481..260b1e4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ua/react-native-airship", - "version": "17.2.0", + "version": "17.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ua/react-native-airship", - "version": "17.2.0", + "version": "17.2.1", "license": "Apache-2.0", "devDependencies": { "@commitlint/config-conventional": "^17.0.2", diff --git a/src/NativeRTNAirship.ts b/src/NativeRTNAirship.ts index c29c28c3..2807d9ba 100644 --- a/src/NativeRTNAirship.ts +++ b/src/NativeRTNAirship.ts @@ -1,5 +1,6 @@ import type { TurboModule } from 'react-native'; import { TurboModuleRegistry } from 'react-native'; +import { JsonValue } from './types'; export interface Spec extends TurboModule { // Airship @@ -68,7 +69,7 @@ export interface Spec extends TurboModule { analyticsAssociateIdentifier(key: string, identifier?: string): Promise; // Action - actionRun(name: string, value?: Object): Promise; + actionRun(name: string, value?: JsonValue): Promise; // Privacy Manager privacyManagerSetEnabledFeatures(features: string[]): Promise; From 7cc69e7d4d5642067d795a6966c1578aec96edaa Mon Sep 17 00:00:00 2001 From: Ulrich GIBERNE Date: Fri, 5 Apr 2024 16:56:45 -0400 Subject: [PATCH 2/7] fix Airship Actions running --- .../urbanairship/reactnative/AirshipModule.kt | 4 +-- .../urbanairship/reactnative/AirshipSpec.kt | 3 +- example/src/App.tsx | 29 ---------------- ios/AirshipReactNative.swift | 6 ++-- ios/RTNAirship.mm | 5 ++- src/Action.ts | 34 +++++++++++++++++++ src/AirshipActions.ts | 9 +++-- src/AirshipAnalytics.ts | 10 ++---- src/CustomEvent.ts | 18 ++++++++++ src/NativeRTNAirship.ts | 3 +- src/index.tsx | 1 + 11 files changed, 69 insertions(+), 53 deletions(-) create mode 100644 src/Action.ts diff --git a/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt b/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt index 16d6878f..e99ee1ed 100644 --- a/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt +++ b/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt @@ -455,9 +455,9 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) : } @ReactMethod - override fun actionRun(name: String?, value: Dynamic?, promise: Promise) { + override fun actionRun(action: ReadableMap, promise: Promise) { promise.resolveDeferred { callback -> - proxy.actions.runAction(requireNotNull(name), Utils.convertDynamic(value)) + proxy.actions.runAction(requireNotNull(action.getString("_name")), Utils.convertDynamic(action.getDynamic("_value"))) .addResultCallback { actionResult -> if (actionResult != null && actionResult.status == ActionResult.STATUS_COMPLETED) { callback(actionResult.value, null) diff --git a/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt b/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt index 960c766d..5c4bfadd 100644 --- a/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt +++ b/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt @@ -240,8 +240,7 @@ abstract class AirshipSpec internal constructor(context: ReactApplicationContext @ReactMethod @com.facebook.proguard.annotations.DoNotStrip abstract fun actionRun( - name: String?, - value: Dynamic?, + action: ReadableMap, promise: Promise ) diff --git a/example/src/App.tsx b/example/src/App.tsx index c3cce7d2..d31cf057 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -8,40 +8,11 @@ import MessageCenterScreen from './screens/MessageCenterScreen'; import MessageScreen from './screens/MessageScreen'; import PreferenceCenterScreen from './screens/PreferenceCenterScreen'; import Airship, { EventType } from '@ua/react-native-airship'; -import { CustomEvent } from '@ua/react-native-airship'; import MaterialIcons from 'react-native-vector-icons/MaterialIcons'; const Tab = createBottomTabNavigator(); const MessageCenterStack = createStackNavigator(); -Airship.takeOff({ - default: { - appKey: "VWDwdOFjRTKLRxCeXTVP6g", - appSecret: "5Ifi5rYgTm2QHey9JkP0WA", - logLevel: "verbose" - }, - site: "us", // use "eu" for EU cloud projects - urlAllowList: ["*"], - android: { - notificationConfig: { - icon: "ic_notification", - accentColor: "#00ff00" - } - } -}); - -var customEvent = new CustomEvent("event_name", 123.12); -customEvent.addProperty("my_custom_property", "some custom value"); -customEvent.addProperty("is_neat", true); -customEvent.addProperty("any_json", { - "foo": "bar" -}); -Airship.analytics.addCustomEvent(customEvent); - - -var url: string = "ulrich://some-deep-link" -Airship.actions.run("deep_link_action", url); - Airship.addListener(EventType.NotificationResponse, (event) => { console.log('NotificationResponse:', JSON.stringify(event)); }); diff --git a/ios/AirshipReactNative.swift b/ios/AirshipReactNative.swift index 453bd7cd..2fd6494c 100644 --- a/ios/AirshipReactNative.swift +++ b/ios/AirshipReactNative.swift @@ -328,10 +328,10 @@ public extension AirshipReactNative { // Actions @objc public extension AirshipReactNative { - func actionsRun(actionName: String, actionValue: Any?) async throws-> Any? { + func actionsRun(action: [String: Any]) async throws-> Any? { return try await AirshipProxy.shared.action.runAction( - actionName, - value: try AirshipJSON.wrap(actionValue) + action["_name"] as! String, + value: action["_value"] is NSNull ? nil : try AirshipJSON.wrap(action["_value"]) ) } } diff --git a/ios/RTNAirship.mm b/ios/RTNAirship.mm index 2d4d7a2a..f45e0cf4 100644 --- a/ios/RTNAirship.mm +++ b/ios/RTNAirship.mm @@ -336,11 +336,10 @@ + (BOOL)requiresMainQueueSetup { } RCT_REMAP_METHOD(actionRun, - actionRun:(NSString *)name value:(NSDictionary *)value + actionRun:(NSDictionary *)action resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) { - [AirshipReactNative.shared actionsRunWithActionName:name - actionValue:value + [AirshipReactNative.shared actionsRunWithAction:action completionHandler:^(id result , NSError *error) { diff --git a/src/Action.ts b/src/Action.ts new file mode 100644 index 00000000..bec53369 --- /dev/null +++ b/src/Action.ts @@ -0,0 +1,34 @@ +/* Copyright Airship and Contributors */ + +'use strict'; + +import { JsonValue } from './types'; + +/** + * Airship Action Object. + * This is used to encapsulate the Action name and the Action value. + */ +export class Action { + _name: string; + _value?: JsonValue; + + /** + * Airship Action constructor. + * + * @param name The action name. + * @param value The action value. + */ + constructor(name: string, value?: JsonValue) { + this._name = name; + this._value = value; + } + + /** + * Sets the action value. + * + * @param value The action value. + */ + setValue(value?: JsonValue) { + this._value = value; + } +} \ No newline at end of file diff --git a/src/AirshipActions.ts b/src/AirshipActions.ts index 6004373e..9b9af7b3 100644 --- a/src/AirshipActions.ts +++ b/src/AirshipActions.ts @@ -1,4 +1,5 @@ import { JsonValue } from './types'; +import { Action } from './Action'; /** * Airship actions. @@ -9,15 +10,13 @@ export class AirshipActions { /** * Runs an Airship action. * - * @param name The name of the action. - * @param value The action's value. + * @param action The Airship Action. * @return A promise that returns the action result if the action * successfully runs, or the Error if the action was unable to be run. */ public run( - actionName: string, - actionValue?: JsonValue + action: Action ): Promise { - return this.module.actionRun(actionName, actionValue); + return this.module.actionRun(action); } } diff --git a/src/AirshipAnalytics.ts b/src/AirshipAnalytics.ts index ee8e0c76..a9f0d994 100644 --- a/src/AirshipAnalytics.ts +++ b/src/AirshipAnalytics.ts @@ -1,3 +1,4 @@ +import { Action } from "./Action"; import { CustomEvent } from "./CustomEvent"; /** @@ -33,15 +34,10 @@ export class AirshipAnalytics { * custom event is rejected. */ public addCustomEvent(event: CustomEvent): Promise { - const actionArg = { - event_name: event._name, - event_value: event._value, - transaction_id: event._transactionId, - properties: event._properties - } + let action = new Action("add_custom_event_action", event.toJsonValue()) return new Promise((resolve, reject) => { - this.module.actionRun("add_custom_event_action", actionArg).then(() => { + this.module.actionRun(action).then(() => { resolve(null) }, (error: Error) => { reject(error) diff --git a/src/CustomEvent.ts b/src/CustomEvent.ts index 59321386..dae94dbb 100644 --- a/src/CustomEvent.ts +++ b/src/CustomEvent.ts @@ -48,4 +48,22 @@ export class CustomEvent { addProperty(name: string, value: JsonValue) { this._properties[name] = value; } + + /** + * Converts a CustomEvent into a JsonValue. + * + * @returns A JsonValue. + */ + toJsonValue(): JsonValue { + let jsonObject: JsonObject = {}; + jsonObject.event_name = this._name; + if (this._value) { + jsonObject.event_value = this._value; + } + jsonObject.properties = this._properties; + if (this._transactionId) { + jsonObject.transaction_id = this._transactionId; + } + return jsonObject; + } } diff --git a/src/NativeRTNAirship.ts b/src/NativeRTNAirship.ts index 2807d9ba..45e36a40 100644 --- a/src/NativeRTNAirship.ts +++ b/src/NativeRTNAirship.ts @@ -1,6 +1,5 @@ import type { TurboModule } from 'react-native'; import { TurboModuleRegistry } from 'react-native'; -import { JsonValue } from './types'; export interface Spec extends TurboModule { // Airship @@ -69,7 +68,7 @@ export interface Spec extends TurboModule { analyticsAssociateIdentifier(key: string, identifier?: string): Promise; // Action - actionRun(name: string, value?: JsonValue): Promise; + actionRun(action: Object): Promise; // Privacy Manager privacyManagerSetEnabledFeatures(features: string[]): Promise; diff --git a/src/index.tsx b/src/index.tsx index 4c9483be..1bf77bd3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -19,6 +19,7 @@ export { SubscriptionListEditor } from './SubscriptionListEditor'; export { TagGroupEditor } from './TagGroupEditor'; export { ScopedSubscriptionListEditor } from './ScopedSubscriptionListEditor'; export { AttributeEditor } from './AttributeEditor'; +export { Action } from './Action'; export * from './types'; export * from './MessageView'; From 46bd345ff08f4b634c8f64dafd127a46dd40ec8a Mon Sep 17 00:00:00 2001 From: Ulrich GIBERNE Date: Mon, 8 Apr 2024 13:53:45 -0400 Subject: [PATCH 3/7] simplify and use proxy addEvent call --- .../urbanairship/reactnative/AirshipModule.kt | 9 +++- .../urbanairship/reactnative/AirshipSpec.kt | 7 ++++ ios/AirshipReactNative.swift | 8 +++- ios/RTNAirship.mm | 11 +++++ src/Action.ts | 34 --------------- src/AirshipActions.ts | 9 ++-- src/AirshipAnalytics.ts | 13 +----- src/CustomEvent.ts | 42 +++++++++++++++++-- src/NativeRTNAirship.ts | 1 + src/index.tsx | 1 - 10 files changed, 79 insertions(+), 56 deletions(-) delete mode 100644 src/Action.ts diff --git a/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt b/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt index e99ee1ed..1432ed94 100644 --- a/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt +++ b/android/src/main/java/com/urbanairship/reactnative/AirshipModule.kt @@ -454,10 +454,17 @@ class AirshipModule internal constructor(val context: ReactApplicationContext) : } } + @ReactMethod + override fun addCustomEvent(event: ReadableMap?, promise: Promise) { + promise.resolveResult { + proxy.analytics.addEvent(Utils.convertMap(event).toJsonValue()) + } + } + @ReactMethod override fun actionRun(action: ReadableMap, promise: Promise) { promise.resolveDeferred { callback -> - proxy.actions.runAction(requireNotNull(action.getString("_name")), Utils.convertDynamic(action.getDynamic("_value"))) + proxy.actions.runAction(requireNotNull(action.getString("name")), Utils.convertDynamic(action.getDynamic("value"))) .addResultCallback { actionResult -> if (actionResult != null && actionResult.status == ActionResult.STATUS_COMPLETED) { callback(actionResult.value, null) diff --git a/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt b/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt index 5c4bfadd..99de0ebd 100644 --- a/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt +++ b/android/src/oldarch/java/com/urbanairship/reactnative/AirshipSpec.kt @@ -237,6 +237,13 @@ abstract class AirshipSpec internal constructor(context: ReactApplicationContext promise: Promise ) + @ReactMethod + @com.facebook.proguard.annotations.DoNotStrip + abstract fun addCustomEvent( + event: ReadableMap?, + promise: Promise + ) + @ReactMethod @com.facebook.proguard.annotations.DoNotStrip abstract fun actionRun( diff --git a/ios/AirshipReactNative.swift b/ios/AirshipReactNative.swift index 2fd6494c..0b87427f 100644 --- a/ios/AirshipReactNative.swift +++ b/ios/AirshipReactNative.swift @@ -330,8 +330,8 @@ public extension AirshipReactNative { public extension AirshipReactNative { func actionsRun(action: [String: Any]) async throws-> Any? { return try await AirshipProxy.shared.action.runAction( - action["_name"] as! String, - value: action["_value"] is NSNull ? nil : try AirshipJSON.wrap(action["_value"]) + action["name"] as! String, + value: action["value"] is NSNull ? nil : try AirshipJSON.wrap(action["value"]) ) } } @@ -350,6 +350,10 @@ public extension AirshipReactNative { key: key ) } + + func addCustomEvent(_ json: Any) throws { + try AirshipProxy.shared.analytics.addEvent(json) + } } // Contact diff --git a/ios/RTNAirship.mm b/ios/RTNAirship.mm index f45e0cf4..5bc8bb25 100644 --- a/ios/RTNAirship.mm +++ b/ios/RTNAirship.mm @@ -374,6 +374,17 @@ + (BOOL)requiresMainQueueSetup { [self handleResult:nil error:error resolve:resolve reject:reject]; } +RCT_REMAP_METHOD(addCustomEvent, + addCustomEvent:(NSDictionary *)event + resolve:(RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject) { + NSError *error; + [AirshipReactNative.shared addCustomEvent:event + error:&error]; + + [self handleResult:nil error:error resolve:resolve reject:reject]; +} + RCT_REMAP_METHOD(contactEditAttributes, contactEditAttributes:(NSArray *)operations resolve:(RCTPromiseResolveBlock)resolve diff --git a/src/Action.ts b/src/Action.ts deleted file mode 100644 index bec53369..00000000 --- a/src/Action.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright Airship and Contributors */ - -'use strict'; - -import { JsonValue } from './types'; - -/** - * Airship Action Object. - * This is used to encapsulate the Action name and the Action value. - */ -export class Action { - _name: string; - _value?: JsonValue; - - /** - * Airship Action constructor. - * - * @param name The action name. - * @param value The action value. - */ - constructor(name: string, value?: JsonValue) { - this._name = name; - this._value = value; - } - - /** - * Sets the action value. - * - * @param value The action value. - */ - setValue(value?: JsonValue) { - this._value = value; - } -} \ No newline at end of file diff --git a/src/AirshipActions.ts b/src/AirshipActions.ts index 9b9af7b3..10ba6d48 100644 --- a/src/AirshipActions.ts +++ b/src/AirshipActions.ts @@ -1,5 +1,4 @@ import { JsonValue } from './types'; -import { Action } from './Action'; /** * Airship actions. @@ -10,13 +9,15 @@ export class AirshipActions { /** * Runs an Airship action. * - * @param action The Airship Action. + * @param actionName The name of the action. + * @param actionValue The action's value. * @return A promise that returns the action result if the action * successfully runs, or the Error if the action was unable to be run. */ public run( - action: Action + actionName: String, + actionValue: JsonValue ): Promise { - return this.module.actionRun(action); + return this.module.actionRun({name: actionName, value: actionValue}); } } diff --git a/src/AirshipAnalytics.ts b/src/AirshipAnalytics.ts index a9f0d994..5550644b 100644 --- a/src/AirshipAnalytics.ts +++ b/src/AirshipAnalytics.ts @@ -1,4 +1,3 @@ -import { Action } from "./Action"; import { CustomEvent } from "./CustomEvent"; /** @@ -33,15 +32,7 @@ export class AirshipAnalytics { * @return A promise that returns null if resolved, or an Error if the * custom event is rejected. */ - public addCustomEvent(event: CustomEvent): Promise { - let action = new Action("add_custom_event_action", event.toJsonValue()) - - return new Promise((resolve, reject) => { - this.module.actionRun(action).then(() => { - resolve(null) - }, (error: Error) => { - reject(error) - }) - }) + public addCustomEvent(event: CustomEvent): Promise { + return this.module.addCustomEvent(event.toJsonValue()); } } diff --git a/src/CustomEvent.ts b/src/CustomEvent.ts index dae94dbb..43aeeb18 100644 --- a/src/CustomEvent.ts +++ b/src/CustomEvent.ts @@ -12,6 +12,8 @@ export class CustomEvent { _value?: number; _properties: JsonObject; _transactionId?: string; + _interactionId?: string; + _interactionType?: string; /** * Custom event constructor. @@ -39,6 +41,34 @@ export class CustomEvent { this._transactionId = value; } + /** + * Gets the event's interaction ID. + */ + get interactionId(): string | undefined { + return this._interactionId; + } + + /** + * Sets the event's interaction ID. + */ + set interactionId(value: string | undefined) { + this._interactionId = value; + } + + /** + * Gets the event's interaction Type. + */ + get interactionType(): string | undefined { + return this._interactionType; + } + + /** + * Sets the event's interaction Type. + */ + set interactionType(value: string | undefined) { + this._interactionType = value; + } + /** * Adds a property to the custom event. * @@ -56,13 +86,19 @@ export class CustomEvent { */ toJsonValue(): JsonValue { let jsonObject: JsonObject = {}; - jsonObject.event_name = this._name; + jsonObject.eventName = this._name; if (this._value) { - jsonObject.event_value = this._value; + jsonObject.eventValue = this._value; } jsonObject.properties = this._properties; if (this._transactionId) { - jsonObject.transaction_id = this._transactionId; + jsonObject.transactionId = this._transactionId; + } + if (this._interactionId) { + jsonObject.interactionId = this._interactionId; + } + if (this._interactionType) { + jsonObject.interactionType = this._interactionType; } return jsonObject; } diff --git a/src/NativeRTNAirship.ts b/src/NativeRTNAirship.ts index 45e36a40..36cc625f 100644 --- a/src/NativeRTNAirship.ts +++ b/src/NativeRTNAirship.ts @@ -66,6 +66,7 @@ export interface Spec extends TurboModule { // Analytics analyticsTrackScreen(screen?: string): Promise; analyticsAssociateIdentifier(key: string, identifier?: string): Promise; + addCustomEvent(event: Object): Promise; // Action actionRun(action: Object): Promise; diff --git a/src/index.tsx b/src/index.tsx index 1bf77bd3..4c9483be 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -19,7 +19,6 @@ export { SubscriptionListEditor } from './SubscriptionListEditor'; export { TagGroupEditor } from './TagGroupEditor'; export { ScopedSubscriptionListEditor } from './ScopedSubscriptionListEditor'; export { AttributeEditor } from './AttributeEditor'; -export { Action } from './Action'; export * from './types'; export * from './MessageView'; From 0c99f9c5a11a14933a3a5c3536f3d1fbaeb65518 Mon Sep 17 00:00:00 2001 From: Ulrich GIBERNE Date: Mon, 8 Apr 2024 13:56:57 -0400 Subject: [PATCH 4/7] clean up --- src/AirshipActions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AirshipActions.ts b/src/AirshipActions.ts index 10ba6d48..f9dcf5a7 100644 --- a/src/AirshipActions.ts +++ b/src/AirshipActions.ts @@ -15,8 +15,8 @@ export class AirshipActions { * successfully runs, or the Error if the action was unable to be run. */ public run( - actionName: String, - actionValue: JsonValue + actionName: string, + actionValue?: JsonValue ): Promise { return this.module.actionRun({name: actionName, value: actionValue}); } From bfe957275f0b8c6e95739d004e67936087c35e9f Mon Sep 17 00:00:00 2001 From: Ulrich GIBERNE Date: Mon, 8 Apr 2024 14:19:58 -0400 Subject: [PATCH 5/7] null value --- ios/AirshipReactNative.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/AirshipReactNative.swift b/ios/AirshipReactNative.swift index 0b87427f..255ade65 100644 --- a/ios/AirshipReactNative.swift +++ b/ios/AirshipReactNative.swift @@ -328,7 +328,7 @@ public extension AirshipReactNative { // Actions @objc public extension AirshipReactNative { - func actionsRun(action: [String: Any]) async throws-> Any? { + func actionsRun(action: [String: Any?]) async throws-> Any? { return try await AirshipProxy.shared.action.runAction( action["name"] as! String, value: action["value"] is NSNull ? nil : try AirshipJSON.wrap(action["value"]) From 886525406d7862328ff996450dfbedd727a85866 Mon Sep 17 00:00:00 2001 From: Ulrich GIBERNE Date: Mon, 8 Apr 2024 15:10:43 -0400 Subject: [PATCH 6/7] guard let --- ios/AirshipReactNative.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ios/AirshipReactNative.swift b/ios/AirshipReactNative.swift index 255ade65..c26c9646 100644 --- a/ios/AirshipReactNative.swift +++ b/ios/AirshipReactNative.swift @@ -329,8 +329,12 @@ public extension AirshipReactNative { @objc public extension AirshipReactNative { func actionsRun(action: [String: Any?]) async throws-> Any? { + guard let name = action["name"] as? String else { + throw AirshipErrors.error("missing name") + } + return try await AirshipProxy.shared.action.runAction( - action["name"] as! String, + name, value: action["value"] is NSNull ? nil : try AirshipJSON.wrap(action["value"]) ) } From fbdb400f64e27ba78362575190fc7160932f3a6a Mon Sep 17 00:00:00 2001 From: Ulrich GIBERNE Date: Mon, 8 Apr 2024 15:51:18 -0400 Subject: [PATCH 7/7] fix --- ios/AirshipReactNative.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/AirshipReactNative.swift b/ios/AirshipReactNative.swift index c26c9646..dfa7b7bc 100644 --- a/ios/AirshipReactNative.swift +++ b/ios/AirshipReactNative.swift @@ -328,7 +328,7 @@ public extension AirshipReactNative { // Actions @objc public extension AirshipReactNative { - func actionsRun(action: [String: Any?]) async throws-> Any? { + func actionsRun(action: [String: Any]) async throws-> Any? { guard let name = action["name"] as? String else { throw AirshipErrors.error("missing name") }