android - 在 Google Analytics v4 for Android 中创建跟踪器后如何设置跟踪 ID?

标签 android google-analytics google-analytics-firebase

Google Analytics SDK v4 for Android ,文档说您可以创建一个跟踪器,而无需先使用跟踪 ID 对其进行初始化:

If the trackingId is empty, you can still get a tracker, but you must set the tracking id before sending any hits. This is useful if you do not know the tracking id at the time of tracker creation, or if you want to use the same tracker instance to track multiple tracking ids.

A Tracker must be initialized with a tracking id of an app profile before you can send any hits. You can change the id to send hits to a different profile.

创建跟踪器后,您调用什么方法来设置跟踪 ID?

动机

在v3版本的Android SDK中,配置文件可以被拆分,我可以使用资源合并来定义通用值,例如src/main/res/values/analytics.xml中的跟踪ID并包含调试属性,例如 ga_dryRunsrc/debug/res/values/analytics.xml .

但 v4 SDK 现在从 res/xml 读取配置不支持资源合并AFAICT。我想在一个地方(Java 或 XML)定义跟踪 ID,但也可以灵活地为不同的构建变体使用不同的配置文件。

最佳答案

目前,创建跟踪器后无法设置跟踪 ID。一种 HACKY 方法是使用 Tracker.set()方法,其中 key = "&tid" 且 value 作为跟踪 ID。

感谢您描述您的动机。我们会在未来的版本中牢记这一点。

注意:跟踪 ID 只能在创建期间设置的原因是跟踪器对象包含大量状态数据。强烈建议初始创建后不要更改跟踪 ID。

PS:在可预见的将来,将支持 hacky 方法,但如果您决定使用它,请在发布应用程序之前确认可以在实时报告中看到数据。

关于android - 在 Google Analytics v4 for Android 中创建跟踪器后如何设置跟踪 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23390963/

相关文章:

google-analytics - GA API-确认获取整日数据

google-analytics - 如何使用 Google Analytics SDK 返回总浏览量?

Java Reflection 通过 Android 通知上的内部类从 WhatsApp 获取消息

android - db.insert 仅在数据库中存储自动递增的 id

google-analytics - 如何从 Google 跟踪代码管理器为 AJAX 页面调用 _trackPageView?

google-analytics - 在 Google Analytics 中合并相似的 URL

java - 如何从不同的类中获取准确的对象?

Android:离线使用 developer.android.com?

google-analytics - 如何在 Google Analytics 中跟踪 "Open New Tab"流量