Skip to content

Commit ae660bb

Browse files
committed
add trackEvent
1 parent abfbb1c commit ae660bb

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

android/src/main/java/com/imumz/flutter_split/FlutterSplitPlugin.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
7676
// Get Split Client instance
7777
this.client = splitFactory.client();
7878

79-
}else if(call.method.equals("trackEvent")){
80-
String eventType = call.argument("eventName");
81-
HashMap<String,Object> map = new HashMap<String,Object>();
82-
if(this.client!=null){
83-
boolean res = client.track(eventType,map);
84-
if(res){
85-
result.success(true);
86-
}else{
87-
88-
}
89-
}else{
90-
result.error(SDK_NOT_INITIALIZED,"Sdk is not initialized","");
91-
}
9279
}else if(call.method.equals("getTreatment")){
9380
String key = call.argument("key");
9481
HashMap<String,Object> attr = call.argument("attributes");
@@ -142,6 +129,16 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
142129
}else{
143130
result.error(SDK_NOT_INITIALIZED,"Sdk is not initialized","");
144131
}
132+
}else if(call.method.equals("trackEvent")){
133+
if(this.client!=null){
134+
String trafficType = call.argument("trafficType");
135+
String eventType = call.argument("eventType");
136+
HashMap<String,Object> attr = call.argument("attributes");
137+
boolean trackResult = this.client.track(trafficType,eventType,attr);
138+
result.success(trackResult);
139+
}else{
140+
result.error(SDK_NOT_INITIALIZED,"Sdk is not initialized","");
141+
}
145142
}
146143
else {
147144
result.notImplemented();

lib/flutter_split.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FlutterSplit {
1111
Map<String, dynamic> attr = {};
1212
attr['appKey'] = appKey;
1313
attr['userId'] = userId;
14-
return await _channel.invokeMethod('initializeSdk', attr);
14+
return await _channel.invokeMethod('initializeSdk', attr);
1515
}
1616

1717
Future<String> getTreatment(String key, Map<String, dynamic> attr) async {
@@ -92,9 +92,12 @@ class FlutterSplit {
9292
return await _channel.invokeMethod('dispose');
9393
}
9494

95-
static Future<bool> trackEvent(
96-
String eventName, Map<String, dynamic> props) async {
97-
//TODO: Implement trackEvent
98-
return false;
95+
Future<bool> trackEvent(
96+
String eventType, String trafficType, Map<String, dynamic> props) async {
97+
return await _channel.invokeMethod('trackEvent', {
98+
'trafficType': trafficType,
99+
'eventType': eventType,
100+
'attributes': props
101+
});
99102
}
100103
}

0 commit comments

Comments
 (0)