mzanalytics 0.0.4 mzanalytics: ^0.0.4 copied to clipboard
A mzanalytics flutter plugin project.
mzanalytics #
A mzanalytics flutter plugin project.
准备工作 🍭 #
##版本限制
Flutter SDK:>=1.17.0
。
##Flutter
将mzanalytics
添加至pubspec.yaml
引用。
dependencies:
mzanalytics: ^latest_version
##示例
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:mzanalytics/mzanalytics.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _cid = 'Unknown';
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String cid;
Mzanalytics.ios_setEnableLog(true);
Mzanalytics.ios_appid("2814");
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 handleTimeout() async { // callback function
Mzanalytics.ios_trackPageView({'pageTitle':"页面",'CustomDimMetrics':{"customDimension1":"点击信用卡",
"customDimension2":"查看商品详情",
"customMetrics1":"点击信用卡总用户数",
"customMetrics2":"查看商品详情总用户数"}});
Mzanalytics.ios_trackEvent({'eventClassify':'点击热门banner','eventAction':'Click','eventTag':'点击'});
Mzanalytics.ios_trackSiteCustomEvent({'CustomEvent':{"customActionId":"1",
"customActionLabel1":"2020/01/10",
"customActionLabel2":"15728749249",
"customActionLabel3":"北京",
"customActionValue1":"1"},'CustomDimMetrics':{"customDimension1":"点击信用卡",
"customDimension2":"查看商品详情",
"customMetrics1":"点击信用卡总用户数",
"customMetrics2":"查看商品详情总用户数"}});
Mzanalytics.ios_trackPulse;
String cid;
cid = await Mzanalytics.ios_getCid;
setState(() {
_cid = cid;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('cid: $_cid\n'),
),
),
);
}
}