A dart wrapper on the mixpanel REST API to be used in Flutter applications. As this is using the http REST API it works both with Android and iOS.
There is an example app that demonstrates how to use the plugin,
You just need to instantiate the class and you'll be ready to send track
or engage
events.
Make sure to check mixpanel documentation for the REST API to know the options available.
MixpanelAnalytics(
token: 'XXXXXXXXX',
userId$: _user$.stream,
verbose: true,
shouldAnonymize: true,
shaFn: (value) => value,
onError: (e) => setState(() {
_error = e;
_success = null;
}),
);
There are two different constructors, the regular one which will send events on the fly and the batch
mode which will group the requests (by type) and send them every X seconds (configurable).
MixpanelAnalytics.batch(
token: 'XXXXXXXXX',
userId$: _user$.stream,
uploadInterval: Duration(seconds: 30),
shouldAnonymize: true,
shaFn: (value) => value,
verbose: true,
onError: (e) => setState(() {
_error = e;
_success = null;
}),
);
Check the documentation for more information on the features not yet supported https://developer.mixpanel.com/docs/http
In addition to the data
parameter, https://api.mixpanel.com/track
supports a number of optional parameters. For the most part, these optional parameters are useful only in special situations.
Parameters |
---|
ip |
redirect |
img |
callback |
In addition to the data
parameter, https://api.mixpanel.com/engage
supports a number of optional parameters. For the most part, these optional parameters are useful only in special situations.
Parameters |
---|
redirect |
callback |
When sending batch requests, if one of them is invalid the whole batch operation will fail and the batch will be saved to retry the next iteration. This could become a problem as the whole batch could be stored and retried over and over. A strategy for this would be either to send individually the requests and ditch the only invalid one or just dith the whole lot (TBD).