trackEvent method

void trackEvent(
  1. Map? identityId,
  2. List<Map>? profile,
  3. String? eventName,
  4. Map? eventData, {
  5. dynamic onResponse(
    1. Object?
    )?,
  6. dynamic onFailure(
    1. Object?
    )?,
})

Implementation

void trackEvent(
    Map? identityId, List<Map>? profile, String? eventName, Map? eventData,
    {Function(Object?)? onResponse, Function(Object?)? onFailure}) async {
  // print("identityId $identityId");
  // print("profile profile");
  // print("eventName $eventName");
  // print("eventData $eventData");
  final result = await _channel.invokeMethod<Map<dynamic, dynamic>>(
    Const.trackEvent,
    {
      "identityId": identityId,
      "profile": profile,
      "eventName": eventName,
      "eventData": eventData,
    },
  );
  if (result != null) {
    final input = result['input'] as Object?;
    // _log("~~~~~~~~~~~~~monitorEvent: ${jsonEncode(monitorEvent)}");
    final isSuccessful = result['isSuccessful'] as bool?;
    final code = result['code'] as int?;
    final response = result['response'] as Object?;
    // _log("~~~~~~~~~~~~~isSuccessful: $isSuccessful");
    // _log("~~~~~~~~~~~~~code: $code");
    // _log("~~~~~~~~~~~~~response: ${jsonEncode(response)}");

    // if (kDebugMode) {
    //   await Future.delayed(const Duration(seconds: 2));
    // }

    if (response != null) {
      onResponse?.call({
        if (input != null) "input": input,
        if (isSuccessful != null) "isSuccessful": isSuccessful,
        if (code != null) "code": code,
        "response": response,
      });
    }
    final error = result['error'] as String?;
    if (error != null) {
      onFailure?.call({
        if (input != null) "input": input,
        "error": error,
      });
    }
  }
}