MixpanelAnalytics class

Constructors

MixpanelAnalytics({required String token, Stream<String?>? userId$, bool shouldAnonymize = false, ShaFn shaFn = _defaultShaFn, bool verbose = false, bool useIp = false, void onError(Object)?, String? proxyUrl, Map<String, String>? optionalHeaders, String? prefsKey, String? baseApiUrl})
Provides an instance of this class. The instance of the class created with this constructor will send the events on the fly, which could result on high traffic in case there are many events. Also, if a request returns an error, this will be logged but the event will be lost. If you want events to be send in batch and also reliability to the requests use MixpanelAnalytics.batch instead. token is the Mixpanel token associated with your project. userId$ is a stream which contains the value of the userId that will be used to identify the events for a user. shouldAnonymize will anonymize the sensitive information (userId) sent to mixpanel. shaFn function used to anonymize the data. verbose true will provide a detailed error cause in case the request is not successful. useIp is the ip property as explained in mixpanel documentation onError is a callback function that will be executed in case there is an error, otherwise debugPrint will be used. proxyUrl URL to use in the requests as a proxy. This URL will be used as follows $proxyUrl/mixpanel.api... optionalHeaders http headers to add in each request. prefsKey key to use in the SharedPreferences. If you leave it empty a default name will be used. baseApiUrl Ingestion API URL. If you don't inform it, the US-based url will be used (api.mixpanel.com). https://developer.mixpanel.com/docs/privacy-security#storing-your-data-in-the-european-union
MixpanelAnalytics.batch({required String token, required Duration uploadInterval, Stream<String?>? userId$, bool shouldAnonymize = false, ShaFn shaFn = _defaultShaFn, bool verbose = false, bool useIp = false, void onError(Object)?, String? proxyUrl, Map<String, String>? optionalHeaders, String? prefsKey, String? baseApiUrl})
Provides an instance of this class. With this constructor, the instance will send the events in batch, and also if the request can't be sent (connectivity issues) it will be retried until it is successful. token is the Mixpanel token associated with your project. userId$ is a stream which contains the value of the userId that will be used to identify the events for a user. uploadInterval is the interval used to batch the events. shouldAnonymize will anonymize the sensitive information (userId) sent to mixpanel. shaFn function used to anonymize the data. verbose true will provide a detailed error cause in case the request is not successful. ip is the ip property as explained in mixpanel documentation onError is a callback function that will be executed in case there is an error, otherwise debugPrint will be used. proxyUrl URL to use in the requests as a proxy. This URL will be used as follows $proxyUrl/mixpanel.api... optionalHeaders http headers to add in each request. prefsKey key to use in the SharedPreferences. If you leave it empty a default name will be used. baseApiUrl Ingestion API URL. If you don't inform it, the US-based url will be used (api.mixpanel.com). https://developer.mixpanel.com/docs/privacy-security#storing-your-data-in-the-european-union

Properties

baseApiUrl String
By default will point to the US-based Mixpanel servers (api.mixpanel.com) Its value can be overriden in the constructor and there you can use, for instance, the EU-based servers url: api-eu.mixpanel.com See this for more information: https://developer.mixpanel.com/docs/privacy-security#storing-your-data-in-the-european-union
final
hashCode int
The hash code for this object.
no setterinherited
http ↔ Client
We can inject the client required, useful for testing
getter/setter pair
isBatchMode bool
When in batch mode, events will be added to a queue and send in batch every _uploadInterval
no setter
mixpanelToken String
Returns the value of the token in mixpanel.
no setter
optionalHeaders Map<String, String>
Sets the optional headers.
no getter
prefs ↔ SharedPreferences?
In case we use MixpanelAnalytics.batch() we need to provide a storage provider This will be used to save the events not sent
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
userId String?
Sets the value of the userId.
no getter

Methods

dispose() → void
Used in case we want to remove the timer to send batched events.
engage({required MixpanelUpdateOperations operation, required Map<String, dynamic> value, DateTime? time, String? ip, bool? ignoreTime, bool? ignoreAlias}) Future<bool>
Sends a request to engage a specific event. Requests will be sent immediately. If you want to batch the events use MixpanelAnalytics.batch instead. operation is the operation update as per MixpanelUpdateOperations. value is a map with the properties to be sent. time is the date that will be added in the event. If not provided, current time will be used. ip is the ip property as explained in mixpanel documentation ignoreTime is the $ignore_time property as explained in mixpanel documentation ignoreAlias is the $ignore_alias property as explained in mixpanel documentation
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
track({required String event, required Map<String, dynamic> properties, DateTime? time, String? ip, String? insertId}) Future<bool>
Sends a request to track a specific event. Requests will be sent immediately. If you want to batch the events use MixpanelAnalytics.batch instead. event will be the name of the event. properties is a map with the properties to be sent. time is the date that will be added in the event. If not provided, current time will be used. ip is the ip property as explained in mixpanel documentation insertId is the $insert_id property as explained in mixpanel documentation

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

maxEventsInBatchRequest → const int