Flutter 友盟自定义事件统计flutter_fai_umeng

添加自定义事件 

Flutter 友盟自定义事件统计flutter_fai_umeng_第1张图片

 

Flutter 友盟自定义事件统计flutter_fai_umeng_第2张图片

 flutter_fai_umeng 插件

pubspec.yaml 引入插件依赖

Flutter 友盟自定义事件统计flutter_fai_umeng_第3张图片

执行命令

flutter pub get
​例如 : Running "flutter pub get" in flutter_umeng_tj...                    0.5s

依赖加载成功后的模样

 

State 函数initState 进行初始化操作

@override
void initState() {
  // TODO: implement initState
  super.initState();

  ///友盟的初始化
  ///参数一 appkey
  ///参数二 推送使用的pushSecret
  ///参数三 是否打开调试日志
  FlutterFaiUmeng.uMengInit("", pushSecret: "", logEnabled: true);
  FlutterFaiUmeng.uMengPageStart("MyHomePage");
}

注册开始页面

@override
void initState() {
  // TODO: implement initState
  super.initState();

  ......

  FlutterFaiUmeng.uMengPageStart("MyHomePage");

  ......
}

页面结束

@override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    FlutterFaiUmeng.uMengPageStart("MyHomePage");
  }
import 'package:flutter/material.dart';
import 'package:flutter_fai_umeng/flutter_fai_umeng.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
  void _incrementCounter() {
    FlutterFaiUmeng.uMengEventClick("login");
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    ///友盟的初始化
    ///参数一 appkey
    ///参数二 推送使用的pushSecret
    ///参数三 是否打开调试日志
    FlutterFaiUmeng.uMengInit("",pushSecret: "", logEnabled: true);

    FlutterFaiUmeng.uMengPageStart("MyHomePage");
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    FlutterFaiUmeng.uMengPageStart("MyHomePage");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              'You have pushed the button this many times:',
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

 

 统计结果

Flutter 友盟自定义事件统计flutter_fai_umeng_第4张图片

 

你可能感兴趣的:(Flutter)