若要在 Google 跟踪代码管理器中设置 Google Analytics 4 (GA4),您需要配置 Google 代码。借助 Google 代码,您可以让数据从您的网站流向 Google Analytics 以及任何其他指定的目标账号。请确保为每个网站创建唯一的 Google 代码。如需有关设置 Google Analytics 的更多说明,请参阅设置 Google Analytics。
Google 代码的运作方式
Google 代码的运作方式如下:在网页上加载您的 Google Analytics 媒体资源,并执行以下操作:
准备工作
本指南假定您已完成以下操作:
此外,本指南还假定您具备以下条件:
- 对网站的跟踪代码管理器容器拥有访问权限
- 拥有 Google Analytics 账号的“编辑者”(或更高级别)角色
设置 Google 代码
- 前往 https://tagmanager.google.com。
- 登录您的 Google 账号。了解如何创建 Google 账号。
- 在跟踪代码管理器中,点击账号标签页(左上角),然后选择您的容器。熟悉跟踪代码管理器的界面。
- 在“工作区”标签页中,前往代码,然后点击新建(右上角)。
- 在随即显示的面板中,按以下步骤操作:
- 将“未命名代码”替换为您的代码名称(例如“Google 代码”)。
- 在“代码配置”部分中:
- 在“选择代码类型”中,选择 Google 代码。
- 在“代码 ID”中,输入您的代码 ID。了解如何查找代码 ID。
- 可选:您可以设置其他配置选项,用于管理您的 Google 代码与其目标账号的通信方式。如果您已设置 Google 代码,并想保留该代码的所有默认设置,可以跳过可选设置。
- 在“触发条件”部分中,选择初始化 - 所有初始化事件或部分初始化事件。详细了解网页浏览触发器。
- 点击保存。
验证并发布
Verify
- Go to https://tagmanager.google.com.
- Sign in to your Google Account. Learn how to create a Google Account.
- Open the Tag Manager container you want to edit. Find your way around Tag Manager.
- In the Workspace tab, click Preview (top right) to launch Google Tag Assistant in a new tab.
- Enter your website URL and click Connect. Learn to debug with Tag Assistant.
Publish
- In the Workspace tab, click Submit (top right)
- In the Submission Configuration section, follow these steps:
- Select Publish and Create Version to publish the changes to your site. To save the changes without publishing them, select Create Version instead.
- Enter a name and description for the version.
- Select Activity History to review the changes you've made since the previous version.
- Click Publish (top right).