Configure Firebase Analaytics + Google Tag Manager (GTM) per build variant

被刻印的时光 ゝ 提交于 2019-12-05 02:01:10

This is how we set up our Gradle multi-flavor project to use different GTM container for each build variant:

/
|_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.

GTM will connect to the FA dashboard of the project specified by your google-services.json. Multi-flavor multi-build type google-services.json support has been available since plugin version 2.1.0 [1]

The container ID is derived from the container file name, as you surmised. To use a per-build variant you can use gradle copy task to stage the correct container.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!