track method

Future<bool> track(
  1. RawMetricEvent event
)

Tracks an event.

This will return true if the event was successfully tracked, and false otherwise.

Implementation

Future<bool> track(RawMetricEvent event) async {
  try {
    final hasInternet = await _hasInternet();
    if (!hasInternet) return false;

    final response = await _dio.post(
      "$baseUrl/metric-events",
      options: Options(headers: _headers),
      data: jsonEncode(event.toJson()),
    );
    if (response.statusCode == null) return false;
    if (response.statusCode! >= 200 && response.statusCode! < 300) {
      return true;
    } else {
      return false;
    }
  } catch (e) {
    // For now, we are just catching the error and returning false.
    // Eventually, we should log the error and handle it better
    return false;
  }
}