event_tracker 0.0.1
event_tracker: ^0.0.1 copied to clipboard
The Lemnisk Flutter SDK allows you to track user event data from your Android app. The SDK can be easily imported into any Android or iOS app. Based on the data it receives from the user activity, it [...]
example/lib/main.dart
import 'dart:async';
import 'dart:convert';
import 'dart:math';
import 'package:appsflyer_sdk/appsflyer_sdk.dart';
import 'package:event_tracker/LemniskFlutterScreen.dart';
import 'package:event_tracker/model/TrackBulider.dart';
import 'package:event_tracker/model/TrackModel.dart';
import 'package:event_tracker/platform_device_id.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String? _deviceId;
String? _deviceType;
String? _deviceManufacture;
String? _deviceModel;
String? _androidID;
String? _versionName;
String? _appName;
String? _appVersion;
String? _appBuildNo;
String? _googleAdvertisingID;
String? _networkIP;
String? _writeKey;
String? _appScreenHeightWidth;
String? _appScreenHeightHeight;
String? _appDataReceivedAt;
dynamic? _googleAdvertisingBool;
String? _appDataSenddAt;
AppsflyerSdk? appsflyerSdk;
String? _appOriginalTimetemp;
String? _appTimestemp;
@override
void initState() {
super.initState();
initPlatformState();
// initAppsFlyer();
print('rishiiii ${DateTime.now().toUtc()}');
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String? deviceId;
String? deviceType;
String? deviceManufacture;
String? deviceModel;
String? versionName;
String? appName;
String? appVersion;
String? appBuild;
String? googleAdvertisingID;
dynamic? googleAdvertisingBool;
String? networkIP;
String? writekey;
String? appScreenHeightWidth;
String? appScreenHeightHeight;
String? appDataReceivedAt;
String? appDataSenddAt;
String? appOriginalTimetemp;
String? appTimestemp;
try {
deviceId = await PlatformDeviceId.getDeviceId;
deviceType = await PlatformDeviceId.getPlatFormDeviceType;
deviceModel = await PlatformDeviceId.getDeviceModel;
deviceManufacture = await PlatformDeviceId.getManufactureModel;
versionName = await PlatformDeviceId.getOSVersion;
appName = await PlatformDeviceId.getAppName;
appVersion = await PlatformDeviceId.getAppVersion;
appBuild = await PlatformDeviceId.getBuildNumber;
googleAdvertisingID = await PlatformDeviceId.getGoogleadvertisingID;
googleAdvertisingBool = await PlatformDeviceId.getGoogleadvertisingIDBoolValue;
networkIP = await PlatformDeviceId.getNetworkIP;
writekey = await PlatformDeviceId.getWriteKey;
appScreenHeightHeight = await PlatformDeviceId.getScreenHeight;
appScreenHeightWidth = await PlatformDeviceId.getScreenWidth;
appDataReceivedAt = await PlatformDeviceId.getReceivedAt;
appDataSenddAt = await PlatformDeviceId.getSendAt;
appOriginalTimetemp = await PlatformDeviceId.getOriginalTimetemp;
appTimestemp = await PlatformDeviceId.getTimestemp;
} on PlatformException {
deviceId = 'Failed to get deviceId.';
}
if (!mounted) return;
setState(() {
_deviceId = deviceId;
_deviceType = deviceType;
_deviceModel = deviceModel;
_deviceManufacture = deviceManufacture;
_versionName = versionName;
_appName = appName;
_appVersion = appVersion;
_appBuildNo = appBuild;
_googleAdvertisingID = googleAdvertisingID;
_networkIP = networkIP;
_writeKey = writekey;
_appScreenHeightHeight = appScreenHeightHeight;
_appScreenHeightWidth = appScreenHeightWidth;
_googleAdvertisingBool = googleAdvertisingBool;
_appDataReceivedAt = appDataReceivedAt;
_appDataSenddAt = appDataSenddAt;
_appOriginalTimetemp = appOriginalTimetemp;
_appTimestemp = appTimestemp;
});
print("->$_deviceId");
print("->$_deviceType");
print("->$_deviceModel");
print("->$_deviceManufacture");
print("->$_versionName");
print("->$_appName");
print("->$_appVersion");
print("->$_appBuildNo");
print("->$_googleAdvertisingID");
print("->$_networkIP");
print("->$_writeKey");
print("->$_appScreenHeightWidth");
print("->$_appScreenHeightHeight");
print("->$_appDataReceivedAt");
print("->$_appDataSenddAt");
print("->$googleAdvertisingBool");
}
//aps flyter inisilization
// Future<void> initAppsFlyer() async {
// Map appsFlyerOptions = {"afDevKey": 'afDevKey', "afAppId": _deviceId, "isDebug": true};
//
// appsflyerSdk = AppsflyerSdk(appsFlyerOptions);
// appsflyerSdk?.initSdk(
// registerConversionDataCallback: true,
// registerOnAppOpenAttributionCallback: true,
// registerOnDeepLinkingCallback: true,
// );
// appsflyerSdk?.onAppOpenAttribution((res) {
// print("onAppOpenAttribution: " + res.toString());
// });
//
// appsflyerSdk?.onInstallConversionData((res) {
// print("res: " + res.toString());
// });
//
// appsflyerSdk?.onDeepLinking((res) {
// print("res: " + res.toString());
// });
// }
Future<void> getTrackFromFun() async {
//create a properties map
TrackBulider trackBulider = TrackBulider();
trackBulider.properties['properties'] = 'carousel';
trackBulider.properties['button'] = 2;
//craete a otherid map
OtherID otheridBulider = OtherID();
otheridBulider.trackerId['trackerId'] = '6791c47a-0178-47bc-8711-86a2c67b2255';
Future<TrackModel?> screenTrack = LemniskFlutterScreen.screen("MainActivity", trackBulider, otheridBulider);
TrackModel? fMain = await screenTrack;
//create hole map
Map<dynamic, dynamic> lib = {
"library": {
"name": "Flutter SDK",
"version": "0.01",
},
"app": {
"name": _appName,
"version": _appVersion,
"build": _appBuildNo,
},
"device": {
"id": _deviceId,
"advertisingId": _googleAdvertisingID,
"adTrackingEnabled": _googleAdvertisingBool,
"manufacturer": _deviceManufacture,
"model": _deviceModel,
"type": _deviceType,
"token": "ff15bc0c20c4aa6cd50854ff165fd265c838e5405bfeb9571066395b8c9da449",
},
"screen": {
"width": _appScreenHeightWidth,
"height": _appScreenHeightHeight,
"density": 2,
},
"userAgent": {
"osType": _deviceType,
"osVersion": _versionName,
},
"ip": _networkIP
};
Map map = {
"id": getRandomString(20),
"userId": "6791c47a-0178-47bc-8711-86a2c67b2255",
"otherIds": fMain!.otherid,
"event": fMain.activityName,
"messageId": "ajs-f8ca1e4de5024d9430b3928bd8ac6b96",
"properties": fMain.properties,
"receivedAt": _appDataReceivedAt,
"sentAt": _appDataSenddAt,
"timestamp": _appTimestemp,
"type": "track",
"originalTimestamp": _appOriginalTimetemp,
"writeKey": _writeKey,
};
map.addAll({"context": lib});
print(JsonEncoder().convert(map));
//networking......
//Provider.of<EventProvider>(context, listen: false).sendDataToLemnisk(context, JsonEncoder().convert(map));
//we can hit on server....
String url = "https://tpl.lemnisk.co/analyze/analyze.php";
print('trackevent' + url);
Uri uri = Uri.parse(url);
// trackPayLoad = JsonEncoder().convert(map);
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 falied===== $responseString');
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Events'),
),
body: Center(
child: SingleChildScrollView(
child: Column(
children: [
Column(
children: [
SizedBox(
height: 20,
),
Text('Device Related Info'),
Divider(),
Text('Device ID : $_deviceId'),
Text('Device Type : $_deviceType'),
Text('Device Model : $_deviceModel'),
Text('Device Manufacture : $_deviceManufacture'),
Text('Device Android ID : $_androidID'),
Text('Device version name : $_versionName'),
SizedBox(
height: 20,
),
Text('App Related Info'),
Divider(),
Text('AppName : $_appName'),
Text('AppVersion : $_appVersion'),
Text('AppBuild No : $_appBuildNo'),
SizedBox(
height: 20,
),
Text('Google Advertising Info'),
Divider(),
Text('GoogleAdverising ID : $_googleAdvertisingID'),
SizedBox(
height: 20,
),
Text('IP address Info'),
Divider(),
Text('Network IP : $_networkIP'),
SizedBox(
height: 20,
),
Text('Another Info'),
Divider(),
Text('WriteKey : $_writeKey'),
Text('Screen Width : $_appScreenHeightWidth'),
Text('Screen Height : $_appScreenHeightHeight'),
Text('Received : $_appDataReceivedAt'),
Text('timestamp : $_appDataReceivedAt'),
Text('originalTimestamp : $_appDataReceivedAt'),
Text('SendTimesTemp : $_appDataSenddAt'),
],
),
SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {
getTrackFromFun();
},
child: Text('Track'),
),
SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {},
child: Text('Screen'),
),
SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {},
child: Text('Identifier'),
),
],
),
),
),
),
);
}
}
void createTrackMap() {
var id = getRandomString(20);
var userid = getRandomString(30);
}
const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
Random _rnd = Random();
String getRandomString(int length) => String.fromCharCodes(Iterable.generate(length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));