recordEvent static method
Implementation
static Future<String?> recordEvent(Map<String, Object> options) async {
if (!_instance._countlyState.isInitialized) {
String message = '"initWithConfig" must be called before "recordEvent"';
log('recordEvent, $message', logLevel: LogLevel.ERROR);
return message;
}
List<String> args = [];
options['key'] ??= '';
String eventKey = options['key'].toString();
log('Calling "recordEvent":[$eventKey]');
if (eventKey.isEmpty) {
String error = 'recordEvent, Valid Countly event key is required';
log(error);
return 'Error : $error';
}
args.add(eventKey);
options['count'] ??= 1;
args.add(options['count'].toString());
options['sum'] ??= '0';
args.add(options['sum'].toString());
options['duration'] ??= '0';
args.add(options['duration'].toString());
if (options['segmentation'] != null) {
var segmentation = options['segmentation'] as Map;
segmentation.forEach((k, v) {
args.add(k.toString());
args.add(v.toString());
});
}
final String? result = await _channel.invokeMethod('recordEvent', <String, dynamic>{'data': json.encode(args)});
return result;
}