sendEventPayload method
Implementation
Future<Null> sendEventPayload() async {
if(lastTrackRequest > 0 && events.length <= minimumEventThreshold) {
return null;
}
if(!isSendingTrackingData && (DateTime.now().millisecondsSinceEpoch - lastTrackRequest > trackRequestInterval)) {
isSendingTrackingData = true;
DataDomeLogger.info("Logging events");
var dio = Dio();
var url = "https://api-sdk.datadome.co/sdk/";
var params = _deviceData;
Response response = await dio.post(url,
options: Options(headers: {
"Content-Type": "application/x-www-form-urlencoded",
}),
data: params,
);
// Parsing event tracking response and store new cookie
if(response.statusCode == 200) {
if(response.data != null && response.data['cookie'] != null && (response.data['cookie'] as String).isNotEmpty) {
var responseBody = EventTrackingResponse.fromJson(response.data);
DataDomeDio.storeCookie(responseBody.cookie);
}
}
// After sending payload
isSendingTrackingData = false;
lastTrackRequest = DateTime.now().millisecondsSinceEpoch;
events.clear();
}
}