Skip to content

Commit

Permalink
chore: manual metric tracking (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 authored Nov 20, 2024
1 parent 0fadd4d commit ce1140c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 32 deletions.
27 changes: 15 additions & 12 deletions android/src/main/kotlin/io/customer/customer_io/CustomerIoPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -191,22 +193,23 @@ class CustomerIoPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}

private fun trackMetric(params: Map<String, Any>) {
// TODO: Fix trackMetric implementation
/*
val deliveryId = params.getString(Keys.Tracking.DELIVERY_ID)
val deliveryToken = params.getString(Keys.Tracking.DELIVERY_TOKEN)
val eventName = params.getProperty<String>(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<String>(Keys.Tracking.DELIVERY_ID)
val deliveryToken = params.getAsTypeOrNull<String>(Keys.Tracking.DELIVERY_TOKEN)
val eventName = params.getAsTypeOrNull<String>(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<String, Any>) {
Expand Down
28 changes: 14 additions & 14 deletions ios/Classes/SwiftCustomerIoPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,20 @@ public class SwiftCustomerIoPlugin: NSObject, FlutterPlugin {
}

private func trackMetric(params : Dictionary<String, AnyHashable>){
// 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<String, AnyHashable>){
Expand Down
2 changes: 1 addition & 1 deletion lib/customer_io_const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion lib/customer_io_enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/customer_io_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class CustomerIOMethodChannel extends CustomerIOPlatform {
@override
void setDeviceAttributes({required Map<String, dynamic> attributes}) {
try {
final payload = {TrackingConsts.attributes: attributes};
final payload = {TrackingConsts.traits: attributes};
methodChannel.invokeMethod(MethodConsts.setDeviceAttributes, payload);
} on PlatformException catch (exception) {
handleException(exception);
Expand Down
6 changes: 3 additions & 3 deletions test/customer_io_method_channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void main() {
final Map<String, dynamic> args = {
'deliveryId': '123',
'deliveryToken': 'asdf',
'metricEvent': 'clicked'
'metricEvent': 'opened'
};

final customerIO = CustomerIOMethodChannel();
Expand Down Expand Up @@ -153,11 +153,11 @@ void main() {
'setDeviceAttributes() should call platform method with correct arguments',
() async {
final Map<String, dynamic> args = {
'attributes': {'os': 'Android'}
'traits': {'os': 'Android'}
};

final customerIO = CustomerIOMethodChannel();
customerIO.setDeviceAttributes(attributes: args['attributes']);
customerIO.setDeviceAttributes(attributes: args['traits']);

expectMethodInvocationArguments('setDeviceAttributes', args);
});
Expand Down

0 comments on commit ce1140c

Please sign in to comment.