mzanalytics 0.1.6 mzanalytics: ^0.1.6 copied to clipboard
A plugin for the Flutter project of iOS and Android platform based on MZAnalytics SDK.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:mzanalytics/mzanalytics.dart';
import 'dart:io';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _cid = 'Unknown';
String _oaid = 'Unknown';
@override
void initState() {
super.initState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> android_initEvent() async {
try {
Mzanalytics.android_initEvent();
} on PlatformException {}
if (!mounted) return;
}
Future<void> android_sendBaseEvent() async {
try {
Mzanalytics.android_sendBaseEvent({
"dt": '首⻚⻚面',
"ec": '点击热⻔banner',
"ea": 'Click',
"el": '点击',
"ev": '10',
});
} on PlatformException {}
if (!mounted) return;
}
Future<void> android_pageEvent() async {
try {
Mzanalytics.android_pageEvent({
"dt": '底部导航栏',
});
} on PlatformException {}
if (!mounted) return;
}
Future<void> android_seniorEvent() async {
try {
Mzanalytics.android_seniorEvent({
"cal1": '提交订单',
"cal2": '支付订单',
"cav1": '提交订单数',
"cav2": '支付订单数',
"caid": '1',
});
} on PlatformException {}
if (!mounted) return;
}
Future<void> android_heartEvent() async {
try {
Mzanalytics.android_heartEvent();
} on PlatformException {}
if (!mounted) return;
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> ios_event() async {
String cid;
const timeout = const Duration(seconds: 2);
const ms = const Duration(milliseconds: 1);
// startTimeout([int milliseconds]) {
// var duration = milliseconds == null ? timeout : ms * milliseconds;
// return new Timer(duration, handleTimeout);
// }
// new Timer(timeout, handleTimeout);
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
}
void getcid() async {
// callback function
String cid;
if(Platform.isIOS){
cid = await Mzanalytics.ios_getCid;
}else if(Platform.isAndroid){
cid = await Mzanalytics.android_getCid();
}
setState(() {
_cid = cid;
});
}
void getoaid() async {
// callback function
String oaid;
if(Platform.isIOS){
oaid ="无";
}else if(Platform.isAndroid){
oaid = await Mzanalytics.android_getOaid();
}
setState(() {
_oaid = oaid;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Container(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
RaisedButton(
onPressed: () {
if(Platform.isIOS){
Mzanalytics.ios_appid("2815");
}else if(Platform.isAndroid){
android_initEvent();
}
},
child: Text('初始化'),
),
RaisedButton(
onPressed: () {
if(Platform.isIOS){
Mzanalytics.ios_trackPageView({
'pageTitle': "页面"
});
}else if(Platform.isAndroid){
android_pageEvent();
}
},
child: Text('页面事件'),
),
RaisedButton(
onPressed: () {
if(Platform.isIOS){
Mzanalytics.ios_trackEvent({
'eventClassify': '点击热门banner',
'eventAction': 'Click',
'eventTag': '点击'
});
}else if(Platform.isAndroid){
android_sendBaseEvent();
}
},
child: Text('自定义事件监测'),
),
RaisedButton(
onPressed: () {
if(Platform.isIOS){
Mzanalytics.ios_trackSiteCustomEvent({
'CustomEvent': {
"customActionId": "1",
"customActionLabel1": "2020/01/10",
"customActionLabel2": "15728749249",
"customActionLabel3": "北京",
"customActionValue1": "1"
},
'CustomDimMetrics': {
"customDimension1": "点击信用卡",
"customDimension2": "查看商品详情",
"customMetrics1": "点击信用卡总用户数",
"customMetrics2": "查看商品详情总用户数"
}
});
}else if(Platform.isAndroid){
android_seniorEvent();
}
},
child: Text('高级自定义事件'),
),
RaisedButton(
onPressed: () {
if(Platform.isIOS){
Mzanalytics.ios_trackPulse;
}else if(Platform.isAndroid){
android_heartEvent();
}
},
child: Text('心跳事件'),
),
RaisedButton(
onPressed: () {
getcid();
},
child: Text('cid: $_cid\n'),
),
RaisedButton(
onPressed: () {
getoaid();
},
child: Text('oaid: $_oaid\n'),
),
],
),
),
),
);
}
}