trackEvent method
Tracks an event with the Optimus API.
Implementation
Future<void> trackEvent(
String eventName, [
OptimusProperties? properties,
]) async {
final request = TrackingRequest(
eventName,
"",
await _handleDeviceInfoGathering(),
await _handleMetaDataGathering(),
)
..identifiers = await _handleIdentifiersGathering()
..attributes = await _handleAttributesGathering(properties);
final body = convert.jsonEncode(request);
final response = await _client.post(
Uri.https(_apiEndpoint, trackingUrl),
headers: _getJsonHeaders(),
body: body,
encoding: const convert.Utf8Codec(),
);
final res = Response.fromJson(
convert.jsonDecode(response.body) as Map<String, dynamic>,
);
logRequest(path: trackingUrl, message: body);
logResponse(
path: trackingUrl,
responseCode: response.statusCode,
responseBody: response.body,
);
if (response.statusCode != 200 || !res.success) {
throw ClientException(
res.message.isNotEmpty
? res.message
: 'Something went wrong while calling Optimus tracking event API',
response.statusCode,
);
}
}