zhugeio 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 79

zhugeio #

诸葛io 插件,封装了 iOS & Android SDK 常用 API ,使用此插件,可以完成埋点的统计上报。

1. 在项目中添加安装插件 #

在 Flutter 项目的 pubspec.yam 文件中添加 zhugeio 依赖

dependencies:
  # zhugeio flutter plugin 
  zhugeio: ^1.0.0

执行 flutter packages get 命令安装插件

  flutter packages get  

Flutter 官网文档

2. Android 端 #

添加所需权限

<!--需要网络权限-->
<uses-permission  
  android:name="android.permission.INTERNET"/>
<!--需要获取网络状态-->
<uses-permission  
  android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission  
  android:name="android.permission.ACCESS_WIFI_STATE"/>
<!--获取设备唯一标识-->
<uses-permission  
  android:name="android.permission.READ_PHONE_STATE"/>

项目中添加依赖

dependencies {
    implementation 'com.ZhugeioAnalytic:zhugeio:3.4.1'
}

初始化

import com.zhuge.analysis.stat.ZhugeParam;
import com.zhuge.analysis.stat.ZhugeSDK;


public class MainActivity extends FlutterActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GeneratedPluginRegistrant.registerWith(this);

    ZhugeParam param = new ZhugeParam.Builder().appKey("appkey")
            .appChannel("channel")
            .build();
    ZhugeSDK.getInstance().initWithParam(getApplicationContext(), param);
  }

}

3. iOS 端 #

首先执行

cd ios
pod install

用应用的AppKey启动诸葛io SDK

 #import "Zhuge.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[Zhuge sharedInstance] startWithAppKey:@"Your App Key" launchOptions:launchOptions];
}

如果你需要修改SDK的默认设置,如设置版本渠道时,一定要在startWithAppKey前执行;代码如下:

    Zhuge *zhuge = [Zhuge sharedInstance];

    // 实时调试开关
    // 设置为YES,可在诸葛io的「实时调试」页面实时观察事件数据上传
    // 建议仅在需要时打开,调试完成后,请及时关闭
    [zhuge.config setDebug : NO];

    // 自定义应用版本
    [zhuge.config setAppVersion:@"0.9-beta"]; // 默认是info.plist中CFBundleShortVersionString值

    // 自定义渠道
    [zhuge.config setChannel:@"My App Store"]; // 默认是@"App Store"

    // 开启行为追踪
    [zhuge startWithAppKey:@"Your App Key" launchOptions:launchOptions];

4. Flutter 中使用插件 #

在具体 dart 文件中导入 zhugeio.dart

import 'package:zhugeio/zhugeio.dart';

4.1 普通埋点事件 #

Zhugeio.track("购买", {"商品名称":"iPhone","内存":"128g"});

4.2 识别用户 #

Zhugeio.identify("zhangsan", {"age":18});

4.3 收入事件 #

Map product = {"price":5400,  
               "productQuantity":2,
               "productID":"abcd",
               "revenueType":"手机"};
Zhugeio.trackRevenue(product);

1.0.1 #

  • 用户追踪
  • 事件追踪
  • 收入事件追踪

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:zhugeio/zhugeio.dart';

import 'button.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  TextEditingController userNameController;
  TextEditingController userKeyController;
  TextEditingController userValueController;

  TextEditingController eventNameController;
  TextEditingController key0controller;
  TextEditingController value0controller;
  TextEditingController key1controller;
  TextEditingController value1controller;


  TextEditingController priceController;
  TextEditingController productIdController;
  TextEditingController productQuantityController;
  TextEditingController typeController;


  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await Zhugeio.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // 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.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {

    userNameController = new TextEditingController();
    userKeyController = new TextEditingController();
    userValueController = new TextEditingController();

    eventNameController = new TextEditingController();
    key0controller = new TextEditingController();
    value0controller = new TextEditingController();
    key1controller = new TextEditingController();
    value1controller = new TextEditingController();

    priceController = new TextEditingController();
    productIdController = new TextEditingController();
    productQuantityController = new TextEditingController();
    typeController = new TextEditingController();
    
    _buildButton(int tag, String title) {
      return new Container(
        margin: EdgeInsets.only(top: 0.0,left: 15.0),
        height: 30.0,
        width: 150.0,
        child: new MaterialButton(
          color: Colors.blue,
          textColor: Colors.white,
          child: new Text(title),
          onPressed: () {
            clickButton(tag);
          },
        ),
      );
    }

    _buildTextField(String hintText, TextEditingController _controller) {
      return new Container(
        margin: EdgeInsets.only(top: 5.0,left: 15.0,right: 15),
        height: 39.0,
//        SingleChildScrollView
        child: new TextField(
          controller: _controller,
          decoration: InputDecoration(
            contentPadding: EdgeInsets.all(5.0),
            border: OutlineInputBorder (
              borderRadius: BorderRadius.circular(4.0),
            ),
            fillColor: Colors.white70,
            filled: true,
            hintText: hintText,
          ),
        ),
      );
    }

    _buildTitle(String title) {
      return new Container(
        margin: EdgeInsets.only(top: 20.0,left: 15.0,right: 15.0),
        child: Text(
          title,
          style: TextStyle(fontWeight: FontWeight.bold),
        ),
      );
    }

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin Zhugeio app'),
        ),
        body: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              /// 用户追踪
              _buildTitle("UserID:"),

              _buildTextField("用户名", userNameController),

              Row(
                children: <Widget>[
                  new Expanded(
                    child: _buildTextField("key",userKeyController),
                  ),
                  new Expanded(
                    child: _buildTextField("value",userValueController),
                  ),
                ],
              ),
              _buildButton(0,"追踪用户"),

              /// 自定义事件追踪
              _buildTitle("自定义事件测试:"),
              _buildTextField("事件名称",eventNameController),
              Row(
                children: <Widget>[
                  new Expanded(
                    child: _buildTextField("Key0",key0controller),
                  ),
                  new Expanded(
                    child: _buildTextField("Value0",value0controller),
                  ),
                ],
              ),
              Row(
                children: <Widget>[
                  new Expanded(
                    child: _buildTextField("Key1",key1controller),
                  ),
                  new Expanded(
                    child: _buildTextField("Value1", value1controller),
                  ),
                ],
              ),
              _buildButton(1,"TrackDefault"),

              /// 收入事件追踪
              _buildTitle("收入事件测试:"),
              Row(
                children: <Widget>[
                  new Expanded(
                    child: _buildTextField("Price",priceController),
                  ),
                  new Expanded(
                    child: _buildTextField("ProductQuantity",productQuantityController),
                  ),
                ],
              ),

              Row(
                children: <Widget>[
                  new Expanded(
                    child: _buildTextField("ProductId",productIdController),
                  ),
                  new Expanded(
                    child: _buildTextField("Type",typeController),
                  ),
                ],
              ),
              _buildButton(2,"TrackRevenue"),

            ],
          ),
        )
      ),
    );
  }

  clickButton(int tag) {
    if(tag == 0) {
//      Zhugeio.identify("zhangsan", {"age":18});
      Zhugeio.identify(userNameController.text, getUserInfo());
    } else if (tag == 1) {
//      Zhugeio.track("购买", {"商品名称":"iPhone","内存":"128g"});
      Zhugeio.track(eventNameController.text, getDefaultEventsInfo());
    } else if (tag == 2) {
      Zhugeio.trackRevenue(getRevenueEventsInfo());
    }

  }

  Map getUserInfo() {
    Map userPro;
    userPro = {userKeyController.text:userValueController.text};
    print( userNameController.text + "== $userPro" );
    return userPro;
  }

  Map getDefaultEventsInfo() {
    Map defaultPro;
    defaultPro = {key0controller.text:value0controller.text, key1controller.text:value1controller.text};
    print( eventNameController.text + "== $defaultPro" );
    return defaultPro;

  }

  Map getRevenueEventsInfo() {
    Map revenuePro;
//    revenuePro.put("price",100.12);  //数值型属性不要带引号
//    revenuePro.put("productID","小米NFC手环");
//    revenuePro.put("productQuantity",2); //数值型属性不要带引号
//    revenuePro.put("revenueType","手环");
    revenuePro = {"price":priceController.text,
                  "productQuantity":productQuantityController.text,
                  "productID":productIdController.text,
                  "revenueType":typeController.text};
    print("RevenuePro == $revenuePro" );
    return revenuePro;
  }





}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  zhugeio: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:zhugeio/zhugeio.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
57
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/zhugeio.dart.

Run flutter format to format lib/zhugeio.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test