one_target_mobile_sdk 0.0.2 one_target_mobile_sdk: ^0.0.2 copied to clipboard
G1 tracking's plugin
import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:one_target_mobile_sdk/one_target_mobile_sdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String input = "";
String output = "";
@override
void initState() {
super.initState();
_setupTracking();
}
void _log(String msg) {
if (kDebugMode) {
print(msg);
}
}
void _setupTracking() {
Analytics.setupTracking(
true,
"490bf1f1-2e88-4d6d-8ec4-2bb7de74f9a8",
isShowLog: false,
).then((isSetupSuccess) {
_log("_setupTracking isSetupSuccess $isSetupSuccess");
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios, color: Colors.white),
onPressed: () {
exit(0);
},
),
centerTitle: true,
title: const Text('OneTargetMobileSDK'),
),
body: ListView(
padding: const EdgeInsets.all(16.0),
physics: const BouncingScrollPhysics(),
children: [
SampleButton(
text: "Send event 1",
onPressed: () {
_trackEvent1();
},
),
SampleButton(
text: "Send event 2",
onPressed: () {
_trackEvent2();
},
),
const SizedBox(height: 32.0),
const Text('>>>INPUT'),
Text(_getPrettyString()),
const SizedBox(height: 32.0),
const Text('<<<OUTPUT'),
Text(output),
],
),
),
);
}
void _trackEvent1() {
_refreshInput("");
_refreshOutput("");
Analytics.trackEvent(
"490bf1f1-2e88-4d6d-8ec4-2bb7de74f9a8",
{
"user_id": "U1${DateTime.now().millisecondsSinceEpoch}",
"phone": "0123456789",
"email": "loitp@galaxy.one",
"deviceId": "999999999",
},
"event_name",
DateTime.now().millisecondsSinceEpoch,
{
"pageTitle": "Passenger Information",
"pagePath": "/home",
},
onResponse: (input, isSuccessful, code, response) {
_log(">>>onResponse $input $isSuccessful, $code, $response");
_refreshInput("$input");
_refreshOutput(
"isSuccessful: $isSuccessful, code: $code, response: $response");
},
onFailure: (input, e) {
_log(">>>onFailure $e");
_refreshInput("$input");
_refreshOutput("$e");
},
);
}
void _trackEvent2() {
_refreshInput("");
_refreshOutput("");
Analytics.trackEvent(
"490bf1f1-2e88-4d6d-8ec4-2bb7de74f9a8",
{
"user_id": "U2${DateTime.now().millisecondsSinceEpoch}",
"phone": "000111222",
"email": "loitp@galaxy.one",
"deviceId": "8888888888",
},
"track_now_event",
DateTime.now().millisecondsSinceEpoch,
{
"name": "Loitp",
"bod": "01/01/2000",
"player_id": 123456,
},
onResponse: (input, isSuccessful, code, response) {
_log(">>>onResponse $input $isSuccessful, $code, $response");
_refreshInput("$input");
_refreshOutput(
"isSuccessful: $isSuccessful, code: $code, response: $response");
},
onFailure: (input, e) {
_log(">>>onFailure $e");
_refreshInput("$input");
_refreshOutput("$e");
},
);
}
void _refreshInput(String input) {
setState(() {
this.input = input;
});
_refreshOutput("");
}
void _refreshOutput(String output) {
setState(() {
this.output = output;
});
}
String _getPrettyString() {
String prettyString = "";
if (input.isNotEmpty) {
final object = json.decode(input);
prettyString = const JsonEncoder.withIndent(' ').convert(object);
}
return prettyString;
}
}