track method
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
Implementation
Future<bool> track({
required String event,
required Map<String, dynamic> properties,
DateTime? time,
String? ip,
String? insertId,
}) async {
final trackEvent = _createTrackEvent(
event, properties, time ?? DateTime.now(), ip, insertId);
if (isBatchMode) {
// TODO: this should be place within an init() along within the constructor.
// This is not perfect, as we are waiting for the caller to send an event before sending the stored in memory.
// But doing it on an init() would be a breaking change.
// To be executed only the first time user tries to send an event
if (!_isQueuedEventsReadFromStorage) {
await _restoreQueuedEventsFromStorage();
_isQueuedEventsReadFromStorage = true;
}
_trackEvents.add(trackEvent);
return _saveQueuedEventsToLocalStorage();
}
final base64Event = _base64Encoder(trackEvent);
return _sendTrackEvent(base64Event);
}