关于 google-consent-mode-v2
介绍 Google Consent Mode v2 的配置方法,面向使用 Google 标签并依据用户同意状态调整数据处理的广告主和实施人员。内容涵盖参数映射、GTM 设置、地区规则及验证调试。
主要功能
- 01配置同意状态默认值和更新
- 02映射 CMP 同意类别
- 03设置 GTM 同意触发器
- 04按地区应用默认规则
- 05检查标签和网络请求
- 06说明转化与行为建模条件
适用场景
- 01为 EEA 用户部署 Consent Mode v2
- 02将 CMP 选择映射到 Google 标签
- 03排查同意状态与标签行为
- 04核对 GA4 和 Ads 测量设置
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ mukul975/ privacy-data-protection-skills --skill google-consent-mode-v2安装后在 Claude Code 中输入/google-consent-mode-v2确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
assets/consent_mode_gtag.htmlconsent_mode_gtm.htmlconsent_parameters.mdtemplate.mdreferences/standards.mdworkflows.mdscripts/process.py详细介绍
配置 Google Consent Mode v2
概述
Google Consent Mode v2 是一个框架,可根据用户的同意状态调整 Google 标签(Analytics、Ads、Floodlight)的行为。Consent Mode v2 于 2023 年 11 月宣布,并于 2024 年 3 月开始强制实施。它在现有的 analytics_storage 和 ad_storage 参数之外,引入了两个新参数:ad_user_data 和 ad_personalization。对于向欧洲经济区(EEA)用户提供服务的广告主,必须实施 Consent Mode v2,才能在 Google Ads 和 GA4 中保留衡量和受众功能。否则,Google 将不会处理 EEA 用户数据以用于再营销列表或转化衡量。
Consent Mode v2 参数
参数定义
| 参数 | 控制内容 | 默认值 | 描述 |
|---|---|---|---|
ad_storage | 广告 Cookie | denied | 控制是否可以读取或写入广告相关 Cookie(gcl*、IDE) |
ad_user_data | 用于广告的用户数据 | denied | 控制是否可以向 Google 发送用于广告目的的用户数据 |
ad_personalization | 广告个性化 | denied | 控制数据是否可用于再营销和个性化广告 |
analytics_storage | 分析 Cookie | denied | 控制是否可以读取或写入分析 Cookie(_ga、_gid) |
functionality_storage | 功能 Cookie | granted | 控制功能 Cookie(语言偏好设置) |
personalization_storage | 个性化 Cookie | denied | 控制个性化 Cookie(推荐内容) |
security_storage | 安全 Cookie | granted | 控制与安全相关的 Cookie(身份验证、防欺诈) |
Pinnacle E-Commerce Ltd 的同意状态映射
将 CMP 同意类别映射到 Consent Mode 参数:
| CMP 类别 | ad_storage | ad_user_data | ad_personalization | analytics_storage |
|---|---|---|---|---|
| 全部拒绝(默认) | denied | denied | denied | denied |
| 仅分析 | denied | denied | denied | granted |
| 分析 + 广告 | granted | granted | granted | granted |
| 分析 + 广告(无个性化) | granted | granted | denied | granted |
| 全部接受 | granted | granted | granted | granted |
实施
基本实施(Google Tag / gtag.js)
步骤 1:在加载任何 Google 标签之前设置默认值
将此脚本放在 <head> 中,位于 Google 标签之前:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Set default consent state — deny all non-essential before user interaction
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied',
'functionality_storage': 'granted',
'personalization_storage': 'denied',
'security_storage': 'granted',
'wait_for_update': 500 // Wait 500ms for CMP to load
});
// Enable URL passthrough for conversion measurement without cookies
gtag('set', 'url_passthrough', true);
// Enable ads data redaction when ad_storage is denied
gtag('set', 'ads_data_redaction', true);
</script>
步骤 2:加载 Google 标签
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PINNACLE123"></script>
<script>
gtag('js', new Date());
gtag('config', 'G-PINNACLE123');
</script>
步骤 3:用户与 CMP 交互时更新同意状态
// Called by the CMP when user makes a consent choice
function updateGoogleConsent(consentState) {
gtag('consent', 'update', {
'ad_storage': consentState.advertising ? 'granted' : 'denied',
'ad_user_data': consentState.advertising ? 'granted' : 'denied',
'ad_personalization': consentState.personalization ? 'granted' : 'denied',
'analytics_storage': consentState.analytics ? 'granted' : 'denied'
});
}
Google Tag Manager 实施
步骤 1:配置 Consent Initialization 触发器
在 GTM 中,为默认同意标签使用“Consent Initialization — All Pages”触发器类型。该触发器会在所有其他触发器之前触发。
默认同意标签(Consent Initialization 触发器):
| 设置 | 值 |
|---|---|
| 标签类型 | Google tag:Consent configuration |
| 操作 | Default |
| ad_storage | Denied |
| ad_user_data | Denied |
| ad_personalization | Denied |
| analytics_storage | Denied |
| 等待更新 | 500 ms |
| URL 透传 | 已启用 |
| 广告数据屏蔽 | 已启用 |
步骤 2:配置同意更新标签
创建自定义 HTML 标签,或使用在同意状态变更时触发的 CMP 专用模板:
更新同意标签(自定义事件触发器:consent_update):
| 设置 | 值 |
|---|---|
| 标签类型 | Google tag:Consent configuration |
| 操作 | Update |
| ad_storage | {{CMP - Ad Storage Consent}} |
| ad_user_data | {{CMP - Ad User Data Consent}} |
| ad_personalization | {{CMP - Ad Personalization Consent}} |
| analytics_storage | {{CMP - Analytics Storage Consent}} |
步骤 3:配置标签同意设置
为 GTM 中的每个 Google 标签配置内置的同意检查:
| 标签 | 必需的同意 | 额外同意 |
|---|---|---|
| GA4 配置 | analytics_storage | — |
| GA4 事件 | analytics_storage | — |
| Google Ads 转化 | ad_storage | ad_user_data |
| Google Ads 再营销 | ad_storage | ad_user_data,ad_personalization |
| Floodlight 计数器 | ad_storage | ad_user_data |
| Floodlight 销售 | ad_storage | ad_user_data |
区域特定设置
根据用户所在地区应用不同的默认设置:
// Strict defaults for EEA users
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied',
'region': ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR',
'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL',
'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'IS', 'LI', 'NO']
});
// Less restrictive defaults for US users (adjust per state law)
gtag('consent', 'default', {
'ad_storage': 'granted',
'ad_user_data': 'granted',
'ad_personalization': 'granted',
'analytics_storage': 'granted',
'region': ['US']
});
转化建模和无 Cookie Ping
同意模式如何保留衡量数据
当用户拒绝同意时,Google 标签仍会发送无 Cookie ping,其中包含:
- 页面 URL(已应用 ads_data_redaction)
- 时间戳
- 用户代理
- 来源页(当 ads_data_redaction 为 false 时)
- 汇总后的同意状态
Google 会将这些 ping 与已同意用户的数据结合起来,构建机器学习模型,以估算:
- 转化建模:估算未同意 ad_storage 的用户带来的转化
- GA4 中的行为建模:估算未同意用户的用户数和会话指标
转化建模要求
Google 要生成建模转化,Pinnacle E-Commerce Ltd 必须满足以下要求:
| 要求 | 门槛 |
|---|---|
| 每日获得同意的最低转化数 | 每个转化操作 70+ |
| 每日最低总转化数 | 每个转化操作 100+ |
| 同意模式实施时长 | 至少连续 7 天 |
| 标签覆盖范围 | 所有与转化相关的页面 |
GA4 行为建模
GA4 行为建模可填补分析数据中的缺失部分:
| 要求 | 门槛 |
|---|---|
| 每日获得同意的最低用户数 | 每个媒体资源 1,000+ |
| 最低数据天数 | 连续 7+ 天 |
| 同意模式覆盖范围 | 所有 GA4 网页浏览和事件标签 |
验证和调试
Google Tag Assistant 验证
使用 Google Tag Assistant(浏览器扩展程序)进行验证:
- 默认同意先于标签触发:检查 Tag Assistant 时间线中,同意默认值是否显示在 Google 标签配置之前
- 与 CMP 交互时触发同意更新:验证用户与 Cookie 横幅交互时是否出现同意更新事件
- 标签行为与同意状态一致:确认 GA4 和 Ads 标签是否根据同意状态触发或被阻止
实时调试
在 GA4 DebugView 中,受同意状态影响的事件会显示以下信息:
- 显示当前同意状态的“consent”徽章
- 当 analytics_storage 被拒绝时,缺少用户 ID/会话 ID
- 无 Cookie ping 指示器
网络层验证
监控对 https://www.google-analytics.com/g/collect 的网络请求:
| 参数 | 已授予同意 | 已拒绝同意 |
|---|---|---|
_p(页面 ID) | 存在 | 存在 |
cid(客户端 ID) | 来自 _ga cookie | 每次命中时随机生成 |
gcs(同意状态) | G111(全部授予) | G100(全部拒绝) |
gcd(默认同意设置) | 存在 | 存在 |
| Cookie 设置 | _ga、_gid | 无 |
EEA 要求(2024 年 3 月)
Google 的《数字市场法》(DMA)合规要求:
- 必须使用 Consent Mode v2:所有面向 EEA 用户投放广告的广告主都必须实施 Consent Mode v2,才能保留再营销名单并进行转化衡量
- 必须设置 ad_user_data 和 ad_personalization:必须设置这两个新增的 v2 参数;若省略,则视为“已拒绝”
- 建议使用经过验证的 CMP:Google 建议使用经过 Google 认证的 CMP 合作伙伴来收集欧盟用户的同意
- 需获得同意才能使用增强型转化:增强型转化(第一方数据匹配)要求 ad_user_data = granted
主要参考资料
- Google Consent Mode v2 文档 — 官方实施指南
- Google Tag Manager 同意配置 — GTM 专用设置说明
- Google Ads DMA 合规指南(2024 年 3 月) — EEA 专属要求
- 欧盟《数字市场法》(DMA)条例 2022/1925 — Google 同意要求的法律依据
- 《电子隐私指令》2002/58/EC 第 5(3) 条 — Cookie 同意的法律依据
- 欧盟法院 C-673/17 案(Planet49) — 适用于同意模式默认状态的主动同意要求