sendEvent method

  1. @override
void sendEvent(
  1. AnalyticsEvent analyticsEvent
)
override

Implementation

@override
void sendEvent(AnalyticsEvent analyticsEvent) async {
  if (!_isEnabled) return;
  try {
    final body = jsonEncode({
      'eventId': Uuid().v4(),
      'bundleId': _bundleId,
      'timestamp': DateTime.now().toUtc().millisecondsSinceEpoch,
      'props': analyticsEvent.toMap(),
    });

    final response = await http.post(
      Uri.parse('$_endpoint/e'),
      headers: _headers,
      body: body,
    );
    final code = response.statusCode;
    if (code == 200 || code == 202) {
      _eventsController.sink.add(analyticsEvent.toMap());
    }
    loggerService.instance.d('[$runtimeType] send event $code: $body');
  } catch (e, s) {
    loggerService.instance.d(
      '[$runtimeType] send event error',
      error: e,
      stackTrace: s,
    );
  }
}