我尝试为谷歌分析启动两个会话,但只跟踪trackerB。有没有办法跟踪两个不同配置文件的数据?
public GoogleAnalyticsTracker trackerA;
public GoogleAnalyticsTracker trackerB;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getApplication();
trackerA = GoogleAnalyticsTracker.getInstance();
trackerB = GoogleAnalyticsTracker.getInstance();
trackerA.startNewSession("UA-XXXXXX-Y", mContext);
trackerB.startNewSession("UA-XXXXXX-YY", mContext);
....
}
答案 0 :(得分:2)
您所谓的跟踪器是一个管理全局状态的单例。您可以通过以下方式获取实际跟踪器:
Context mCtx = this; // Get current context.
GoogleAnalytics myInstance = GoogleAnalytics.getInstance(mCtx.getApplicationContext());
Tracker myNewTracker = myInstance.getTracker("UA-XXXX-2");
参考:https://developers.google.com/analytics/devguides/collection/android/v2/advanced#managing-trackers