作为开发者,您可以使用 Google 跟踪代码管理器在移动应用中植入和管理各种衡量代码与像素,而无需重新生成应用二进制文件并将其重新提交到应用市场。使用 Google Analytics for Firebase SDK 的开发者可以轻松添加跟踪代码管理器来管理和更改相关植入,即使在应用发布之后亦是如此。
然后,您可以在 Google 跟踪代码管理器中配置新的 Firebase 用户属性变量,以捕获 favorite_food 值:
变量名称:Favorite Food
变量类型:Firebase 用户属性
事件参数键名称:favorite_food
修改和屏蔽事件
借助跟踪代码管理器,您可在 Google Analytics for Firebase SDK 记录事件前对其进行修改和屏蔽。通过修改事件,您无需更新应用,即可添加、移除或更改事件参数的值,或者调整事件名称。未被屏蔽的事件由 Google Analytics for Firebase SDK 进行记录。
Google Analytics for Firebase SDK 还会自动记录一些事件和用户属性。您可以在跟踪代码管理器中使用自动收集的事件和属性,而无需添加任何代码。不过,您无法屏蔽这些事件和属性。
3. 发送事件
您可以使用 Firebase 事件名称变量、Firebase 事件参数变量以及其他变量来设置触发器。无论您何时记录 Firebase 事件,都会对触发条件进行求值。默认情况下,Google Analytics for Firebase 事件会自动触发。您可以通过在跟踪代码管理器中添加 Google Analytics for Firebase 代码,阻止将事件发送到 Google Analytics(分析)。
4. 预览、调试和发布您的容器
在发布容器版本之前,您需要进行预览,以确保它可以按预期正常工作。通过 Google 跟踪代码管理器,您可以预览容器的各个版本,只需在网页界面中生成相应链接和二维码,然后使用它们打开您的应用即可。此外,您还可以启用详细日志记录模式,以调试任何意外行为。
预览容器
在预览容器之前,请在 Google 跟踪代码管理器网页界面中选择您要预览的容器版本,然后选择预览,从而生成预览网址。保存此预览网址,以在后续步骤中使用。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2023-10-31。"],[[["\u003cp\u003eGoogle Tag Manager enables managing and deploying marketing and analytics tags in mobile apps without code updates.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can log events within their app, allowing for flexible tag implementation and adjustments later in Tag Manager.\u003c/p\u003e\n"],["\u003cp\u003eBefore using Google Tag Manager, ensure prerequisites are met, including setting up Firebase and Google Analytics.\u003c/p\u003e\n"],["\u003cp\u003eTag Manager uses events logged by Firebase to trigger tags, offering options to modify or block these events.\u003c/p\u003e\n"],["\u003cp\u003ePreview and debug your Tag Manager container before publishing it to ensure it functions as expected.\u003c/p\u003e\n"]]],["Developers can integrate Google Tag Manager into mobile apps via the Firebase SDK to manage measurement tags and pixels without app updates. This involves adding the Tag Manager library, downloading a container, and creating variables in Tag Manager to capture event parameters and user properties. Events can be modified or blocked before logging. Triggers determine when tags fire. Before publishing, preview the container using a generated link, debug with verbose logging, and finally, publish for app users.\n"],null,["# Google Tag Manager for Android\n\nAs a developer, you can use Google Tag Manager to implement and manage\nmeasurement tags and pixels in your mobile applications, without having to\nrebuild and resubmit application binaries to app marketplaces. Developers who\nwork with the Google Analytics for Firebase SDK can easily add Tag Manager to\nhelp manage and make changes to the implementation, even after the app has\nshipped.\n\nDevelopers can log important events and decide later which tags or pixels should\nbe fired.\n\nPrerequisites\n-------------\n\nBefore getting started:\n\n- In the [Firebase console](https://console.firebase.google.com/), add your app to your Firebase project.\n- [Set up Google Analytics](https://firebase.google.com/docs/analytics/android/start/) for your app, including enabling Google Analytics in your Firebase project and adding the Google Analytics for Firebase SDK to your app.\n- [Create a Tag Manager account](https://tagmanager.google.com/).\n- [Configure a Google Tag Manager container](https://support.google.com/tagmanager/answer/6103696#CreatingAnAccount).\n\nThe following sections walk you through the steps to configure and use Google\nTag Manager in your Android application.\n\n1. Add Google Tag Manager to your project\n-----------------------------------------\n\n1. In your module Gradle file (usually `app/build.gradle`), add the following\n dependency on the Tag Manager library:\n\n dependencies {\n // ...\n compile 'com.google.android.gms:play-services-tagmanager:18.3.0'\n }\n\n2. Sign in to your [Tag Manager](https://tagmanager.google.com) account.\n\n3. Select a mobile container.\n\n4. Click **Versions** in the top navigation bar.\n\n5. Click the container version you wish to use.\n\n6. Click **Download**.\n\n7. Create the `app/src/main/assets/containers` folder if it doesn't exist. Copy\n the downloaded container to the folder.\n\n2. Log events and variables\n---------------------------\n\nTag Manager uses events, parameters, and user properties logged by the Google\nAnalytics for Firebase SDK to trigger and build tags you've configured in\nGoogle Tag Manager.\n\nRead the [Firebase developer documentation](https://firebase.google.com/docs/analytics/) for instructions on how to\n[log events](https://firebase.google.com/docs/analytics/android/events) and [set user properties](https://firebase.google.com/docs/analytics/android/properties).\n\n### Configure variables in Tag Manager\n\nTo capture the value of event parameters and user properties for use in Google\nTag Manager, you can [configure variables](https://support.google.com/tagmanager/answer/6106899) in the Tag Manager interface.\n\nFor example, you could log the following custom event in your app: \n\n Bundle params = new Bundle();\n params.putString(\"image_name\", name);\n params.putString(\"full_text\", text);\n mFirebaseAnalytics.logEvent(\"share_image\", params);\n\nThen, you could configure new Event Parameter variables in Tag Manager as\nfollows to capture the `image_name` and `full_text parameter` values:\n\n- **Variable Name**: Image Name\n- **Variable Type**: Event Parameter\n- **Event Parameter Key Name** : `image_name`\n\nand:\n\n- **Variable Name**: Full Text\n- **Variable Type**: Event Parameter\n- **Event Parameter Key Name** : `full_text`\n\nSimilarly, you could set the following user property in your app: \n\n mFirebaseAnalytics.setUserProperty(\"favorite_food\", mFavoriteFood);\n\nThen, you could configure a new Firebase User Property variable in Google Tag\nManager to capture the `favorite_food` value:\n\n- **Variable Name**: Favorite Food\n- **Variable Type**: Firebase User Property\n- **Event Parameter Key Name** : `favorite_food`\n\n### Modify and block events\n\nTag Manager enables you to modify and block events before they are logged by the\nGoogle Analytics for Firebase SDK. Modifying events can help you add, remove, or\nchange the values of event parameters or adjust event names without app updates.\nEvents that are not blocked will be logged by the Google Analytics for Firebase\nSDK.\n\nThe Google Analytics for Firebase SDK also automatically logs some [events](https://support.google.com/firebase/answer/6317485) and\n[user properties](https://support.google.com/firebase/answer/6317486). You can use automatically collected events and properties in\nTag Manager without needing to add any code. However, you can't block them.\n\n3. Send events\n--------------\n\nFirebase event name variables, Firebase event parameter variables, and other\nvariables are used to set up [triggers](https://support.google.com/tagmanager/answer/6106961). Trigger conditions are evaluated\nwhenever you log a Firebase event. By default, Google Analytics for Firebase\nevents automatically fire. It is possible to add a Google Analytics for Firebase\ntag in Tag Manager to block events from being sent to Google Analytics.\n\n4. Preview, debug, and publish your container\n---------------------------------------------\n\nBefore publishing a version of your container, you'll want to preview it to make\nsure it works as intended. Google Tag Manager gives you the ability to preview\nversions of your container by generating links and QR codes in the web interface\nand using them to open your application. You can also [enable a verbose logging\nmode](#debug-container) to debug any unexpected behavior.\n\n### Preview container\n\nBefore previewing a container, generate a preview URL in the Google Tag Manager\nweb interface by selecting the version of the container you'd like to preview,\nand then selecting **Preview**. Save this preview URL for later steps.\n**Figure 1:**Get a preview URL from the Tag Manager web interface.\n\nTo preview your container (if you use Android Studio, skip to step 3):\n\n1. Add this preview activity to your `AndroidManifest` file:\n\n \u003c!-- Add preview activity. --\u003e\n \u003cactivity\n android:name=\"com.google.android.gms.tagmanager.TagManagerPreviewActivity\"\n android:noHistory=\"true\"\u003e \u003c!-- optional, removes previewActivity from activity stack. --\u003e\n \u003cintent-filter\u003e\n \u003cdata android:scheme=\"tagmanager.c.com.example.app\" /\u003e\n \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n \u003ccategory android:name=\"android.intent.category.BROWSABLE\"/\u003e\n \u003c/intent-filter\u003e\n \u003c/activity\u003e\n\n2. Change this line to include your application's package name:\n\n \u003cdata android:scheme=\"tagmanager.c.com.example.app\"/\u003e\n\n3. In the Google Tag Manager web interface, generate a preview link:\n\n 1. Sign in to your [Tag Manager](https://tagmanager.google.com) account.\n 2. Select a mobile container.\n 3. Click **Versions** in the top navigation bar.\n 4. Click **Actions \\\u003e Preview** on the container version you'd like to preview.\n 5. Enter your application's package name.\n 6. Click **Generate begin preview link**.\n4. Stop your application and use the generated preview link or QR Code to\n launch your application.\n\n5. You can exit the preview mode by clicking a link generated by the\n **Generate end preview link** option in the web interface.\n\n### Debug container\n\nTo troubleshoot your container implementation, enable verbose logging: \n\n $ adb shell setprop log.tag.GoogleTagManager VERBOSE\n\n### Publish container\n\nAfter you preview your container and verify that it is working, you can\n[publish it](https://support.google.com/tagmanager/answer/6107163). After you have published your container, your tag configurations\nwill become available to mobile app users.\n| **Note:** For mobile containers, a default container is used to set initial tag configurations until the first time a container is downloaded. Once the app has connected to the internet and downloaded a container, it will never use the default container again. Applications periodically check for container updates, typically every 12 hours.\n\nNext steps\n----------\n\nRead [Advanced configuration](/tag-platform/tag-manager/android/v5/advanced-config)."]]