開發人員可以使用 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 代碼管理工具,在網路介面中產生連結和 QR code,然後使用這些項目開啟應用程式,藉此預覽容器版本。您也可以啟用詳細記錄模式,以便偵錯任何非預期的行為。
預覽容器
在預覽容器之前,請先在 Google 代碼管理工具網頁介面中產生預覽網址,方法是選取要預覽的容器版本,然後選取「預覽」。請儲存這個預覽網址,以便在後續步驟中使用。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\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)."]]