Skip to content

Commit 3a836bb

Browse files
committed
method of metric tracking
1 parent f7b41a8 commit 3a836bb

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

android/src/main/kotlin/io/customer/customer_io/CustomerIoPlugin.kt

+15-13
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import io.customer.sdk.core.di.SDKComponent
1616
import io.customer.sdk.core.util.CioLogLevel
1717
import io.customer.sdk.core.util.Logger
1818
import io.customer.sdk.data.model.Region
19+
import io.customer.sdk.events.Metric
20+
import io.customer.sdk.events.TrackMetric
1921
import io.flutter.embedding.engine.plugins.FlutterPlugin
2022
import io.flutter.embedding.engine.plugins.activity.ActivityAware
2123
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
2224
import io.flutter.plugin.common.MethodCall
2325
import io.flutter.plugin.common.MethodChannel
2426
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
25-
import io.flutter.plugin.common.MethodChannel.Result
2627
import java.lang.ref.WeakReference
2728

2829
/**
@@ -191,22 +192,23 @@ class CustomerIoPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
191192
}
192193

193194
private fun trackMetric(params: Map<String, Any>) {
194-
// TODO: Fix trackMetric implementation
195-
/*
196-
val deliveryId = params.getString(Keys.Tracking.DELIVERY_ID)
197-
val deliveryToken = params.getString(Keys.Tracking.DELIVERY_TOKEN)
198-
val eventName = params.getProperty<String>(Keys.Tracking.METRIC_EVENT)
199-
val event = MetricEvent.getEvent(eventName)
200-
201-
if (event == null) {
202-
logger.info("metric event type null. Possible issue with SDK? Given: $eventName")
203-
return
195+
val deliveryId = params.getAsTypeOrNull<String>(Keys.Tracking.DELIVERY_ID)
196+
val deliveryToken = params.getAsTypeOrNull<String>(Keys.Tracking.DELIVERY_TOKEN)
197+
val eventName = params.getAsTypeOrNull<String>(Keys.Tracking.METRIC_EVENT)
198+
199+
if (deliveryId == null || deliveryToken == null || eventName == null) {
200+
throw IllegalArgumentException("Missing required parameters")
204201
}
205202

203+
val event = Metric.valueOf(eventName)
204+
206205
CustomerIO.instance().trackMetric(
207-
deliveryID = deliveryId, deviceToken = deliveryToken, event = event
206+
event = TrackMetric.Push(
207+
deliveryId = deliveryId,
208+
deviceToken = deliveryToken,
209+
metric = event
210+
)
208211
)
209-
*/
210212
}
211213

212214
private fun setDeviceAttributes(params: Map<String, Any>) {

ios/Classes/SwiftCustomerIoPlugin.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,20 @@ public class SwiftCustomerIoPlugin: NSObject, FlutterPlugin {
153153
}
154154

155155
private func trackMetric(params : Dictionary<String, AnyHashable>){
156-
// TODO: Fix trackMetric implementation
157-
/*
158-
guard let deliveryId = params[Keys.Tracking.deliveryId] as? String,
159-
let deviceToken = params[Keys.Tracking.deliveryToken] as? String,
160-
let metricEvent = params[Keys.Tracking.metricEvent] as? String,
161-
let event = Metric.getEvent(from: metricEvent)
162-
else {
163-
return
164-
}
165-
166-
CustomerIO.shared.trackMetric(deliveryID: deliveryId,
167-
event: event,
168-
deviceToken: deviceToken)
169-
*/
156+
157+
guard let deliveryId = params[Keys.Tracking.deliveryId] as? String,
158+
let deviceToken = params[Keys.Tracking.deliveryToken] as? String,
159+
let metricEvent = params[Keys.Tracking.metricEvent] as? String,
160+
let event = Metric.getEvent(from: metricEvent)
161+
else {
162+
logger.error("Missing required parameters in: \(params)")
163+
return
164+
}
165+
166+
CustomerIO.shared.trackMetric(deliveryID: deliveryId,
167+
event: event,
168+
deviceToken: deviceToken)
169+
170170
}
171171

172172
private func initialize(params : Dictionary<String, AnyHashable>){

lib/customer_io_enums.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ enum CioLogLevel { none, error, info, debug }
88
enum Region { us, eu }
99

1010
/// Enum to specify the type of metric for tracking
11-
enum MetricEvent { delivered, opened, converted, clicked }
11+
enum MetricEvent { delivered, opened, converted }
1212

1313
/// Enum to specify the click behavior of push notification for Android
1414
enum PushClickBehaviorAndroid {

0 commit comments

Comments
 (0)