flutter友盟分享_flutter中友盟插件开发使用
CSDN-專業IT技術社區-登錄?blog.csdn.net
開發插件要具備的知識:Flutter 與 原生 Android iOS 雙向通信
Flutter通過MethodChannel實現Flutter 與Android iOS 的雙向通信 查看詳情
Flutter通過BasicMessageChannel實現Flutter 與Android iOS 的雙向通信查看詳情
Flutter 中內嵌 Android iOS 原生View的編程基礎
flutter調用android 原生TextView查看詳情
flutter調用ios 原生View查看詳情
最重要的一點是 具備 Android iOS 原生語言的開發能力
flutter_fai_umeng 插件可實現的功能:同時適配于 Android Ios 兩個平臺
實現友盟多渠道統計
實現頁面的進入與退出統計
實現自定義事件的統計
實現錯誤信息的統計
1 基本使用說明
1.1 Flutter 項目中 pubspec.xml 文件中 配置插件
flutter_fai_umeng:
git:
url: https://github.com/zhaolongs/flutter_fai_umeng.git
ref: master
1.2 初始化友盟
import 'package:flutter_fai_umeng/flutter_fai_umeng.dart';
///友盟的初始化
///參數一 appkey
///參數二 推送使用的pushSecret
///參數三 是否打開調試日志
FlutterFaiUmeng.uMengInit("5dcfb8f84ca357f70e000b0a",
pushSecret: "5cb4fc014c143a77fb85cb17edd807a2", logEnabled: true);
flutter_fai_umeng 插件封裝了常用的初始化配制
如在Android 中
public static void uMengInit(Context context, String appkey, String pushSecret, boolean logEnabled) {
///在本方法中使用了[getChannelName]方法來獲取配置在 AndroidManifest.xml中的友盟的渠道名稱
///如使用 360加固打包啟動了多渠道打包配制,getChannelName 方法將會獲取到這個渠道名稱
uMengInit(context, appkey, getChannelName(context), UMConfigure.DEVICE_TYPE_PHONE, pushSecret, logEnabled);
}
/**
* @param channel 渠道的命名規范
* 1.可以由英文字母、阿拉伯數字、下劃線、中劃線、空格、括號組成,可以含漢字以及其他明文字符,但是不建議使用中文命名,會出現亂碼。
* 2.首尾字符不可以為空格。
* 3.不要使用純數字作為渠道ID。
* 4.最多256個字符。
* 5.”unknown” 及其各種大小寫形式,作為【友盟+】保留的字段,不可以作為渠道名。
*
* 在您查看數據時,渠道會作為一個數據細分的維度。
* @param context
* @param appkey
* @param channel
* @param deviceType
* @param pushSecret
*/
public static void uMengInit(Context context, String appkey, String channel, int deviceType, String pushSecret, boolean logEnabled) {
/**
* 設置組件化的Log開關
* 參數: boolean 默認為false,如需查看LOG設置為true
* Error(打印SDK集成或運行時錯誤信息)。
* Warn(打印SDK警告信息)。
* Info(打印SDK提示信息)。
* Debug(打印SDK調試信息)。
*/
UMConfigure.setLogEnabled(logEnabled);
//打開調試模式
MobclickAgent.setDebugMode( logEnabled );
//true打開 ,false為關閉
//禁止默認的頁面統計方式 (一般不用設置,因為默認是進行統計的)
//MobclickAgent.openActivityDurationTrack(true);
//錯誤收集(默認已經配置,而且已經打開)
//MobclickAgent.setCatchUncaughtExceptions(true);
if (channel == null || channel.equals("")) {
channel = "test";
}
if (appkey == null || appkey.equals("")) {
throw new NullPointerException("appkey is null");
}
/**
* 注意: 即使您已經在AndroidManifest.xml中配置過appkey和channel值,也需要在App代碼中調
* 用初始化接口(如需要使用AndroidManifest.xml中配置好的appkey和channel值,
* UMConfigure.init調用中appkey和channel參數請置為null)。
*/
UMConfigure.init(context, appkey, channel, deviceType, pushSecret);
// 選用LEGACY_AUTO頁面采集模式
MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
// 支持在子進程中統計自定義事件
UMConfigure.setProcessEvent(true);
}
/**
* 獲取渠道名
*
* @param ctx 此處習慣性的設置為activity,實際上context就可以
* @return 如果沒有獲取成功,那么返回值為空
*/
public static String getChannelName(Context ctx) {
if (ctx == null) {
return null;
}
String channelName = null;
try {
PackageManager packageManager = ctx.getPackageManager();
if (packageManager != null) {
//注意此處為ApplicationInfo 而不是 ActivityInfo,因為友盟設置的meta-data是在application標簽中,而不是某activity標簽中,所以用ApplicationInfo
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(ctx.getPackageName(), PackageManager.GET_META_DATA);
if (applicationInfo != null) {
if (applicationInfo.metaData != null) {
channelName = applicationInfo.metaData.getString("UMENG_CHANNEL");
}
}
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return channelName;
}
在 ios 中
//日志
[UMConfigure setLogEnabled:logEnabled];
if(logEnabled){
//開發者需要顯式的調用此函數,日志系統才能工作
[UMCommonLogManager setUpUMCommonLogManager];
}
//渠道設置以及友盟的初始化
[UMConfigure initWithAppkey:appkey channel:@"App Store"];
//設置為自動采集頁面
[MobClick setAutoPageEnabled:NO];
1.3 頁面的統計
進入頁面
FlutterFaiUmeng.uMengPageStart("測試頁面1");
退出頁面
FlutterFaiUmeng.uMengPageEnd("測試頁面1");
1.4 自定義事件的統計
FlutterFaiUmeng.uMengEventClick("login");
這里使用到的login 是在友盟管理后臺設置的自定義事件名稱
1.5 錯誤日志統計
友盟官方提到
組件化統計SDK內建JVM層錯誤統計。
SDK通過Thread.UncaughtExceptionHandler 捕獲程序崩潰日志,并在程序下次啟動時發送到服務器
所以在這里編寫的 Flutter 插件是延用的友盟官方的策略,如果是開發者自己捕捉的異常,可手動上傳。
FlutterFaiUmeng.uMengError("有錯誤了");
如有疑問可以回復
總結
以上是生活随笔為你收集整理的flutter友盟分享_flutter中友盟插件开发使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux nas解决方案_阿里产品总监
- 下一篇: 门窗五大核心性能是那些?