Android中統計分析的SDK ,友盟統計,百度統計,騰訊統計
APP統計分析
使用者畫像
對程式設計師來說,使用者畫像就是使用者的屬性和行為;通俗地說,使用者畫像是包括了個人資訊、興趣愛好、日常行為等血肉豐滿的客戶實體。使用者畫像是精準營銷的產物,企業通過收集使用者的行為,然後分析出使用者的特徵與偏好,進而挖掘潛在的商業價值,實現企業效益的最大化。使用者畫像的一個具體應用是電商app的“猜你喜歡”欄目,電商平臺通過對使用者購買過的商品進行統計,可以分析使用者日常生活用的是什麼物品;電商平臺還可以對使用者的搜尋行為、瀏覽行為進行統計,從中分析使用者感興趣的商品,或者說考慮購買的商品。電商平臺得到包括日常生活、興趣愛好、購買意向在內的使用者畫像後,自然就能有針對性的向用戶推薦合適的商品,從而擴大銷量、增加營業額。
下圖是使用者畫像的一個具體例子
統計分析的內容
app進行統計分析,主要有兩方面的內容:一、使用者行為統計,包括
1、使用者開啟和關閉頁面,以及在頁面的停留時長;
2、使用者點選行為的分佈與頻率;
3、使用者輸入的文字和圖片,如搜尋時的關鍵詞、二維碼的掃描資訊、分享的圖文內容等等;
4、使用者對多媒體資訊的接受程式,如聽音樂的時長、看視訊的時長等等;
二、執行情況分析,包括
1、app的啟動時間;
2、app崩潰的日誌資訊;
3、app殺死程序;
友盟統計
整合步驟
1、在libs目錄加入下面sdk包:umeng-analytics-v6.0.1.jar
utdid4all-1.0.4.jar
2、在AndroidManifest.xml中補充許可權定義,以及meta-data引數定義,包括UMENG_APPKEY、UMENG_CHANNEL等等,其中UMENG_APPKEY需要到友盟網站上註冊申請;
3、程式碼裡先設定採集引數,然後開始採集行為事件;
MobclickAgent
setDebugMode : 設定是否開啟除錯模式。true為開啟除錯,false為關閉除錯。
setSessionContinueMillis : 設定session的持續時間,單位毫秒。
startWithConfigure : 設定友盟的統計分析配置。該方法的引數是UMAnalyticsConfig物件,包含了appkey、渠道號、是否啟用崩潰採集等等資訊。
openActivityDurationTrack : 設定是否開啟預設的Activity頁面統計方式。true為開啟,false為關閉。
setAutoLocation : 設定是否自動定位。
注意,友盟sdk的傳送策略不在程式碼中設定,要在友盟的後臺管理頁面中設定。具體步驟為:點選應用名稱->設定->傳送策略,目前有兩種:啟動時傳送(預設)、按間隔傳送。
友盟sdk的老版本還提供了實時傳送與僅在wifi下發送兩種策略,但在新版本中取消了,原因如下:
1、實時傳送會存在大量冗餘欄位的重複傳送的現象,造成終端使用者不必要的流量消耗;
2、僅在wifi下發送,資料的延遲會非常嚴重,造成資料統計結果的失真;
下面是MobclickAgent類與事件有關的方法說明:
onPageStart : 頁面啟動事件。
onPageEnd : 頁面結束事件。
onResume : 恢復統計。
onPause : 暫停統計。
onEvent : 普通事件,一般是點選事件。
onEventValue : 複雜事件,比如說音樂播放事件。
onSocialEvent : 社會化分享事件。
onProfileSignIn : 登入事件。
onProfileSignOff : 登出事件。
onKillProcess : 殺死程序事件。
下面是友盟統計分析的程式碼例子:
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import com.example.exmanalysis.umeng.analytics.FragmentStack; import com.example.exmanalysis.umeng.analytics.FragmentTabs; import com.example.exmanalysis.umeng.analytics.WebviewAnalytic; import com.umeng.analytics.MobclickAgent; import com.umeng.analytics.MobclickAgent.EScenarioType; import com.umeng.analytics.social.UMPlatformData; import com.umeng.analytics.social.UMPlatformData.GENDER; import com.umeng.analytics.social.UMPlatformData.UMedia; public class UmengActivity extends Activity { private final static String TAG = "UmengActivity"; private Context mContext; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_umeng); mContext = this; MobclickAgent.setDebugMode(true); // SDK在統計Fragment時,需要關閉Activity自帶的頁面統計, // 然後在每個頁面中重新整合頁面統計的程式碼(包括呼叫了 onResume 和 onPause 的Activity)。 MobclickAgent.openActivityDurationTrack(false); // MobclickAgent.setAutoLocation(true); // MobclickAgent.setSessionContinueMillis(1000); // MobclickAgent.startWithConfigure( // new UMAnalyticsConfig(mContext, "4f83c5d852701564c0000011", "Umeng", EScenarioType.E_UM_NORMAL)); MobclickAgent.setScenarioType(mContext, EScenarioType.E_UM_NORMAL); } @Override public void onResume() { super.onResume(); MobclickAgent.onPageStart(TAG); MobclickAgent.onResume(mContext); } @Override public void onPause() { super.onPause(); MobclickAgent.onPageEnd(TAG); MobclickAgent.onPause(mContext); } public void onButtonClick(View view) { int id = view.getId(); switch (id) { case R.id.umeng_example_analytics_event_cc: List<String> keyPath = new ArrayList<String>(); keyPath.add("one"); keyPath.add("two"); keyPath.add("tree"); MobclickAgent.onEvent(mContext, keyPath, 20, "label"); break; case R.id.umeng_example_analytics_event: MobclickAgent.onEvent(mContext, "click"); MobclickAgent.onEvent(mContext, "click", "button"); break; case R.id.umeng_example_analytics_ekv: Map<String, String> map_ekv = new HashMap<String, String>(); map_ekv.put("type", "popular"); map_ekv.put("artist", "JJLin"); MobclickAgent.onEvent(mContext, "music", map_ekv); break; case R.id.umeng_example_analytics_duration: Map<String, String> map_value = new HashMap<String, String>(); map_value.put("type", "popular"); map_value.put("artist", "JJLin"); MobclickAgent.onEventValue(this, "music", map_value, 12000); break; case R.id.umeng_example_analytics_make_crash: "123".substring(10); break; case R.id.umeng_example_analytics_js_analytic: startActivity(new Intent(this, WebviewAnalytic.class)); break; case R.id.umeng_example_analytics_fragment_stack: startActivity(new Intent(this, FragmentStack.class)); break; case R.id.umeng_example_analytics_fragment_tabs: startActivity(new Intent(this, FragmentTabs.class)); break; case R.id.umeng_example_analytics_social: UMPlatformData platform = new UMPlatformData(UMedia.SINA_WEIBO, "user_id"); platform.setGender(GENDER.MALE); // optional platform.setWeiboId("weiboId"); // optional MobclickAgent.onSocialEvent(this, platform); break; case R.id.umeng_example_analytics_signin: MobclickAgent.onProfileSignIn("example_id"); break; case R.id.umeng_example_analytics_signoff: MobclickAgent.onProfileSignOff(); break; } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Hook(); return true; } return super.onKeyDown(keyCode, event); } // /對於好多應用,會在程式中殺死 程序,這樣會導致我們統計不到此時Activity結束的資訊, // /對於這種情況需要呼叫 'MobclickAgent.onKillProcess( Context )' // /方法,儲存一些頁面呼叫的資料。正常的應用是不需要呼叫此方法的。 private void Hook() { AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setPositiveButton("退出應用", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { MobclickAgent.onKillProcess(mContext); int pid = android.os.Process.myPid(); android.os.Process.killProcess(pid); } }); builder.setNeutralButton("後退一下", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { finish(); } }); builder.setNegativeButton("點錯了", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); builder.show(); } }
百度統計
整合步驟
1、在libs目錄加入下面sdk包:libcrash_analysis.so
user_profile_mtj_1.5.jar
2、在AndroidManifest.xml中補充許可權定義,以及meta-data引數定義,包括BaiduMobAd_STAT_ID、BaiduMobAd_CHANNEL等等,其中BaiduMobAd_STAT_ID需要到百度網站上註冊申請;
3、程式碼裡先設定採集引數,然後開始採集行為事件;
StatService
百度統計分析主要用到StatService類。下面是與設定有關的方法說明:setDebugOn : 設定是否開啟除錯模式。true為開啟除錯,false為關閉除錯。
setSessionTimeOut : 設定session的超時時間,單位秒。
setAppKey : 設定appkey。建議在AndroidManifest.xml中填寫。
setAppChannel : 設定應用的渠道。
setOn : 開啟崩潰錯誤收集。預設是關閉的
setLogSenderDelayed : 設定啟動時日誌傳送的延時,單位秒。
setSendLogStrategy : 設定日誌傳送的策略。SendStrategyEnum.APP_START表示應用啟動時傳送,SendStrategyEnum.ONCE_A_DAY表示每天傳送一次,SendStrategyEnum.SET_TIME_INTERVAL表示固定時間間隔傳送。
下面是與事件有關的方法說明:
onPageStart : 頁面啟動事件。
onPageEnd : 頁面結束事件。
onResume : 恢復統計。
onPause : 暫停統計。
onEvent : 普通事件,一般是點選事件
onEventDuration : 持續一段時間的事件。
onEventStart : 事件開始。
onEventEnd : 事件結束。
下面是百度統計分析的程式碼例子:
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.baidu.mobstat.NativeCrashHandler;
import com.baidu.mobstat.SendStrategyEnum;
import com.baidu.mobstat.StatService;
import com.example.exmanalysis.baidu.AnotherDemoActivity1;
import com.example.exmanalysis.baidu.Conf;
import com.example.exmanalysis.baidu.DemoActivity2;
import com.example.exmanalysis.baidu.DemoActivity3;
import com.example.exmanalysis.baidu.WebViewActivity;
import com.example.exmanalysis.baidu.appfragment.AppFragmentDemoActivity;
import com.example.exmanalysis.baidu.supportv4fragment.MainFragmentActivity;
public class BaiduActivity extends Activity {
private Button btnPrev;
private Button btnNext;
private Button btnWebview;
private Button btnException;
private Button btnNativeException;
private Button btnSetTV;
private Button btnEvent;
private Button btnEventDuration;
private Button btnEventStart;
private Button btnEventEnd;
private Button btnFragmentPage;
private Button btnAppFragmentPage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.baidu_activity);
boolean isWear = getPackageManager().hasSystemFeature("android.hardware.type.watch");
Log.e("TEST", "isWear: " + isWear);
Log.e("TEAT", "manufacturer: " + Build.MANUFACTURER);
// 設定AppKey
// StatService.setAppKey("a9e2ad84a2"); // appkey必須在mtj網站上註冊生成,該設定建議在AndroidManifest.xml中填寫,程式碼設定容易丟失
/*
* 設定渠道的推薦方法。該方法同setAppChannel(String), 如果第三個引數設定為true(防止渠道程式碼設定會丟失的情況),將會儲存該渠道,每次設定都會更新儲存的渠道,
* 如果之前的版本使用了該函式設定渠道,而後來的版本需要AndroidManifest.xml設定渠道,那麼需要將第二個引數設定為空字串,並且第三個引數設定為false即可。
* appChannel是應用的釋出渠道,不需要在mtj網站上註冊,直接填寫就可以 該引數也可以設定在AndroidManifest.xml中
*/
// StatService.setAppChannel(this, "RepleceWithYourChannel", true);
// 測試時,可以使用1秒鐘session過期,這樣不斷的間隔1S啟動退出會產生大量日誌。
StatService.setSessionTimeOut(30);
// setOn也可以在AndroidManifest.xml檔案中填寫,BaiduMobAd_EXCEPTION_LOG,開啟崩潰錯誤收集,預設是關閉的
StatService.setOn(this, StatService.EXCEPTION_LOG);
/*
* 設定啟動時日誌傳送延時的秒數<br/> 單位為秒,大小為0s到30s之間<br/> 注:請在StatService.setSendLogStrategy之前呼叫,否則設定不起作用
*
* 如果設定的是傳送策略是啟動時傳送,那麼這個引數就會在傳送前檢查您設定的這個引數,表示延遲多少S傳送。<br/> 這個引數的設定暫時只支援程式碼加入,
* 在您的首個啟動的Activity中的onCreate函式中使用就可以。<br/>
*/
StatService.setLogSenderDelayed(0);
/*
* 用於設定日誌傳送策略<br /> 嵌入位置:Activity的onCreate()函式中 <br />
*
* 呼叫方式:StatService.setSendLogStrategy(this,SendStrategyEnum. SET_TIME_INTERVAL, 1, false); 第二個引數可選:
* SendStrategyEnum.APP_START SendStrategyEnum.ONCE_A_DAY SendStrategyEnum.SET_TIME_INTERVAL 第三個引數:
* 這個引數在第二個引數選擇SendStrategyEnum.SET_TIME_INTERVAL時生效、 取值。為1-24之間的整數,即1<=rtime_interval<=24,以小時為單位 第四個引數:
* 表示是否僅支援wifi下日誌傳送,若為true,表示僅在wifi環境下發送日誌;若為false,表示可以在任何聯網環境下發送日誌
*/
StatService.setSendLogStrategy(this, SendStrategyEnum.SET_TIME_INTERVAL, 1, false);
// 除錯百度統計SDK的Log開關,可以在Eclipse中看到sdk列印的日誌,釋出時去除呼叫,或者設定為false
StatService.setDebugOn(true);
String sdkVersion = StatService.getSdkVersion();
TextView sdkVersionTxtv = (TextView) findViewById(R.id.tv_sdk_version);
if (sdkVersion != null) {
sdkVersionTxtv.setText("sdk version is: " + sdkVersion);
}
btnPrev = (Button) findViewById(R.id.layout1_btn1);
btnNext = (Button) findViewById(R.id.layout1_btn2);
btnWebview = (Button) findViewById(R.id.layout1_btn_web_view);
btnException = (Button) findViewById(R.id.layout1_btn_excep);
btnNativeException = (Button) findViewById(R.id.layout1_btn_native_excep);
btnNativeException.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
NativeCrashHandler.doNativeCrash();
}
});
btnSetTV = (Button) findViewById(R.id.layout1_btn_set_TV);
btnSetTV.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
StatService.setForTv(BaiduActivity.this, true);
}
});
btnEvent = (Button) findViewById(R.id.layout1_btn_event);
btnEventDuration = (Button) findViewById(R.id.layout1_btn_event_duration);
btnEventStart = (Button) findViewById(R.id.layout1_btn_event_start);
btnEventEnd = (Button) findViewById(R.id.layout1_btn_event_end);
btnFragmentPage = (Button) findViewById(R.id.layout1_fragment);
btnAppFragmentPage = (Button) findViewById(R.id.layout1_app_fragment);
findViewById(R.id.btn_another_process).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(BaiduActivity.this, AnotherDemoActivity1.class);
startActivity(intent);
}
});
btnPrev.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(BaiduActivity.this, DemoActivity3.class);
BaiduActivity.this.startActivity(intent);
}
});
btnNext.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(BaiduActivity.this, DemoActivity2.class);
BaiduActivity.this.startActivity(intent);
}
});
btnWebview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(BaiduActivity.this, WebViewActivity.class);
BaiduActivity.this.startActivity(intent);
}
});
btnException.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Thread t = new Thread() {
@Override
public void run() {
if (!MyApplication.SHIELD_EXCEPTION) {
Log.w(Conf.TAG, 10 / 0 + "");
}
}
};
t.start();
}
});
btnEvent.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
StatService.onEvent(BaiduActivity.this.getApplicationContext(), "registered id", "pass", 1);
}
});
/**
* 自定義事件的第一種方法,寫入某個事件的持續時長
*/
btnEventDuration.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// 事件id("registered id")的事件pass,其時長持續100毫秒
StatService.onEventDuration(BaiduActivity.this, "registered id", "pass", 100);
}
});
/*
* 自定義事件的第二種方法,自己定義該事件的起始時間和結束時間
*/
btnEventStart.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// 事件id("registered id")的事件pass,其時長持續10毫秒
StatService.onEventStart(BaiduActivity.this, "registered id", "pass"); // 必須和onEventEnd共用才行
}
});
/*
* 自定義事件的第二種方法,自己定義該事件的起始時間和結束時間
*/
btnEventEnd.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// 事件id("registered id")的事件pass,其時長持續10毫秒
StatService.onEventEnd(BaiduActivity.this, "registered id", "pass"); // 必須和onEventStart共用才行
}
});
btnFragmentPage.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent in = new Intent();
in.setClass(BaiduActivity.this, MainFragmentActivity.class);
startActivity(in);
}
});
btnAppFragmentPage.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Intent in = new Intent();
in.setClass(BaiduActivity.this, AppFragmentDemoActivity.class);
startActivity(in);
}
}
});
}
public void onResume() {
super.onResume();
//頁面起始(每個Activity中都需要新增,如果有繼承的父Activity中已經添加了該呼叫,那麼子Activity中務必不能新增)
//不能與StatService.onPageStart一級onPageEnd函式交叉使用
StatService.onResume(this);
}
public void onPause() {
super.onPause();
//頁面結束(每個Activity中都需要新增,如果有繼承的父Activity中已經添加了該呼叫,那麼子Activity中務必不能新增)
//不能與StatService.onPageStart一級onPageEnd函式交叉使用
StatService.onPause(this);
}
}
騰訊統計
整合步驟
1、在libs目錄加入下面sdk包:libMtaNativeCrash.so
mid-sdk-2.3.jar
mta-android-stat-sdk-2.2.0_20160504.jar
2、在AndroidManifest.xml中補充許可權定義,以及meta-data引數定義,包括TA_APPKEY、InstallChannel等等,其中TA_APPKEY需要到騰訊網站上註冊申請;
3、程式碼裡先設定採集引數,然後開始採集行為事件;
StatConfig
騰訊統計分析的引數設定用的是StatConfig類,主要方法說明如下:setDebugEnable : 設定是否開啟除錯模式。true為開啟除錯,false為關閉除錯。
setSessionTimoutMillis : 設定session的超時時間,單位秒。
setAppKey : 設定appkey。建議在AndroidManifest.xml中填寫。
setInstallChannel : 設定安裝的渠道。
setAutoExceptionCaught : 設定是否自動採集崩潰資訊(即app未處理的異常)。true表示自動採集,false表示不採集。
setStatSendStrategy : 設定日誌傳送的策略。StatReportStrategy.PERIOD表示按時間間隔傳送,StatReportStrategy.INSTANT實時傳送即每個行為都立即傳送,StatReportStrategy.ONLY_WIFI表示只在wifi網路下發送,StatReportStrategy.BATCH表示批量傳送即達到快取臨界值時觸發,StatReportStrategy.APP_LAUNCH表示應用啟動時傳送。
setEnableSmartReporting : 設定是否允許在WIFI網路下實時上報。
setSendPeriodMinutes : 設定日誌傳送的時間間隔。單位分鐘,該方法在StatReportStrategy.PERIOD時啟用。
setMaxStoreEventCount : 設定快取中的事件最大數目。該方法在StatReportStrategy.BATCH時啟用。
StatService
騰訊統計分析的事件跟蹤用的是StatService類,主要方法說明如下:startStatService : 開始統計服務。如果整合統計服務的是普通app,則無需呼叫該方法;如果提供出來的是第三方sdk,由於jar包不包含AndroidManifest.xml,因此必須在程式碼中呼叫該方法,才能啟用統計服務。
onResume : 恢復統計。
onPause : 暫停統計。
addActionListener : 監聽前後臺狀態。該方法的引數為StatActionListener物件,物件內部需實現兩個方法,分別是前臺執行onBecameForeground、後臺執行onBecameBackground。
trackCustomEvent : 跟蹤自定義事件。
trackCustomBeginEvent : 跟蹤自定義事件開始。
trackCustomEndEvent : 跟蹤自定義事件結束。
trackCustomKVEvent : 跟蹤自定義的key-value事件。
trackCustomBeginKVEvent : 跟蹤自定義的key-value事件開始。
trackCustomEndKVEvent : 跟蹤自定義的key-value事件結束。
reportError : 上報錯誤資訊。
reportException : 上報異常資訊。
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.os.MemoryFile;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.tencent.stat.StatAppMonitor;
import com.tencent.stat.StatConfig;
import com.tencent.stat.StatNativeCrashReport;
import com.tencent.stat.StatService;
import com.tencent.stat.StatServiceImpl;
public class TencentActivity extends Activity {
private final static String TAG = "TencentActivity";
private Context ctx = null;
private Button btn_customevent_args_count = null;
private Button btn_customevent_kv_count = null;
private Button btn_customevent_args_duration_begin = null;
private Button btn_customevent_args_duration_end = null;
private Button btn_customevent_kv_duration_begin = null;
private Button btn_customevent_kv_duration_end = null;
private Button btn_report_error = null;
private Button btn_report_exception = null;
private Button btn_catch_unhandled_exception = null;
private Button btn_init_nativeCrash = null;
private Button btn_catch_native_crash = null;
private Button btn_monitor_events = null;
public void onActivityOpen() { // 你的函式
Properties prop = new Properties();
prop.setProperty("aty", "搶票活動"); // 活動頁面
prop.setProperty("gid", "潛在付費使用者"); // 使用者組名稱
prop.setProperty("attr", "1"); // 使用者屬性(年齡、性別等)
prop.setProperty("act_type", "1"); // 行為型別(最近30天啟動過、最近30天使用時長超過、最近30天是否有過升級行為等)
prop.setProperty("act_val", "10"); // 行為取值
StatService.trackCustomKVEvent(this, "mta_tag_activity_open", prop);
}
public void onActivityClick2() { // 你的函式
Properties prop = new Properties();
prop.setProperty("aty", "搶票活動"); // 活動頁面
prop.setProperty("btn", "報名"); // 按鈕
prop.setProperty("gid", "潛在付費使用者"); // 使用者組名稱
prop.setProperty("attr ", "1"); // 使用者屬性(年齡、性別等)
prop.setProperty("act_type ", "1"); // 行為型別(最近30天啟動過、最近30天使用時長超過、最近30天是否有過升級行為等)
prop.setProperty("act_val ", "10"); // 行為取值
StatService.trackCustomKVEvent(this, "mta_tag_activity_click", prop);
}
public void onUserPay() { // 你的函式
Properties prop = new Properties();
prop.setProperty("scene", "通關"); // 付費場景
prop.setProperty("amount", "350"); // 付費金額
prop.setProperty("way", "手機支付"); // 付費方式(可選擇上報)
StatService.trackCustomKVEvent(null, "mta_tag_user_pay", prop);
}
MemoryFile memoryFile = null;
private View.OnClickListener l = new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "ctx==" + ctx);
int id = v.getId();
switch (id) {
case R.id.btn_customevent_args_count:
StatService.trackCustomEvent(ctx, "trackCustomEvent", "args");
StatService.trackCustomEvent(ctx, "id1", "args");
StatService.trackCustomEvent(ctx, "id2", "");
StatService.trackCustomEvent(ctx, "trackCustomEvent", null);
StatServiceImpl.trackBackground(getApplicationContext(), 10, null);
break;
case R.id.btn_customevent_kv_count:
Properties prop = new Properties();
prop.setProperty("key", "value");
prop.setProperty("key2", "value2");
StatService.trackCustomKVEvent(ctx, "trackCustomKVEvent", prop);
prop = new Properties();
prop.setProperty("a", "b");
StatService.trackCustomKVEvent(ctx, "4", prop);
StatService.trackCustomKVEvent(ctx, "trackCustomKVEvent", prop);
prop = new Properties();
prop.setProperty("num", "3434");
StatService.trackCustomKVEvent(ctx, "trackCustomKVEvent", prop);
break;
case R.id.btn_customevent_args_duration_begin:
StatService.trackCustomBeginEvent(ctx, "trackCustomEvent", "loadConfigFile");
break;
case R.id.btn_customevent_args_duration_end:
StatService.trackCustomEndEvent(ctx, "trackCustomEvent", "loadConfigFile");
break;
case R.id.btn_customevent_kv_duration_begin:
Properties properties = new Properties();
properties.setProperty("load", "config");
StatService.trackCustomBeginKVEvent(ctx, "trackCustomEvent", properties);
break;
case R.id.btn_customevent_kv_duration_end:
properties = new Properties();
properties.setProperty("load", "config");
StatService.trackCustomEndKVEvent(ctx, "trackCustomEvent", properties);
break;
case R.id.btn_report_error:
StatService.reportError(ctx, "I hate error.");
StatService.commitEvents(getApplicationContext(), -1);
break;
case R.id.btn_report_exception:
try {
String myNull = null;
int length = myNull.length();
} catch (NullPointerException ex) {
StatService.reportException(ctx, ex);
}
break;
case R.id.btn_monitor_events:
// 新建監控介面物件
StatAppMonitor monitor = new StatAppMonitor("ping:www.qq.com");
// 介面開始執行
String ip = "www.qq.com";
Runtime run = Runtime.getRuntime();
java.lang.Process proc = null;
try {
String str = "ping -c 3 -i 0.2 -W 1 " + ip;
long starttime = System.currentTimeMillis();
proc = run.exec(str);
int retCode = proc.waitFor();
long difftime = System.currentTimeMillis() - starttime;
// 設定介面耗時
monitor.setMillisecondsConsume(difftime);
// 設定介面返回碼
monitor.setReturnCode(retCode);
// 設定請求包大小,若有的話
monitor.setReqSize(1000);
// 設定響應包大小,若有的話
monitor.setRespSize(2000);
// 設定抽樣率,預設為1,表示100%。如果是50%,則填2(100/50),如果是25%,則填4(100/25),以此類推。
// monitor.setSampling(2);
if (retCode == 0) {
Log.d(TAG, "ping連線成功");
// 標記為成功
monitor.setResultType(StatAppMonitor.SUCCESS_RESULT_TYPE);
} else {
Log.d(TAG, "ping測試失敗");
// 標記為邏輯失敗,可能由網路未連線等原因引起的,但對於業務來說不是致命的,是可容忍的
monitor.setResultType(StatAppMonitor.LOGIC_FAILURE_RESULT_TYPE);
}
} catch (Exception e) {
Log.d(TAG, e.getMessage());
// 介面調用出現異常,致命的,標識為失敗
monitor.setResultType(StatAppMonitor.FAILURE_RESULT_TYPE);
} finally {
proc.destroy();
}
// 上報介面監控的資訊
StatService.reportAppMonitorStat(ctx, monitor);
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("www.qq.com", 80);
map.put("pingma.qq.com", 80);
StatService.testSpeed(ctx, map);
break;
case R.id.btn_catch_unhandled_exception:
int i = 1 / 0;
break;
case R.id.btn_init_nativeCrash:
String tombfilepath = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/my";
StatConfig.initNativeCrashReport(ctx, null);
break;
case R.id.btn_catch_native_crash:
StatNativeCrashReport.doNativeCrashTest();
break;
default:
break;
}
}
};
String getCurProcessName(Context context) {
int pid = android.os.Process.myPid();
ActivityManager mActivityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager
.getRunningAppProcesses()) {
if (appProcess.pid == pid) {
return appProcess.processName;
}
}
return null;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tencent);
ctx = this;
// 高階功能:線上配置更新
// String onOrOff = StatConfig.getCustomProperty("switch", "off");
// Log.d(TAG, "switch" + onOrOff);
// if(onOrOff.equalsIgnoreCase("on")){
// // 開啟某項功能
// }else{
// // 禁用某項功能
// }
// String appid = "互聯的appid";
// String appkey = "Aqc" + appid;
// StatConfig.setAutoExceptionCaught(false); // 禁止捕獲app未處理的異常
// StatConfig.setEnableSmartReporting(true); // 禁止WIFI網路實時上報
// StatConfig.setSendPeriodMinutes(24 * 60); // PERIOD間隔週期,24小時
// StatConfig.setStatSendStrategy(StatReportStrategy.PERIOD); //
// PERIOD上報策略
// try {
// StatService.startStatService(this, appkey,
// com.tencent.stat.common.StatConstants.VERSION);
// } catch (MtaSDkException e) {
// Log.e("DEBUG", "MTA init Failed.");
// }
initActivity();
}
private void initActivity() {
setTitle("常用統計分析");
btn_customevent_args_count = (Button) findViewById(R.id.btn_customevent_args_count);
btn_customevent_kv_count = (Button) findViewById(R.id.btn_customevent_kv_count);
btn_customevent_args_duration_begin = (Button) findViewById(R.id.btn_customevent_args_duration_begin);
btn_customevent_args_duration_end = (Button) findViewById(R.id.btn_customevent_args_duration_end);
btn_customevent_kv_duration_begin = (Button) findViewById(R.id.btn_customevent_kv_duration_begin);
btn_customevent_kv_duration_end = (Button) findViewById(R.id.btn_customevent_kv_duration_end);
btn_report_error = (Button) findViewById(R.id.btn_report_error);
btn_report_exception = (Button) findViewById(R.id.btn_report_exception);
btn_catch_unhandled_exception = (Button) findViewById(R.id.btn_catch_unhandled_exception);
btn_catch_native_crash = (Button) findViewById(R.id.btn_catch_native_crash);
btn_init_nativeCrash = (Button) findViewById(R.id.btn_init_nativeCrash);
btn_monitor_events = (Button) findViewById(R.id.btn_monitor_events);
btn_customevent_args_count.setOnClickListener(l);
btn_customevent_kv_count.setOnClickListener(l);
btn_customevent_args_duration_begin.setOnClickListener(l);
btn_customevent_args_duration_end.setOnClickListener(l);
btn_customevent_kv_duration_begin.setOnClickListener(l);
btn_customevent_kv_duration_end.setOnClickListener(l);
btn_report_error.setOnClickListener(l);
btn_report_exception.setOnClickListener(l);
btn_catch_unhandled_exception.setOnClickListener(l);
btn_init_nativeCrash.setOnClickListener(l);
btn_catch_native_crash.setOnClickListener(l);
btn_monitor_events.setOnClickListener(l);
}
@Override
protected void onResume() {
super.onResume();
StatService.onResume(this);
}
@Override
protected void onPause() {
super.onPause();
StatService.onPause(this);
}
}
相關推薦
android跳轉手機百度高德騰訊谷歌地圖、地圖傳座標、座標偏移、base64解碼相關
調起百度的native app http://developer.baidu.com/map/uri-introandroid.htm#idmykey47 座標轉換 http://api.map.baidu.com/ag/coord/convert?from=2&
Android中統計分析的SDK ,友盟統計,百度統計,騰訊統計
APP統計分析 使用者畫像 對程式設計師來說,使用者畫像就是使用者的屬性和行為;通俗地說,使用者畫像是包括了個人資訊、興趣愛好、日常行為等血肉豐滿的客戶實體。使用者畫像是精準營銷的產物,企業通過收集使用者的行為,然後分析出使用者的特徵與偏好,進而挖掘潛在的商業價值,實現企業
Android 使用第三方SDK—友盟實現分享功能
今天給大家寫一下友盟的分享,這段時間在專案有用到,這裡簡單給大家介紹一下。 首先,到微信,QQ,微博開放平臺新增應用,獲取key,下面列出連結: 到友盟官網註冊,新增應用獲取唯一的key, 下載友盟分享的SDK,需要引入到自己專案當中。我這隻用到了微信,QQ,微博,就只選了一部分功
android 中如何分析記憶體洩漏
前提條件: 1,電腦安裝了java 執行環境 2,手機端開啟了 USB 除錯開關 3,獲取 root 許可權 4,安裝MAT工具,下載地址:http://www.eclipse.org/mat/downloads.php 基本步驟: 1,使用eclipse 自帶的 D
iOS 微信支付SDK與微信友盟分享兩者同時整合時,出現的問題與解決之路。
這兩天改版一箇舊的APP,要舊貌換新顏,拿到app後進行編譯,一直報下面的錯誤。 報不認識的符號名PayReq錯誤。奇怪,啥也沒動就這樣,真不知道給的包是不是本來就是個報錯的工程。 不管怎樣,要對它修改就先要跑起來啊。 根據錯誤提示,判斷是libwec
Android studio打包的時候友盟出錯
在gradle.app裡面配置以下內容即可 lintOptions { disable 'MissingTranslation' checkReleaseBuilds false // Or, if you prefer, you can continue to c
Android中效能分析之TraceView
1 package com.sunzn.app.utils; 2 3 import java.io.File; 4 import java.io.IOException; 5 import java.io.InputStream; 6 import java.lang.ref.S
eCharts+百度地圖實習格網統計圖
格網統計圖是一種將統計資料彙總到格網當中顯示的統計圖表,它的使用範圍相當廣泛。可以使用一點的監測值代表一個網格區域的值。可以不用使用插值而得到整個面的統計值。 eCharts本身並不提供格網統計圖的實現,但eCharts提供的使用者自定義表可以幫助我們實現。 格網統計圖:
三、騰訊統計和bugly追蹤整合
加入騰訊基礎統計,我們就可以看到我們的應用的統計資料啦。 一、獲取SDK 去官網註冊一個應用,並且下載SDK。 二、整合SDK 整合方法也非常簡便,一步步按照文件來就行了。 1、加入jar包。 2、AndroidManifest.xml裡面新增引數和許可權。 3、在Base
Android中自定義ViewGroup使每行元件數量不確定,並拿到選中資料
1先看效果圖 2專案目錄 3在定義控制元件FlowTagGroup package android.zhh.com.myviewgroup; /** * Created by sky on 2017/3/10. */ import android.conten
Android中控制元件的事件——xml設定對應效果state_[pressed,checked,selected,focused]
本篇文章主要是討論下控制元件的點選事件 一、在Drawable中新增控制元件的backgroundColor樣式(點選切換顏色) 直接貼測試結果了:【在Drawable中建立xml資原始檔,在其中的Selector標籤對中新增樣式(如下黑色截圖)】 ImageButton
android中如何去掉pulltorefreshlistview點選item時的背景顏色,與item外邊距設定
如圖所示,做專案中通過運用pulltorefreshlistview下拉重新整理元件實現item與邊有一定距離的效果圖,如下圖所示,item內容我已清除。 通過 com.handmark.p
Android中獲取屏幕相關信息(屏幕大小,狀態欄、標題欄高度)的代碼
status tle efault android中 () 兩個 statusbar create eight 如下代碼內容是關於 Android中獲取屏幕相關信息(屏幕大小,狀態欄、標題欄高度)的代碼。 DisplayMetrics metrics = new Displ
Android 仿微信調用第三方應用導航(百度,高德、騰訊)
detail decorview fcm onclick api 描述 log def repr 實現目標 先來一張微信功能截圖看看要做什麽 其實就是有一個目的地,點擊目的地的時候彈出可選擇的應用進行導航。 大腦動一下,要實現這個功能應該大體分成兩步: 底部彈出可選的地
借助百度OCR,實現一鍵識別圖片中文字,就是這麽酷!
mage src 百度 文字 身份證 公眾 分享圖片 目前 增加 轉眼已是淩晨兩點,還好通過java根據百度提供的OCR接口,實現了一個有趣的小應用:一鍵識別圖片中文字 經過一個小時的反復測試,沒想到識別確實很高,而且,居然還可以識別稍微復雜的驗證碼 比如: 主要為了
在React 中使用百度地圖,高德地圖出現'AMap' is not defined 'BMap' is not defined
在React 中使用百度地圖,高德地圖出現'AMap' is not defined 'BMap' is not defined index.html <script type="text/javascript" src="http://api.map.baidu.co
scrapy-redis例項,分佈爬蟲爬取騰訊新聞,儲存在資料庫中
本篇文章為scrapy-redis的例項應用,原始碼已經上傳到github: https://github.com/Voccoo/NewSpider 使用到了: python 3.x redis scrapy-redis pymysql Redis-Desktop-Manage
在React 中使用百度地圖,高德地圖出現'AMap' is not defined 'BMap' is not defined
index.html <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=你的key"></script> <scrip
android面試90問,阿里,騰訊,百度小米公司
基礎問題相關 1、介面的意義-百度 2、抽象類的意義-百度 3、內部類的作用-樂視4、Java 虛擬機器的特性-百度-樂視5、哪些情況下的物件會被垃圾回收機制處理掉-美團-小米6、程序和執行緒的區別-獵豹-美團7、java中==和equals和hashCode的區別-樂視8、H
Android呼叫已安裝市場平臺(如Google Play商店,豌豆莢,百度手機助手,應用寶等)評論功能
效果圖: 程式碼: Uri uri = Uri.parse("market://details?id=" + getPackageName()); //傳遞包名,讓市場接收