MixpanelAnalytics constructor

MixpanelAnalytics({
  1. required String token,
  2. Stream<String?>? userId$,
  3. bool shouldAnonymize = false,
  4. ShaFn shaFn = _defaultShaFn,
  5. bool verbose = false,
  6. bool useIp = false,
  7. void onError(
    1. Object
    )?,
  8. String? proxyUrl,
  9. Map<String, String>? optionalHeaders,
  10. String? prefsKey,
  11. 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

Implementation

MixpanelAnalytics({
  required String token,
  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,
      _optionalHeaders = optionalHeaders,
      baseApiUrl = baseApiUrl ?? _baseUsApiUrl {
  _userId$?.listen((id) => _userId = id);
  _prefsKey = prefsKey ?? _prefsKey;
}