sendDataOrBulk static method
sendDataOrBulk Sends the given data to be added to the init data
addedData
Data to be added to the init data
Implementation
static Future<bool> sendDataOrBulk(Map<String, String> addedData) async {
assert(isInitialized, "not ready to send data");
assert(
_matomoForever.bulkSize <= 0 ||
(_matomoForever.tokenAuth ?? "").isNotEmpty,
"bulk sending is only possible with authToken");
assert(
_matomoForever.bulkSize > 0 ||
_matomoForever.method == MatomoForeverMethod.post,
"bulk sending possible only through POST method");
Map<String, String> compiledData = _matomoForever._compileData(addedData);
if (_matomoForever.bulkSize > 0) {
compiledData.remove("token_auth");
_matomoForever._queue.add(compiledData);
if (_matomoForever._queue.length < _matomoForever.bulkSize) {
return (true);
}
return (await MatomoForever.sendQueue());
}
if (_matomoForever.method == MatomoForeverMethod.get) {
_matomoForever.sendThroughGetMethod ??= _sendThroughGetMethod;
return (await _matomoForever.sendThroughGetMethod!(
_matomoForever.siteUrl!,
compiledData.toQueryString(),
headers: _matomoForever.headers,
));
}
_matomoForever.sendThroughPostMethod ??= _sendThroughPostMethod;
return (await _matomoForever.sendThroughPostMethod!(
_matomoForever.siteUrl!,
compiledData,
headers: _matomoForever.headers,
));
}