我尝试为Google Analytics(分析)启动两个会话,但是仅跟踪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);
....
}
最佳答案
您所说的跟踪器是一个管理全局状态的单例。您可以通过以下方式获取实际的跟踪器:
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