track static method

void track(
  1. String name,
  2. AttributeBuilder properties,
  3. OtherBuilder otherid
)

Implementation

static void track(String name, AttributeBuilder properties, OtherBuilder otherid) async {
  GenricModel genricModel = GenricModel();
  genricModel.name = name;
  genricModel.properties = properties.properties;
  genricModel.otherid = otherid.otherid;
  GenricModel? fMain = await genricModel;

  String? deviceId;
  String? deviceType;
  String? deviceManufacture;
  String? deviceModel;
  String? versionName;

  String? appName;
  String? appVersion;
  String? appBuild;

  String? googleAdvertisingID;
  dynamic? googleAdvertisingBool;

  String? networkIP;

  String? appScreenHeightWidth;
  String? appScreenHeightHeight;

  String? appDataReceivedAt;
  String? appDataSenddAt;
  String? appOriginalTimetemp;
  String? appTimestemp;
  String? appServerTs;
  String? appMsgId;

  try {
    deviceId = await _getDeviceId;
    deviceType = await _getPlatFormDeviceType;
    deviceModel = await _getDeviceModel;
    deviceManufacture = await _getManufactureModel;
    versionName = await _getOSVersion;
    appName = await _getAppName;
    appVersion = await _getAppVersion;
    appBuild = await _getBuildNumber;
    googleAdvertisingID = await _getGoogleadvertisingID;
    googleAdvertisingBool = await _getGoogleadvertisingIDBoolValue;
    networkIP = await _getNetworkIP;

    appScreenHeightHeight = await _getScreenHeight;
    appScreenHeightWidth = await _getScreenWidth;

    appDataReceivedAt = await _getReceivedAt;
    appDataSenddAt = await _getSendAt;

    appOriginalTimetemp = await _getOriginalTimestemp;
    appServerTs = await _getServerTs;
    appTimestemp = await _getTimestemp;
    appMsgId = await _getMessageId;
  } on PlatformException {
    deviceId = 'Failed to get information.';
  }

  Map<dynamic, dynamic> lib = {
    "library": {
      "name": "Flutter SDK",
      "version": sdkVersion,
    },
    "server_ts": appServerTs,
    "app": {
      "name": appName,
      "version": appVersion,
      "build": appBuild,
    },
    "device": {
      "id": deviceId,
      "advertisingId": googleAdvertisingID,
      "adTrackingEnabled": googleAdvertisingBool,
      "manufacturer": deviceManufacture,
      "model": deviceModel,
      "type": deviceType,
      "token": LemniskFirebase.FCM_URL,
    },
    "screen": {
      "width": appScreenHeightWidth,
      "height": appScreenHeightHeight,
      "density": 2,
    },
    "userAgent": {
      "osType": deviceType,
      "osVersion": versionName,
    },
    "ip": networkIP
  };
  Map map = {
    "id": deviceId,
    "messageId": appMsgId,
    "userId": "userId",
    "otherIds": fMain.otherid,
    "event": name,
    "properties": fMain.properties,
    "receivedAt": appDataReceivedAt,
    "sentAt": appDataSenddAt,
    "timestamp": appTimestemp,
    "type": "track",
    "originalTimestamp": appOriginalTimetemp,
    "writeKey": _writeKey,
  };
  map.addAll({"context": lib});

  //After the full payload is created..now we send all to lemnisk server
  print('track event' + _serverUrl!);
  Uri uri = Uri.parse(_serverUrl!);
  var response = await http.post(uri, body: JsonEncoder().convert(map));
  if (response.statusCode == 200) {
    final String responseString = response.body;
    print('event track success =====   $responseString');
  } else {
    final String responseString = response.body;
    print('event track failed =====   $responseString');
  }

  //appsflyer analytics
  if (_enableAppsFlyer == true) {
    try {
      trackAppsFlyerEvent(name, properties.properties);
    } on Exception catch (e) {
      print("logEvent Appsflyer Error: ${e.toString()}");
    }
  }

  //clevertap analytics
  if (_enableClevertap == true) {
    try {
      trackClevertapEvent(name, properties.properties);
    } on Exception catch (e) {
      print("recordEvent Clevertap Error: ${e.toString()}");
    }
  }

  //firebase analytics
  if (_enableFirebase == true) {
    try {
      trackGaEvent(name, properties.properties);
      print("logEvent GA4 success");
    } on Exception catch (e) {
      print("logEvent GA4 Error: ${e.toString()}");
    }
  }
}