recordEvent static method

Future<String?> recordEvent(
  1. Map<String, Object> options
)

Records an event returns the error or success message

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<Object> 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) {
    args.add(options['segmentation']!);
  }

  final String? result = await _channel.invokeMethod('recordEvent', <String, dynamic>{'data': json.encode(args)});

  return result;
}