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());
    }
    _core.logger.i('[$runtimeType] send event $code: $body');
  } catch (e, _) {
    _core.logger.e('[$runtimeType] send event error', error: e);
  }
}