企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 账号和概念 登录网站<https://www.jiguang.cn/>申请。如何在后台创建应用、[查阅文档](http://docs.jiguang.cn/jpush/client/Android/android_sdk/)不再赘述。 # Android项目配置 新建一个Android项目,打开module下的gradle文件,查看applicationId是否和后台配置的文件包名一致。同时在defaultConfig中添加manifestPlaceholders。 ~~~ defaultConfig { applicationId "com.fymod.jpush" minSdkVersion 14 targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" manifestPlaceholders = [ JPUSH_APPKEY : "201dc8c87b057a824b49ac94", //JPush上注册的包名对应的appkey. JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可. ] } ~~~ 在dependencies中添加极光的引入 ~~~ compile 'cn.jiguang.sdk:janalytics:1.1.1' // 此处以JAnalytics 1.1.1 版本为例。 compile 'cn.jiguang.sdk:jcore:1.1.2' // 此处以JCore 1.1.2 版本为例。 ~~~ 为了方便统一管理,我新建了一个Application,并在AndroidManifest.xml中设置为application的android:name。 ~~~ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.fymod.jpush"> <application android:name=".MainApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name="com.fymod.jpush.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> ~~~ 在Application中添加初始化代码 ~~~ JAnalyticsInterface.setDebugMode(true); //开启调试模式 JAnalyticsInterface.init(this); //初始化 JAnalyticsInterface.initCrashHandler(this); //开启crashlog日志上报 ~~~ # 页面统计 在每个Activity或者Fragment的onResume中添加 JAnalyticsInterface.onPageStart(this,this.getClass().getCanonicalName()); 在onPause方法中添加JAnalyticsInterface.onPageEnd(this,this.getClass().getCanonicalName()); 最简单的办法是定义一个基类Activity,其他所有Activity都继承这个基类,这样只需要在基类里面添加上代码就行了。 ~~~ @Override protected void onResume() { JAnalyticsInterface.onPageStart(this,this.getClass().getCanonicalName()); super.onResume(); } @Override protected void onPause() { JAnalyticsInterface.onPageEnd(this,this.getClass().getCanonicalName()); super.onPause(); } ~~~ # 事件模型 极光提供了多种事件模型,CountEvent(计数事件)、CalculateEvent(计算事件)、RegisterEvent(注册事件)、LoginEvent(登录事件)、BrowseEvent(浏览事件)、PurchaseEvent(购买事件) 我测试并非所有事件模型都能成功,要根据具体情况和极光版本而定。 ~~~ // 测试计数事件 public void testCountEvent() { CountEvent cEvent = new CountEvent("eventId"); cEvent.addKeyValue("key1","value1").addKeyValue("key2","value2"); JAnalyticsInterface.onEvent(this, cEvent); } // 测试计算事件 // 通过相同的事件不同的值进行累加 public void testCalculateEvent() { CalculateEvent cEvent = new CalculateEvent(); cEvent.setEventId("eventId2"); cEvent.setEventValue(999.9).addKeyValue("key1","value1").addKeyValue("key2","value2"); JAnalyticsInterface.onEvent(this, cEvent); } // 测试注册事件 public void testRegisterEvent() { RegisterEvent rEvent = new RegisterEvent("sina",true); rEvent.addKeyValue("key1","value1").addKeyValue("key2","value2"); JAnalyticsInterface.onEvent(this, rEvent); } // 测试登录事件 public void testLoginEvent() { LoginEvent lEvent = new LoginEvent("qq",true); lEvent.addKeyValue("key1","value1").addKeyValue("key2","value2"); JAnalyticsInterface.onEvent(this, lEvent); } // 测试浏览事件 // 上传参数包含浏览了多长时间,单位是秒 public void testBrowseEvent() { BrowseEvent bEvent = new BrowseEvent("browseId","热点新闻","news",30); bEvent.addKeyValue("key1","value1").addKeyValue("key2","value2"); JAnalyticsInterface.onEvent(this, bEvent); } // 测试购买事件 public void testPurchaseEvent() { PurchaseEvent pEvent = new PurchaseEvent("goodsId","篮球",300,true, Currency.CNY,"sport",100); pEvent.addKeyValue("key1","value1").addKeyValue("key2","value2"); JAnalyticsInterface.onEvent(this, pEvent); } ~~~ 更详细的事件模型说明和未介绍的账号统计可移动[这里](https://docs.jiguang.cn/janalytics/client/android_api/)查看 # 统计查看 登录极光网站管理控制台,每个项目下方都有统计的入口文字。