diff --git a/android/src/main/kotlin/io/customer/customer_io/CustomerIoPlugin.kt b/android/src/main/kotlin/io/customer/customer_io/CustomerIoPlugin.kt index f763163..7fb8bf3 100644 --- a/android/src/main/kotlin/io/customer/customer_io/CustomerIoPlugin.kt +++ b/android/src/main/kotlin/io/customer/customer_io/CustomerIoPlugin.kt @@ -16,6 +16,8 @@ import io.customer.sdk.core.di.SDKComponent import io.customer.sdk.core.util.CioLogLevel import io.customer.sdk.core.util.Logger import io.customer.sdk.data.model.Region +import io.customer.sdk.events.Metric +import io.customer.sdk.events.TrackMetric import io.flutter.embedding.engine.plugins.FlutterPlugin import io.flutter.embedding.engine.plugins.activity.ActivityAware import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding @@ -191,22 +193,23 @@ class CustomerIoPlugin : FlutterPlugin, MethodCallHandler, ActivityAware { } private fun trackMetric(params: Map) { - // TODO: Fix trackMetric implementation - /* - val deliveryId = params.getString(Keys.Tracking.DELIVERY_ID) - val deliveryToken = params.getString(Keys.Tracking.DELIVERY_TOKEN) - val eventName = params.getProperty(Keys.Tracking.METRIC_EVENT) - val event = MetricEvent.getEvent(eventName) - - if (event == null) { - logger.info("metric event type null. Possible issue with SDK? Given: $eventName") - return + val deliveryId = params.getAsTypeOrNull(Keys.Tracking.DELIVERY_ID) + val deliveryToken = params.getAsTypeOrNull(Keys.Tracking.DELIVERY_TOKEN) + val eventName = params.getAsTypeOrNull(Keys.Tracking.METRIC_EVENT) + + if (deliveryId == null || deliveryToken == null || eventName == null) { + throw IllegalArgumentException("Missing required parameters") } + val event = Metric.valueOf(eventName) + CustomerIO.instance().trackMetric( - deliveryID = deliveryId, deviceToken = deliveryToken, event = event + event = TrackMetric.Push( + deliveryId = deliveryId, + deviceToken = deliveryToken, + metric = event + ) ) - */ } private fun setDeviceAttributes(params: Map) { diff --git a/ios/Classes/SwiftCustomerIoPlugin.swift b/ios/Classes/SwiftCustomerIoPlugin.swift index f21eb81..e77660a 100644 --- a/ios/Classes/SwiftCustomerIoPlugin.swift +++ b/ios/Classes/SwiftCustomerIoPlugin.swift @@ -153,20 +153,20 @@ public class SwiftCustomerIoPlugin: NSObject, FlutterPlugin { } private func trackMetric(params : Dictionary){ - // TODO: Fix trackMetric implementation - /* - guard let deliveryId = params[Keys.Tracking.deliveryId] as? String, - let deviceToken = params[Keys.Tracking.deliveryToken] as? String, - let metricEvent = params[Keys.Tracking.metricEvent] as? String, - let event = Metric.getEvent(from: metricEvent) - else { - return - } - - CustomerIO.shared.trackMetric(deliveryID: deliveryId, - event: event, - deviceToken: deviceToken) - */ + + guard let deliveryId = params[Keys.Tracking.deliveryId] as? String, + let deviceToken = params[Keys.Tracking.deliveryToken] as? String, + let metricEvent = params[Keys.Tracking.metricEvent] as? String, + let event = Metric.getEvent(from: metricEvent) + else { + logger.error("Missing required parameters in: \(params)") + return + } + + CustomerIO.shared.trackMetric(deliveryID: deliveryId, + event: event, + deviceToken: deviceToken) + } private func initialize(params : Dictionary){ diff --git a/lib/customer_io_const.dart b/lib/customer_io_const.dart index d55a30a..7371cdc 100644 --- a/lib/customer_io_const.dart +++ b/lib/customer_io_const.dart @@ -17,8 +17,8 @@ class MethodConsts { class TrackingConsts { static const String userId = "userId"; - static const String traits = "traits"; static const String attributes = "attributes"; + static const String traits = "traits"; static const String eventName = "eventName"; static const String token = "token"; static const String deliveryId = "deliveryId"; diff --git a/lib/customer_io_enums.dart b/lib/customer_io_enums.dart index 3a62435..fe875d7 100644 --- a/lib/customer_io_enums.dart +++ b/lib/customer_io_enums.dart @@ -8,7 +8,7 @@ enum CioLogLevel { none, error, info, debug } enum Region { us, eu } /// Enum to specify the type of metric for tracking -enum MetricEvent { delivered, opened, converted, clicked } +enum MetricEvent { delivered, opened, converted } /// Enum to specify the click behavior of push notification for Android enum PushClickBehaviorAndroid { diff --git a/lib/customer_io_method_channel.dart b/lib/customer_io_method_channel.dart index b19dddb..463e8ab 100644 --- a/lib/customer_io_method_channel.dart +++ b/lib/customer_io_method_channel.dart @@ -182,7 +182,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform { @override void setDeviceAttributes({required Map attributes}) { try { - final payload = {TrackingConsts.attributes: attributes}; + final payload = {TrackingConsts.traits: attributes}; methodChannel.invokeMethod(MethodConsts.setDeviceAttributes, payload); } on PlatformException catch (exception) { handleException(exception); diff --git a/test/customer_io_method_channel_test.dart b/test/customer_io_method_channel_test.dart index ca0a520..22ba981 100644 --- a/test/customer_io_method_channel_test.dart +++ b/test/customer_io_method_channel_test.dart @@ -91,7 +91,7 @@ void main() { final Map args = { 'deliveryId': '123', 'deliveryToken': 'asdf', - 'metricEvent': 'clicked' + 'metricEvent': 'opened' }; final customerIO = CustomerIOMethodChannel(); @@ -153,11 +153,11 @@ void main() { 'setDeviceAttributes() should call platform method with correct arguments', () async { final Map args = { - 'attributes': {'os': 'Android'} + 'traits': {'os': 'Android'} }; final customerIO = CustomerIOMethodChannel(); - customerIO.setDeviceAttributes(attributes: args['attributes']); + customerIO.setDeviceAttributes(attributes: args['traits']); expectMethodInvocationArguments('setDeviceAttributes', args); });