美文网首页
ionic接入友盟埋点和统计

ionic接入友盟埋点和统计

作者: 一只特立独行的道哥 | 来源:发表于2021-01-13 15:27 被阅读0次

    App 接入的是友盟 SDK
    接入文档: 传送门
    SDK 版本号: iOS(6.0.1),android(8.0.0)
    插件: cordova-plugin-jb-umenganalytics

    缺陷:目前暂不支持 browser 版的统计和埋点

    安装

    cordova plugin add cordova-plugin-jb-umenganalytics --variable UMENGKEYIOS=iOS Appkey --variable UMENGKEYANDROID=android AppKey

    AppKey 在友盟平台中创建 app 后获取

    注意事项

    1. iOS 项目

    AppDelegate.m文件中加入如下代码:

    - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
    {
        self.viewController = [[MainViewController alloc] init];
        // 打开日志,会在终端输出统计SDK日志,生产包设置为NO
        [UMConfigure setLogEnabled:YES];
        // 注册appKey,channel在开发包和生产包应该区分开
        [UMConfigure initWithAppkey:@"iOS AppKey" channel:@"Debug"];
        return [super application:application didFinishLaunchingWithOptions:launchOptions];
    }
    

    2. Android 项目

    MainActivity.java文件中加入如下代码:

     public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
    
            // enable Cordova apps to be started in the background
            Bundle extras = getIntent().getExtras();
            if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
                moveTaskToBack(true);
            }
    
            // Set by <content src="index.html" /> in config.xml
            loadUrl(launchUrl);
            String key =  "Android AppKey";
            String channel = "Debug";
            PGCommonSDK.init(this,key,channel, UMConfigure.DEVICE_TYPE_PHONE,"");
            MobclickAgent.setSessionContinueMillis(1000);
            // 打开统计SDK调试模式
            UMConfigure.setLogEnabled(true);
    
        }
    

    3. 埋点使用

    在使用事件埋点前需要现在友盟平台定义该事件,iOS 和 android 还是分开的
    友盟设置自定义事件路径: android/iOS->功能使用->自定义事件->设置->添加事件(可以批量导入)

    然后就可以使用如下代码来上报事件了

    window.AnalyticsAgent.onEventWithLabel(eventId,label)
    

    相关文章

      网友评论

          本文标题:ionic接入友盟埋点和统计

          本文链接:https://www.haomeiwen.com/subject/jfnuaktx.html