trackAll method
Tracks events in a batch.
This will return true if the events werwe successfully tracked, and false otherwise.
Implementation
Future<bool> trackAll(List<MetricEvent> events) async {
try {
final data = jsonEncode(BatchMetricEvents(events: events).toJson());
final hasInternet = await _hasInternet();
if (!hasInternet) return false;
final response = await _dio.post(
"$baseUrl/metric-events/batch",
options: Options(headers: _headers),
data: data,
);
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;
}
}