MixpanelAnalytics.batch constructor
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
Implementation
MixpanelAnalytics.batch({
required String token,
required Duration uploadInterval,
Stream<String?>? userId$,
bool shouldAnonymize = false,
ShaFn shaFn = _defaultShaFn,
bool verbose = false,
bool useIp = false,
void Function(Object)? onError,
String? proxyUrl,
Map<String, String>? optionalHeaders,
String? prefsKey,
String? baseApiUrl,
}) : _token = token,
_userId$ = userId$,
_verbose = verbose,
_useIp = useIp,
_onError = onError,
_shouldAnonymize = shouldAnonymize,
_shaFn = shaFn,
_proxyUrl = proxyUrl,
_uploadInterval = uploadInterval,
_optionalHeaders = optionalHeaders,
baseApiUrl = baseApiUrl ?? _baseUsApiUrl {
_batchTimer = Timer.periodic(_uploadInterval, (_) => _uploadQueuedEvents());
_userId$?.listen((id) => _userId = id);
_prefsKey = prefsKey ?? _prefsKey;
}