gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 08:51:04 25 4
gpt4 key购买 nike

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中,配置文件可以拆分,我可以使用资源合并来定义公共(public)值,比如src/main/res/values/analytics.xml中的tracking ID 并在 src/debug/res/values/analytics.xml 中包含调试属性,例如 ga_dryRun

但是 v4 SDK 现在从不支持资源合并 AFAICT 的 res/xml 读取配置。我想在一个地方定义跟踪 ID,无论是 Java 还是 XML,但也有针对不同构建变体的不同配置文件的灵 active 。

最佳答案

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

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

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

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com