为 Google Analytics(分析)启动多个会话

发布于 2024-12-05 16:31:26 字数 547 浏览 1 评论 0原文

我尝试为 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); 

    ....

}

I tried to start two sessions for google analytics, however it is only tracked for trackerB. Is there any way to track data for two different profiles?

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); 

    ....

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风铃鹿 2024-12-12 16:31:26

您所说的跟踪器是管理全局状态的单例。您可以通过

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

What you are calling tracker is a singleton that manages the global state.you can get the actual tracker by:

Context mCtx = this; // Get current context.
GoogleAnalytics myInstance = GoogleAnalytics.getInstance(mCtx.getApplicationContext());
Tracker myNewTracker = myInstance.getTracker("UA-XXXX-2");

refer to this: https://developers.google.com/analytics/devguides/collection/android/v2/advanced#managing-trackers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文