lemnisk_plugin 0.1.0 lemnisk_plugin: ^0.1.0 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 [...]
import 'package:flutter/material.dart';
import 'package:lemnisk_plugin/AttributeBuilder.dart';
import 'package:lemnisk_plugin/LemniskFlutterCore.dart';
import 'package:lemnisk_plugin/LemniskHelper.dart';
import 'package:clevertap_plugin/clevertap_plugin.dart';
import 'dart:io' show Platform;
void main() {
//lemnisk server requirements
String SERVER_URL = "xyz";
String WRITE_KEY = "xyz";
//firebase analytics requirements
LemniskFirebaseCore lemniskFirebaseCore = LemniskFirebaseCore(
projectName: "xxx",
enable: false,
appId: "xxx",
apiKey: "xxx",
projectId: "xxx",
messagingSenderId: "xxx",
);
//apps flyer requirements
LemniskApsflyerCore lemniskApsflyer = LemniskApsflyerCore(
enable: false,
afAppId: "xxx",
afDevKey: "xxx",
);
//apps flyer requirements
LemniskCleverTapCore lemniskCleverTapCore = LemniskCleverTapCore(
enable: true,
isDebug: true
);
LemniskHelper.configure(SERVER_URL, WRITE_KEY, lemniskFirebaseCore,
lemniskApsflyer, lemniskCleverTapCore);
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
void getIdentify() {
AttributeBuilder attributeBuilder = AttributeBuilder();
attributeBuilder.properties['key1'] = 'value1';
attributeBuilder.properties['key2'] = 'value2';
attributeBuilder.properties['lat'] = 13.291860;
attributeBuilder.properties['long'] = 77.751808;
OtherBuilder otherBuilder = OtherBuilder();
otherBuilder.otherid['otherId'] = 'otherId_value';
LemniskHelper.identify("user_id", attributeBuilder, otherBuilder);
}
void getScreen() {
AttributeBuilder attributeBuilder = AttributeBuilder();
attributeBuilder.properties['key1'] = 'value1';
attributeBuilder.properties['key2'] = 'value2';
OtherBuilder otherBuilder = OtherBuilder();
otherBuilder.otherid['otherId'] = 'otherId_value';
LemniskHelper.screen("MainActivity", attributeBuilder, otherBuilder);
}
void getTrack() {
AttributeBuilder attributeBuilder = AttributeBuilder();
attributeBuilder.properties['properties'] = 'material';
attributeBuilder.properties['button'] = 'Track event from different app';
OtherBuilder otherBuilder = OtherBuilder();
otherBuilder.otherid['trackerId'] = '6791c47a-0178-47bc-8711-86a2c67b2255';
LemniskHelper.track("MainDartFile", attributeBuilder, otherBuilder);
}
void setupCTPush() {
LemniskHelper.setPushToken("token");
if(Platform.isIOS) {
CleverTapPlugin.registerForPush();
}
CleverTapPlugin.setPushToken("token");
if (Platform.isAndroid) {
CleverTapPlugin.createNotificationChannel(
"channelId", "channelName", "channelDescription", 3, true);
}
}
void clevertapAppsflyerSink() {
var appsflyerSdk = LemniskHelper.getAppsFlyerSdk();
CleverTapPlugin.getCleverTapID().then((ctId) => appsflyerSdk?.setCustomerUserId(ctId!));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Lemnisk Flutter SDK'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: Text('Track'),
onPressed: () {
getTrack();
},
style: ElevatedButton.styleFrom(
primary: Colors.blue,
padding: EdgeInsets.symmetric(horizontal: 35, vertical: 10),
textStyle:
TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 20,
),
ElevatedButton(
child: Text('Screen'),
onPressed: () {
getScreen();
},
style: ElevatedButton.styleFrom(
primary: Colors.blue,
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 10),
textStyle:
TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 20,
),
ElevatedButton(
child: Text('Identify'),
onPressed: () {
getIdentify();
},
style: ElevatedButton.styleFrom(
primary: Colors.blue,
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 10),
textStyle:
TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
),
SizedBox(
height: 20,
),
ElevatedButton(
child: Text('clevertapPushSetup'),
onPressed: () {
setupCTPush();
},
style: ElevatedButton.styleFrom(
primary: Colors.blue,
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 10),
textStyle:
TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
),
],
),
),
),
);
}
}