什么是 Google Consent Mode?

Google Consent Mode 允许您将用户关于 Cookie 或应用标识符的同意状态传达给 Google,使标签能够根据用户的偏好调整其行为。

此功能与 UniConsent Consent Management Platform (CMP) 无缝集成。Consent Mode 接收并响应通过您的 Cookie 横幅或小组件获得的用户同意选择。它会动态修改 Analytics、Ads 以及负责创建或访问 Cookie 的第三方标签的行为。

当访问者拒绝同意时,标签不会存储 Cookie;而是向 Google 发送信号。如果您使用的是 Google Analytics 4,Google 会通过转化建模和行为建模技术来弥补数据收集的空缺。

  • Google Analytics
  • Google Ads
  • Floodlight
  • Conversion Linker

您可以在 https://support.google.com/analytics/answer/9976101?hl=en 了解更多关于 Google Consent Mode 的信息。

UniConsent CMP 原生支持 Google Consent Mode API,并且会自动集成。

1. 使用 Google Tag Assistant

在左侧找到 Consent Update 并点击,然后在右侧点击 Consent Update 选项卡。您应该会看到类似以下的内容:

如何确认 UniConsent CMP 的 Google Consent Mode 正常工作如何确认 UniConsent CMP 的 Google Consent Mode 正常工作

请确保 UniConsent CMP 是通过 Consent Initialization - All Pages 触发加载的。

在浏览器的开发者控制台中,不应看到来自 UniConsent CMP 的任何警告消息。

您可以安装 UniConsent Consent Validator 来验证 Consent Mode 数据是否在您的网页上正确传递。

使用 UniConsent Consent Validator 验证 Consent Mode 是否正常工作使用 UniConsent Consent Validator 验证 Consent Mode 是否正常工作

4. 使用 DataLayer API:

在浏览器控制台中输入 window.dataLayer = window.dataLayer || [];,您应该能找到一个 consent, update 部分。

{
    "0": "consent",
    "1": "update",
    "2": {
        "ad_storage": "granted",
        "ad_user_data": "granted",
        "analytics_storage": "granted",
        "functionality_storage": "granted",
        "personalization_storage": "granted",
        "ad_personalization": "granted",
        "security_storage": "granted"
    }
}

您可以使用以下 Javascript API 来访问 Google Consent Mode 数据:

(function waitCMP() {
  var readyCMP
  if (!readyCMP && window['dataLayer']) {
    window['dataLayer'].forEach(function (event) {
      if (event['event'] === 'unic_data') {
        readyCMP = 1
        console.log(event['CONSENT_MODE'])
      }
    })
  }
  if (!readyCMP) {
    setTimeout(waitCMP, 100)
  }
})()
  1. 已启用 Google Consent Mode,但缺少默认状态桩代码

    问题: 您可能会在 Validator 或开发者控制台中看到以下错误消息:

    Error: Consent Mode Default Status is not added.

    解决方案: 在页面顶部添加默认状态桩代码即可解决此问题。您可以参照此处的说明操作:Consent Mode Default Status Tag Installation

  2. 已启用 Google Consent Mode,但默认状态桩代码添加在 Google 标签之后

    问题: 如果默认状态桩代码添加在 Google 标签之后,您可能会在 Validator 或开发者控制台中看到以下错误消息:

    Error: Your Google tags are loaded before Consent Mode Default Status and CMP.

    解决方案: 确保默认状态桩代码添加在页面的最顶部,位于所有 Google 标签之前。请参照此指南操作:Consent Mode Default Status Tag Installation

  3. 通过 Google Tag Manager 启用了 Google Consent Mode,但并非所有 Google 标签都在 Google Tag Manager 中管理

    问题: 当某些 Google 标签未在 Google Tag Manager 中管理时,您可能会看到与上述类似的错误。

    解决方案: 要么在页面顶部添加默认状态桩代码,要么确保所有 Google 标签都在 Google Tag Manager 中管理。请参照此指南:Consent Mode Default Status Tag Installation

  4. 缺少 IAB TCF 桩代码

    问题: 未包含 IAB TCF 桩代码,可能导致错误。

    解决方案: 在页面顶部添加 IAB TCF 桩代码。请参照此处的说明:Stub Codes Installation

  5. 缺少 IAB GPP 桩代码

    问题: 您的实施中缺少 IAB GPP 桩代码。

    解决方案: 在页面顶部添加 IAB GPP 桩代码。您可以在此处找到相关指南:Stub Codes Installation

  6. 缺少 USP API 桩代码

    问题: 未包含 IAB USP 桩代码。

    解决方案: 在页面顶部添加 IAB USP 桩代码即可解决此问题。详细说明请参见:Stub Codes Installation