若要在保护用户隐私的同时获取富有价值的数据洞见,您需要征求网站用户的意见。建议您使用意见征求管理平台 (CMP) 或与您的内容管理系统 (CMS) 搭配使用来征求用户意见并将其发送给 Google。
不妨详细了解如何使用意见征求管理平台或内容管理系统设置意见征求横幅。
第 1 步:设置意见征求横幅
- 如果您使用的是 CCM Advanced(托管式服务),技术支持客户经理 (TAM) 会根据您的要求和样式指南设置横幅。
- 如果您使用的是 CCM Pro(自助式 CMP),TrustArc 会提供相应网址让您登录该门户,并使用向导中的预定义模板配置横幅。
- 确保您的横幅符合 Google 的《欧盟地区用户意见征求政策》(EUUCP) 的要求。如需详细了解 TrustArc 横幅设置,请参阅《用户指南》中的“使用入门”部分。
- 在网站代码中或通过 Google 跟踪代码管理器添加
<div>
元素,用于呈现横幅和 CMP 链接。
第 2 步:设置意见征求模式
使用 Google 跟踪代码管理器
- 打开 Google 跟踪代码管理器并前往您的容器。
- 在“代码”中,点击“新建”,然后为代码命名。
- 点击代码配置,然后点击“在社区模板库中发现更多代码类型”。在模板库中搜索“TrustArc CMP (Consent Mode)”,然后安装 TrustArc 提供的“TrustArc CMP (Consent Mode)”。
- 在“Default Consent Mode settings”(默认意见征求模式设置)下,配置您要使用的默认设置。
- 选择 Deploy CMP Script using the template(使用模板部署 CMP 脚本)选项。
- 在 CMP ID 字段中,输入 CCM Pro 门户中的“第 4 步:复制代码段”中的实例 ID。如果您使用的是 CCM Advanced,TAM 可为您提供这项信息。
- 在 Additional parameters(其他参数)字段中,为该实例输入其他设置。此配置用于覆盖语言、地理位置检测、隐私权政策链接等后端配置。
- 通过启用 Integrate CMP with Google Consent Mode(将 CMP 与 Google 意见征求模式集成)选项,设置 Google 意见征求模式集成。
- 根据您的设置,为意见征求类型和用户偏好设置确定映射关系。针对您要使用的每种意见征求类型,映射到 Cookie 意见征求类别(Required [必需]、Functional [功能]、Advertising [广告])的相应 ID。在 Preferences Cookie(偏好设置 Cookie)字段中,为 cmapi_cookie_privacy 映射第一方 Cookie。在 Behavior Cookie(行为 Cookie)字段中,为 notice_behavior 映射第一方 Cookie。
- 依次点击触发条件 > 用户意见征求初始化 - 所有网页 > 保存。
- 点击右上角的预览测试您的容器(请参阅下面的测试说明)。
- 发布您的容器。
使用其他平台或直接修改网站代码
- 登录 TrustArc 支持门户,点击此链接打开 TrustArc Google 意见征求模式实现指南,然后按照“使用 JavaScript 集成意见征求模式”部分中的说明进行操作。
- 如果您使用网站开发工具,请查看其文档,了解如何在每个网页的 head 标记中植入代码。否则,请跳到第 3 步。
- 如果您使用的是 CCM Advanced 版,请按这一步操作。否则,请跳到第 4 步。在每个网页的 head 标记中(如果您使用网站开发工具,请参阅第 2 步),复制以下代码并粘贴到 head 标记的最上方,紧接着再将您在第 1 步中复制的 CMP 脚本粘贴到此代码的后面。请注意,这对于确保 CMP 正常运行至关重要。
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-YYYYYY');
// 默认的意见征求类型为预留的“denied”
// 根据您自己的要求确定实际值
// 请省略当前未使用的意见征求类型
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied',
'functionality_storage': 'denied',
'personalization_storage': 'denied',
'security_storage': 'denied',
'wait_for_update': 500
});
gtag('set', 'ads_data_redaction', true);
gtag('set', 'developer_id.dNTIxZG', true);
</script>
<!--Banner script here!-->
- 如果您使用的是 CCM Pro 版,请按这一步操作。在每个网页的 head 标记中(如果您使用网站开发工具,请参阅第 2 步),复制以下代码并粘贴到 head 标记的最上方,紧接着再将您在第 1 步中复制的 CMP 脚本粘贴到此代码的后面。请注意,这对于确保 CMP 正常运行至关重要。请务必调整 CMP 类别与意见征求类型之间的关联。
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
gtag('set', 'developer_id.dNTIxZG', true);
// TODO:可以根据客户的需求和具体配置加以更改
gtag('set', 'ads_data_redaction', true);
gtag('set', 'url_passthrough', true);
// 意见征求模式状态
const ConsentType = {
DENIED: 'denied',
GRANTED: 'granted',
};
const convertBooleanToGrantedOrDenied = (boolean) => boolean ? ConsentType.GRANTED : ConsentType.DENIED;
/*
TODO:您可以在这里配置 Google 意见征求模式,映射 CMP 类别和默认值以进行用户意见征求初始化
Google 建议注释掉您不打算使用的意见征求类型。
*/
const domain = 'your_domain.com'; // TODO:更新
// 类别映射
const REQUIRED = 1;
const FUNCTIONAL = 2;
const ADVERTISING = 3;
const consentTypesMapped = {
'ad_storage': ADVERTISING,
'ad_user_data': ADVERTISING,
'ad_personalization': FUNCTIONAL,
'analytics_storage': FUNCTIONAL,
'functionality_storage': FUNCTIONAL,
'personalization_storage': FUNCTIONAL,
'security_storage': REQUIRED
}
const getConsentState = (prefCookie) => {
var consentStates = {};
var noticeBehavior = window.truste.util.readCookie("notice_behavior");
/*
TODO:可以根据客户的需求和具体配置加以更改
*/
var impliedLocation = noticeBehavior && noticeBehavior.includes("na");
for (const consentType in consentTypesMapped) {
var id = consentTypesMapped[consentType];
if(prefCookie && !prefCookie.includes(0)) {
console.log("Existing consent..");
consentStates[consentType] = convertBooleanToGrantedOrDenied(prefCookie && prefCookie.includes(id));
} else {
console.log("Non Existing consent..");
consentStates[consentType] = convertBooleanToGrantedOrDenied(impliedLocation);
;}
;}
consentStates['wait_for_update'] = 500;
console.log(consentStates);
return consentStates;
};
/*
用于在 TrustArc 的脚本中根据用户偏好提交 GCM 事件的辅助函数
consent:consent 将是一个由值 [1, 2, 3, n] 组成的数组,因为 1 表示用户同意用于“必需”用途、2 表示同意用于“功能”用途,以此类推
需根据客户所需的映射关系来自定义此函数。例如:'ad_storage': returnGrantedOrDenied(advertisingAccepted) 将映射到“广告”用途。假如我们需要将它改而映射到“功能”,只需更改它所针对的类别变量即可。
*/
var runOnceGCM = 0;
function handleConsentDecisionForGCM(consent) {
//此代码用于对意见征求模式进行初始化
const consentStates = getConsentState(consent.consentDecision);
var defaultOrUpdate;
if (runOnceGCM == 0) {
defaultOrUpdate = 'default';
runOnceGCM++;
} else {
console.log('consent is being updated');
defaultOrUpdate = 'update';
}
console.log(consentStates);
//同意情况一旦发生变化,我们就会发送更新
gtag('consent', defaultOrUpdate, {
consentStates
});
}
// 此代码负责通过 TrustArc 的 CCM 实例监听任何同意情况变化
// 并根据客户的意见征求映射关系将这些同意情况变化推送到 dataLayer
// 这针对的是初始加载。如果用户的同意情况不同于默认值,那么一旦 CCM 加载,
// 这就会向 datalayer 推送更新。
var interval = setInterval(() => {
if (window.truste) {
var consentDecision = truste.cma.callApi("getGDPRConsentDecision", domain);
handleConsentDecisionForGCM(consentDecision);
clearInterval(interval);
console.log("running once...");
}
}, 100);
// 开始监听用户何时提交其偏好
window.addEventListener("message", (event) => {
let eventDataJson = null;
// 此时我们只关心 TrustArc 事件。TrustArc 的事件是采用 JSON 编码的
try {
eventDataJson = JSON.parse(event.data);
} catch {
// 未采用 JSON 编码的其他某种事件。
// TrustArc 将数据编码为 JSON 的形式
// console.log(event.data);
}
// 这是保护措施,旨在确保我们只从 TrustArc 接收事件
if (eventDataJson && eventDataJson.source === "preference_manager") {
// 表示用户已提交其偏好
if (eventDataJson.message === "submit_preferences") {
console.log("Event Data: ", eventDataJson);
// 等待半秒时间,确保用户的偏好得到体现。
setTimeout(() => {
var consentDecision = truste.cma.callApi("getGDPRConsentDecision", domain);
console.log("Consent Decision: ", consentDecision);
handleConsentDecisionForGCM(consentDecision);
}, 500);
}
}
}, false);
<!--Banner script here!-->
使用 Tag Assistant 开展测试
不妨详细了解如何使用 Google 跟踪代码管理器对意见征求模式进行问题排查。