App 接入的是友盟 SDK
接入文檔: 傳送門
SDK 版本號: iOS(6.0.1),android(8.0.0)
插件: cordova-plugin-jb-umenganalytics
缺陷:目前暫不支持 browser 版的統(tǒng)計和埋點
安裝
cordova plugin add cordova-plugin-jb-umenganalytics --variable UMENGKEYIOS=iOS Appkey --variable UMENGKEYANDROID=android AppKey
AppKey 在友盟平臺中創(chuàng)建 app 后獲取
注意事項
1. iOS 項目
在AppDelegate.m
文件中加入如下代碼:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.viewController = [[MainViewController alloc] init];
// 打開日志慢宗,會在終端輸出統(tǒng)計SDK日志,生產(chǎn)包設(shè)置為NO
[UMConfigure setLogEnabled:YES];
// 注冊appKey,channel在開發(fā)包和生產(chǎn)包應(yīng)該區(qū)分開
[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);
// 打開統(tǒng)計SDK調(diào)試模式
UMConfigure.setLogEnabled(true);
}
3. 埋點使用
在使用事件埋點前需要現(xiàn)在友盟平臺定義該事件,iOS 和 android 還是分開的
友盟設(shè)置自定義事件路徑: android/iOS->功能使用->自定義事件->設(shè)置->添加事件(可以批量導(dǎo)入)
然后就可以使用如下代碼來上報事件了
window.AnalyticsAgent.onEventWithLabel(eventId,label)