[英]Configure Firebase Analaytics + Google Tag Manager (GTM) per build variant
Before Firebase Analytics became available we use a multi flavour, multi build type Android Gradle project setup, and supply a different GTM container ID for each build variant, as follows: 在Firebase Analytics可用之前,我们使用多风格,多构建类型的Android Gradle项目设置,并为每个构建变体提供不同的GTM容器ID,如下所示:
TagManager.getInstance(context)
.loadContainerPreferNonDefault(BuildConfig.GTM_CONTAINER_ID, -1);
TagManager.getInstance(context).getDataLayer().pushEvent(eventName, eventData);
where Gradle would inject different GTM_CONTAINER_ID
per build variant. Gradle会
GTM_CONTAINER_ID
每个构建变体注入不同的GTM_CONTAINER_ID
。
How do we achieve the same with Firebase Analytics + GTM? 我们如何使用Firebase Analytics + GTM实现相同目标? According to docs , we need to download:
根据文档 ,我们需要下载:
and then just start firing events with this: 然后用这个开始触发事件:
FirebaseAnalytics.getInstance(context).logEvent(eventName, bundle);
Where do we specify the GTM container ID to be used? 我们在哪里指定要使用的GTM容器ID? Or is it auto derived by the file name we download from GTM dashboard and put under
assets/containers
? 或者它是从我们从GTM仪表板下载并放在
assets/containers
下的文件名自动派生的? If so, how do we use different GTM configuration per build variant as we do with GTM legacy Android container? 如果是这样,我们如何使用每个构建变体的不同GTM配置,就像我们使用GTM遗留Android容器一样?
This is how we set up our Gradle multi-flavor project to use different GTM container for each build variant: 这就是我们如何设置Gradle多风味项目以便为每个构建变体使用不同的GTM容器:
/
|_app/
|_src/
|_flavor1/
| |_google-services.json # Google services config for debug
| |_release/
| |_google-services.json # Google services config for flavor1
|_flavor1Release/
| |_assets/
| |_containers/
| |_GTM-ABCXY1.json # GTM container for flavor1
|
|_flavor2/
| |_google-services.json # Google services config for debug
| |_release/
| |_google-services.json # Google services config for flavor2
|_flavor2Release/
| |_assets/
| |_containers/
| |_GTM-ABCXY2.json # GTM container for flavor2
|
|_debug/
| |_assets/
| |_containers/
| |_GTM-ABCXY3.json # GTM container for debug
|
|_main/
|_res/
|_java/
Assuming you have 2 flavors flavor1
and flavor2
, and want to have 3 GTM containers, 1 shared for debug build of both flavors, and 1 each for release build of each flavor. 假设你有2种风味的
flavor1
和flavor2
,并且想拥有3个GTM容器,1个共享用于两种口味的调试构建,每个口味用于每种口味的发布构建。
GTM will connect to the FA dashboard of the project specified by your google-services.json
. GTM将连接到
google-services.json
指定的项目的FA仪表板。 Multi-flavor multi-build type google-services.json
support has been available since plugin version 2.1.0 [1] 自插件版本2.1.0 [1]以来,多种类型的多构建类型
google-services.json
支持已经可用
The container ID is derived from the container file name, as you surmised. 正如您所推测的那样,容器ID是从容器文件名派生的。 To use a per-build variant you can use gradle copy task to stage the correct container.
要使用每个构建变体,您可以使用gradle copy任务来分级正确的容器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.