flutter_frog(A log plugin for Flutter) Flutter埋点库

Introduction

A business record package for Flutter. stores the user's behavior information locally through sqflite, and then uploads the log to the server in the protobuf format at an appropriate time (every five minutes by default), and has a default failure retransmission mechanism.

Installation 安装

Add flutter_frog as a dependency in your pubspec.yaml file.

dependencies:
  flutter_frog: ^{{latest version}}

Replace {{latest version}} with the version number in badge above.

  1. Install it
$ flutter packages get
  1. Import it
import 'package:flutter_frog/flutter_frog.dart';

Example 示例

import 'package:flutter/cupertino.dart';
import 'package:flutter_frog/flutter_frog.dart';

import 'dart:io';

class ExampleFrog{
  static IFrogLogger _logger;

  static Future<void> initialize() async {
    int device;
    String deviceId;
    String osVersion;
    String appVersion = "example_appVersion";
    String model; // 手机型号
    String manufacturer; // 手机厂商
    String operator; // 运营商, unicom, mobile, telecom
    String imei;
    int productId;
    String vendor; //渠道

    if (Platform.isIOS) {
      vendor = 'apple';
      device = 1;
      productId = 123;
      osVersion = "exampleOsVersion";
      model = "exampleModel";
      manufacturer = "example-Apple";
      imei = "exampleImei";
    } else if (Platform.isAndroid) {
      device = 2;
      productId = 456;
      osVersion = "exampleOsVersion";
      model = "exampleModel";
      manufacturer = "example-Huawei";
      imei = "exampleImei";
      vendor = 'android';
    }
    deviceId = '';
    operator = "example-operator";
    _logger = await initLogger(
      device,
      deviceId,
      osVersion,
      appVersion,
      model,
      manufacturer,
      operator,
      imei,
      productId,
      _initFrog(),
      parameters: {'vendor': vendor},
    );
  }

  static IFrog _initFrog() {
    return FrogBuilder(doPost: (value) {
      return _upload(value);
    }).build();
  }


  static  Future<void> _upload(List<int> data) async {
    //upload log data to your own server
  }

  static void log(String url, {Map<String, dynamic> parameters}) {
    _logger.log(
      url,
      userId: 123456,
      phoneNumber: "13812341234",
      parameters: parameters,
    );
  }



}

void main(){
  ExampleFrog.initialize(); //init Frog when your app init;
}

class ExampleWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ExampleFrog.log("url",parameters: {});// do a frog point
    return Container();
  }
}

Document 说明

Init a logger help you to do log.The init param includes some info filed and a Frog instance.

logger = await initLogger(
      device,
      deviceId,
      osVersion,
      appVersion,
      model,
      manufacturer,
      operator,
      imei,
      productId,
      _initFrog(),
      parameters: {'vendor': vendor},
    );
logger.log("url",parameters:{});

Create Frog instance,call the FrogBuilder to build a Frog instance.

The builder includes four parameters:IFrogStore,IFrogStore,IFrogPostPolicy and Function(data) DoPost.

IFrogStore,IFrogPoster,IFrogPostPolicy all have default implements,you can only post a doPost function to post your frog data to your own server.Also,you can implements your own IFrogStore,IFrogPoster,IFrogPostPolicy to make your

 FrogBuilder(
    {IFrogStore frogStore,
      IFrogPoster frogPoster,
      IFrogPostPolicy frogPostPolicy,
      DoPost doPost})
      : assert((frogPoster == null && doPost != null) ||
            (frogPoster != null && doPost == null)),
        _frogStore = frogStore ?? FrogStoreImpl(),
        _frogPoster = frogPoster ?? FrogPosterImpl(doPost),
        _frogPostPolicy = frogPostPolicy ?? FrogPostPolicyImpl();

IFrogStore is used to store the log to DB by default,you can implements IFrogStore to store the log by your own.

IFrogPoster is used to post the log data to sever,the default FrogPoster gather the data and make you can use a doPost Function to upload data more easily.

IFrogPostPolicy is used to make a post Policy,When to trigger automatic log upload(every 5 minutes),and how many logs would be upload once(100 pieces).

Libraries

entry
flutter_frog
frog_builder
frog_db_provider
frog_impl
frog_interfaces
frog_logger
frog_logger_impl
frog_post_policy_impl
frog_poster_impl
frog_protobuf
frog_store_impl
logger_utils
protobuf_frog_item
sql_manager