1
1
import 'dart:async' ;
2
- import 'package:flutter/services.dart' ;
3
2
import 'dart:developer' as developer;
4
3
import 'dart:io' show Platform;
4
+
5
5
import 'package:flutter/foundation.dart' show kIsWeb;
6
+ import 'package:flutter/services.dart' ;
6
7
import 'package:mixpanel_flutter/codec/mixpanel_message_codec.dart' ;
7
8
8
9
/// The primary class for integrating Mixpanel with your app.
@@ -145,9 +146,9 @@ class Mixpanel {
145
146
/// Mixpanel using the same disinct_id will be considered associated with the
146
147
/// same visitor/customer for retention and funnel reporting, so be sure that the given
147
148
/// value is globally unique for each individual user you intend to track.
148
- void identify (String distinctId) {
149
+ Future < void > identify (String distinctId) async {
149
150
if (_MixpanelHelper .isValidString (distinctId)) {
150
- _channel.invokeMethod <void >(
151
+ await _channel.invokeMethod <void >(
151
152
'identify' , < String , dynamic > {'distinctId' : distinctId});
152
153
} else {
153
154
developer.log ('`identify` failed: distinctId cannot be blank' ,
@@ -189,9 +190,12 @@ class Mixpanel {
189
190
///
190
191
/// * [eventName] The name of the event to send
191
192
/// * [properties] An optional map containing the key value pairs of the properties to include in this event.
192
- void track (String eventName, {Map <String , dynamic >? properties}) {
193
+ Future <void > track (
194
+ String eventName, {
195
+ Map <String , dynamic >? properties,
196
+ }) async {
193
197
if (_MixpanelHelper .isValidString (eventName)) {
194
- _channel.invokeMethod <void >('track' ,
198
+ await _channel.invokeMethod <void >('track' ,
195
199
< String , dynamic > {'eventName' : eventName, 'properties' : properties});
196
200
} else {
197
201
developer.log ('`track` failed: eventName cannot be blank' ,
@@ -217,10 +221,13 @@ class Mixpanel {
217
221
/// * [eventName] The name of the event to send
218
222
/// * [properties] A Map containing the key value pairs of the properties to include in this event.
219
223
/// * [groups] A Map containing the group key value pairs for this event.
220
- void trackWithGroups (String eventName, Map <String , dynamic > properties,
221
- Map <String , dynamic > groups) {
224
+ Future <void > trackWithGroups (
225
+ String eventName,
226
+ Map <String , dynamic > properties,
227
+ Map <String , dynamic > groups,
228
+ ) async {
222
229
if (_MixpanelHelper .isValidString (eventName)) {
223
- _channel.invokeMethod <void >('trackWithGroups' , < String , dynamic > {
230
+ await _channel.invokeMethod <void >('trackWithGroups' , < String , dynamic > {
224
231
'eventName' : eventName,
225
232
'properties' : properties,
226
233
'groups' : groups
@@ -314,8 +321,8 @@ class Mixpanel {
314
321
/// to remove a superProperty, call unregisterSuperProperty() or clearSuperProperties()
315
322
///
316
323
/// * [properties] A Map containing super properties to register
317
- void registerSuperProperties (Map <String , dynamic > properties) {
318
- _channel.invokeMethod <void >(
324
+ Future < void > registerSuperProperties (Map <String , dynamic > properties) async {
325
+ await _channel.invokeMethod <void >(
319
326
'registerSuperProperties' , < String , dynamic > {'properties' : properties});
320
327
}
321
328
@@ -325,8 +332,10 @@ class Mixpanel {
325
332
/// Calling registerSuperPropertiesOnce will never overwrite existing properties.
326
333
///
327
334
/// * [properties] A Map containing the super properties to register.
328
- void registerSuperPropertiesOnce (Map <String , dynamic > properties) {
329
- _channel.invokeMethod <void >('registerSuperPropertiesOnce' ,
335
+ Future <void > registerSuperPropertiesOnce (
336
+ Map <String , dynamic > properties,
337
+ ) async {
338
+ await _channel.invokeMethod <void >('registerSuperPropertiesOnce' ,
330
339
< String , dynamic > {'properties' : properties});
331
340
}
332
341
@@ -337,9 +346,9 @@ class Mixpanel {
337
346
/// To clear all superProperties, use clearSuperProperties()
338
347
///
339
348
/// * [propertyName] name of the property to unregister
340
- void unregisterSuperProperty (String propertyName) {
349
+ Future < void > unregisterSuperProperty (String propertyName) async {
341
350
if (_MixpanelHelper .isValidString (propertyName)) {
342
- _channel.invokeMethod <void >('unregisterSuperProperty' ,
351
+ await _channel.invokeMethod <void >('unregisterSuperProperty' ,
343
352
< String , dynamic > {'propertyName' : propertyName});
344
353
} else {
345
354
developer.log (
@@ -364,8 +373,8 @@ class Mixpanel {
364
373
/// superProperties registered before the clearSuperProperties method was called.
365
374
///
366
375
/// To remove a single superProperty, use unregisterSuperProperty()
367
- void clearSuperProperties () {
368
- _channel.invokeMethod <void >('clearSuperProperties' );
376
+ Future < void > clearSuperProperties () async {
377
+ await _channel.invokeMethod <void >('clearSuperProperties' );
369
378
}
370
379
371
380
/// Begin timing of an event. Calling timeEvent("Thing") will not send an event, but
@@ -399,8 +408,8 @@ class Mixpanel {
399
408
400
409
/// Clear super properties and generates a new random distinctId for this instance.
401
410
/// Useful for clearing data when a user logs out.
402
- void reset () {
403
- _channel.invokeMethod <void >('reset' );
411
+ Future < void > reset () async {
412
+ await _channel.invokeMethod <void >('reset' );
404
413
}
405
414
406
415
/// Returns the current distinct id of the user.
0 commit comments