简介
此 API 提供了一些工具,用于与“隐私权和消息”标签页提供的消息进行互动。借助该控制台,您可以执行以下操作:
- 禁止向任何指定用户显示消息
- 查询用户的广告拦截状态
- 呈现一个入口点,以便用户撤消欧盟法规同意声明
- 替换美国州级法规的默认“不出售”链接
- 根据用户在欧盟地区 Google 意见征求模式下的状态有条件地加载 Google Ads 和 Google Analytics 代码
等等。
您还可以使用这些工具通过行业标准协议征求用户意见:
- 使用 IAB TCF v2 规范征求 GDPR 用户意见
- 使用 IAB GPP 规范实现美国州级法规选择退出
在这些情况下,同意情况是通过这些 API 传达的。
您可以通过以下几种方式在网站上部署此用户消息功能:
- 在大多数情况下,您根本不需要重新添加代码 - 只要在相关产品中发布消息,您现有的 Google 发布商代码或 AdSense 代码就会部署用户消息。
- 如果您使用广告拦截收入挽回消息,则需要明确向网页添加广告拦截代码。如需了解详情,请参阅 Ad Manager 和 AdSense 代码植入说明。
googlefc
是用户消息传递功能在 JavaScript Window
上为其 API 使用的全局命名空间。
字段摘要
名称 | 类型 | 定义 |
---|---|---|
googlefc.controlledMessagingFunction
|
function(!Object) | 用于确定是否继续进行任何消息传递的函数。所有消息类型都支持此功能。 |
googlefc.callbackQueue
|
!Array<!Object<string, function()>> | !Array<function()> | !googlefc.CallbackQueue | 对回调队列的引用,用于异步执行用户消息传递查询。 |
googlefc.CallbackQueue
|
!Object | 回调队列对象的类型。 |
googlefc.AdBlockerStatusEnum
|
!Object<string, number> | 用于表示用户广告拦截器状态的枚举。 |
googlefc.AllowAdsStatusEnum
|
!Object<string, number> | 用于表示用户允许展示广告的状态的枚举。 |
googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum
|
!Object<string, number> | 一个枚举,用于表示用户的初始美国各州选择不分享/出售个人信息的状态。这会考虑用户所在的美国州。 |
googlefc.GoogleFcConsentModeUserStatus
|
!Object |
googlefc.getGoogleConsentModeValues 的返回类型。
|
googlefc.ConsentModePurposeStatusEnum
|
!Object<string, number> | 一个枚举,用于表示最终用户针对意见征求模式用途做出的决定。 |
googlefc.usstatesoptout.overrideDnsLink
|
undefined|boolean | 一个布尔值,可以设置为 true 以使用您自己的自定义“不出售或分享”链接。 |
googlefc.ccpa.InitialCcpaStatusEnum
旧版。首选 googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum 。
|
!Object<string, number> | 一个枚举,用于表示用户的初始美国州级法规状态。 |
googlefc.ccpa.overrideDnsLink
旧版。首选 googlefc.usstatesoptout.overrideDnsLink 。
|
undefined|boolean | 一个布尔值,可以设置为 true 以使用您自己的自定义“不出售或分享”链接。 |
方法摘要
名称 | 返回类型 | 定义 |
---|---|---|
googlefc.showRevocationMessage()
|
未定义 |
清除意见征求记录并重新加载 googlefc 脚本,以显示适用于用户的意见征求消息。
|
googlefc.getAdBlockerStatus()
|
数值 |
根据用户的广告拦截状态,返回 AdBlockerStatusEnum 中的值。
|
googlefc.getAllowAdsStatus()
|
数值 |
根据用户的广告允许状态,返回 AllowAdsStatusEnum 中的值。
|
googlefc.usstatesoptout.getInitialUsStatesOptOutStatus()
|
数值 |
根据用户的初始美国州级法规选择退出状态,返回 InitialUsStatesOptOutStatusEnum 中的值。这会考虑根据用户当前位置信息而适用的法规。
|
googlefc.usstatesoptout.openConfirmationDialog(function(boolean))
|
未定义 | 如果默认的“不出售/分享”链接被替换,则会打开美国州级法规选择退出确认对话框。 |
googlefc.getGoogleConsentModeValues()
|
!Object |
返回一个 googlefc.GoogleFcConsentModeUserStatus 对象,其中包含用户的当前意见征求模式值,每个可用的意见征求模式用途对应一个值。
|
googlefc.ccpa.getInitialCcpaStatus()
旧版。首选 googlefc.usstatesoptout.getInitialUsStatesOptOutStatus() 。
|
数值 |
根据用户的初始美国州级法规选择退出状态,返回 InitialCcpaStatusEnum 中的值。
|
googlefc.ccpa.openConfirmationDialog(function(boolean))
旧版。首选 googlefc.usstatesoptout.openConfirmationDialog() 。
|
未定义 | 如果默认的“不出售/分享”链接被替换,则打开美国州级法规选择退出确认对话框。 |
在网站上进行测试和调试
“隐私权和消息”工具提供调试和测试功能,可让您了解特定消息、消息子类型或消息组合在您的实际网站上的显示效果。
前提条件:
- 您要预览的消息必须已发布到您要测试的网站
您可以使用以下调试网址参数在网站上查看实时预览:
调试参数 | 允许使用的值 |
---|---|
fc |
alwaysshow (用于触发调试/预览模式) |
fctype |
ab (广告拦截消息)、ccpa (美国州级法规信息拒售要求收集消息)、gdpr (GDPR 意见征求消息)、monetization (Offerwall 消息)、usfl (美国州级法规信息拒售要求收集消息,仅限佛罗里达州)、usnat (美国州级法规信息拒售要求收集消息,适用于除佛罗里达州以外的所有受支持州;等同于 ccpa ) |
以下是一些示例,说明了如何使用此功能在您的网站 (foo.com) 上进行预览:
- 测试美国州级法规选择退出消息 --
http://foo.com/?fc=alwaysshow&fctype=ccpa
- 测试 GDPR 消息传递功能 -
http://foo.com/?fc=alwaysshow&fctype=gdpr
字段:说明和示例
googlefc.controlledMessagingFunction {function(!Object)}
用于确定是否应显示消息的函数。它可用于根据发布商指定的条件(例如订阅者状态或网页网址)控制消息呈现。
如果在其他脚本加载之前在 Window 上定义 googlefc.controlledMessagingFunction
,则在调用 message.proceed(boolean)
之前,消息不会显示。调用 message.proceed(true)
可让消息传递照常进行,而调用 message.proceed(false)
则会阻止任何消息显示在网页浏览中。
示例:假设您在网页上添加了以下脚本,该脚本定义了一个异步函数 determineIfUserIsSubscriber()
,用于检查登录用户是否为订阅者。
<head>
<script>
window.isSubscriber = undefined;
function determineIfUserIsSubscriber() {
if (isSubscriber !== undefined) {
return isSubscriber;
}
return new Promise(resolve => {
setTimeout(() => {
// Change this to true if you want to test what subscribers would see.
window.isSubscriber = false;
resolve(window.isSubscriber);
}, 1000);
});
}
</script>
</head>
以下示例展示了如何使用 googlefc.controlledMessagingFunction
仅向非订阅者显示消息。
<head>
<script>
// Define googlefc and the controlled messaging function on the Window.
window.googlefc = window.googlefc || {};
googlefc.controlledMessagingFunction = async (message) => {
// Determine if the user is a subscriber asynchronously.
const isSubscriber = await determineIfUserIsSubscriber();
if (isSubscriber) {
// If the user is a subscriber, don't show any messages.
message.proceed(false);
} else {
// Otherwise, show messages as usual.
message.proceed(true);
}
}
</script>
</head>
此功能还可扩展,让发布商能够指定仅抑制积分墙。使用此功能扩展可禁止显示 Offerwall,而不会禁止显示其他消息类型。
通过向 message.proceed()
传递一个额外的参数(即类型为 googlefc.MessageTypeEnum
的 Array
),可以实现积分墙专属的受控消息传递。
示例:以下示例展示了如何使用 googlefc.controlledMessagingFunction
仅禁止向订阅者投放 Offerwall,而不禁止投放其他类型的消息:
<head>
<script>
// Define googlefc and the controlled messaging function on the Window.
window.googlefc = window.googlefc || {};
googlefc.controlledMessagingFunction = async (message) => {
// Determine if the Offerwall should display or not.
const shouldDisplayOfferwall = await determineIfUserIsSubscriber();
const applicableMessageTypes = [];
if (!shouldDisplayOfferwall) {
// Do not show the Offerwall, but allow other message types to display.
applicableMessageTypes.push(window.googlefc.MessageTypeEnum.OFFERWALL);
message.proceed(false, applicableMessageTypes);
} else {
// Otherwise, show messages as usual.
message.proceed(true);
}
}
</script>
</head>
对全局回调队列的引用,用于异步执行与消息传递相关的调用。调用任何函数的唯一受支持方式是将其添加到 callbackQueue
。
由于不同类型的数据在不同时间可用,因此应将函数添加为映射,其中一个键为以下字符串,值为要执行的函数。
支持的键:
密钥名称 | 用法 | 相对延迟时间 |
---|---|---|
CONSENT_API_READY
|
当支持的意见征求框架的 API 已定义且可调用时,使用 CONSENT_API_READY 键推送到回调队列的函数会执行。从这一刻起,任何后续添加的以 CONSENT_API_READY 为键的函数的执行都是同步的。如需了解框架的具体详情,请参阅有关 IAB 框架的部分。
|
低 |
CONSENT_DATA_READY
|
当通过受支持的意见征求框架收集的用户同意情况已知时(无论是通过之前的执行还是在用户与意见征求消息互动后),系统会执行使用 CONSENT_DATA_READY 键推送到回调队列中的函数。从这一刻起,任何后续添加的以 CONSENT_DATA_READY 为键的函数的执行都是同步的。
|
高 |
AD_BLOCK_DATA_READY
|
当广告屏蔽数据在流程中可用时,系统会执行使用 AD_BLOCK_DATA_READY 键推送到回调队列中的函数。从这一刻起,任何后续添加的以 AD_BLOCK_DATA_READY 为键的函数的执行都是同步的。
|
高 |
CONSENT_MODE_DATA_READY
|
使用 CONSENT_MODE_DATA_READY 键推送到回调队列的函数会在 Google [意见征求模式](https://support.google.com/google-ads/answer/10000067)数据(用于 Google Ads 和 Google Analytics 代码)在流程中可用时执行。意见征求模式数据准备就绪后,您可以使用 googlefc.getGoogleConsentModeValues 随时访问意见征求模式值。
|
中 |
INITIAL_US_STATES_OPT_OUT_DATA_READY
|
当流程中提供美国州级法规数据时,会执行使用 INITIAL_US_STATES_OPT_OUT_DATA_READY 键推送到回调队列的函数。请注意,任何后续的美国州法规数据请求都应通过直接调用 GPP API (__gpp ) 来获取。
|
中 |
INITIAL_CCPA_DATA_READY
|
美国州级法规的旧版键。首选 INITIAL_US_STATES_OPT_OUT_DATA_READY 。 当流程中提供美国州法规数据时,使用 INITIAL_CCPA_DATA_READY 键推送到回调队列的函数会执行。请注意,任何后续的美国州法规数据请求都应通过直接调用 GPP API (__gpp ) 来获取。
|
中 |
googlefc.CallbackQueue {!Object}
方法总结:
名称 | 类型 | 参数 | 返回类型 | 角色 |
---|---|---|---|---|
push(data)
|
数值 |
data :一个键值对,其中键是数据可用性类型之一,值是要执行的 JavaScript 函数。
可接受的数据可用性键包括 CONSENT_API_READY 、CONSENT_DATA_READY 、AD_BLOCK_DATA_READY 、INITIAL_US_STATES_OPT_OUT_DATA_READY 、CONSENT_MODE_DATA_READY 和(旧版)INITIAL_CCPA_DATA_READY 。
|
到目前为止添加的命令数量。此方法会返回数组的当前长度。 | 按数据可用的顺序执行传入的函数,然后按这些函数添加到队列中的顺序执行。 |
示例:
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Queue the callback on the callbackQueue.
googlefc.callbackQueue.push({
'AD_BLOCK_DATA_READY':
() => {
if (googlefc.getAdBlockerStatus() == googlefc.AdBlockerStatusEnum.NO_AD_BLOCKER) {
// Handle a non-ad blocking user.
}
}
});
</script>
googlefc.AdBlockerStatusEnum {!Object<string, number>}
表示用户的不同广告拦截状态。不同的状态包括:
googlefc.AdBlockerStatusEnum = {
// Something failed, in an unknown state.
UNKNOWN: 0,
// The user was running an extension level ad blocker.
EXTENSION_AD_BLOCKER: 1,
// The user was running a network level ad blocker.
NETWORK_LEVEL_AD_BLOCKER: 2,
// The user was not blocking ads.
NO_AD_BLOCKER: 3,
};
googlefc.AllowAdsStatusEnum {!Object<string, number>}
表示用户的不同广告拦截允许展示广告状态。不同的状态包括:
googlefc.AllowAdsStatusEnum = {
// Something failed, in an unknown state.
UNKNOWN: 0,
// User is currently using an ad blocker, was never using an ad blocker, or
// allowed ads, but not because they saw the Privacy & messaging message.
ADS_NOT_ALLOWED: 1,
// User is no longer using an ad blocker after seeing the ad blocking message.
ADS_ALLOWED: 2,
};
googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum{!Object<string, number>}
表示用户的不同美国州级法规选择退出状态。不同的状态如下:
googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum = {
// Something failed, status unknown.
UNKNOWN: 0,
// No US state regulation applies to this user.
DOES_NOT_APPLY: 1,
// A US state regulation applies to this user, and the user has not opted out yet.
NOT_OPTED_OUT: 2,
// A US state regulation applies to this user, and the user has opted out.
OPTED_OUT: 3,
};
googlefc.GoogleFcConsentModeUserStatus{!Object}
googlefc.getGoogleConsentModeValues
返回的对象的类型。
interface GoogleFcConsentModeUserStatus {
// End user consent decision value for the ad_storage consent mode purpose.
adStoragePurposeConsentStatus: number;
// End user consent decision value for the ad_user_data consent mode purpose.
adUserDataPurposeConsentStatus: number;
// End user consent decision value for the ad_personalization consent mode purpose.
adPersonalizationPurposeConsentStatus: number;
// End user consent decision value for the analytics_storage consent mode purpose.
analyticsStoragePurposeConsentStatus: number;
}
每个字段的值都是一个数字,对应于 googlefc.ConsentModePurposeStatusEnum
枚举值。
googlefc.ConsentModePurposeStatusEnum{!Object<string, number>}
表示同意模式用途的不同可能最终用户同意值。不同的值包括:
googlefc.ConsentModePurposeStatusEnum = {
// Indicates either an error state, or that consent mode data is not ready
// yet.
UNKNOWN: 0,
// Consent is granted for the given consent mode purpose.
GRANTED: 1,
// Consent is denied for the given consent mode purpose.
DENIED: 2,
// Consent is not applicable for the given consent mode purpose.
NOT_APPLICABLE: 3,
// The consent mode purpose has not been configured for use in the Privacy &
// messaging UI.
NOT_CONFIGURED: 4
};
googlefc.usstatesoptout.overrideDnsLink{undefined|boolean}
将此字段设置为 true 可隐藏默认的“不出售或分享”链接,并使用您自己的自定义“不出售或分享”链接。
示例:
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
// Signals that the default DNS link will be overridden.
googlefc.usstatesoptout.overrideDnsLink = true;
</script>
googlefc.ccpa.InitialCcpaStatusEnum{!Object<string, number>}
表示用户的不同美国州级法规选择退出状态。不同的状态如下:
googlefc.ccpa.InitialCcpaStatusEnum = {
// Something failed, in an unknown state.
UNKNOWN: 0,
// No US state regulation applies to this user.
CCPA_DOES_NOT_APPLY: 1,
// A US state regulation applies to this user, and the user has not opted out yet.
NOT_OPTED_OUT: 2,
// A US state regulation applies to this user, and the user has opted out.
OPTED_OUT: 3,
};
googlefc.ccpa.overrideDnsLink{undefined|boolean}
将此字段设置为 true 可隐藏默认的“不出售/分享我的个人信息”链接,并使用您自己的自定义“不出售/分享我的个人信息”链接。请注意,如果您将此字段设置为 true,则您有责任在自己的网站上呈现“不出售或分享”链接。此字段应与 openConfirmationDialog
结合使用。
示例:
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.ccpa = window.googlefc.ccpa || {};
// Signals that the default DNS link will be overridden.
googlefc.ccpa.overrideDnsLink = true;
</script>
方法:说明和示例
googlefc.getConsentStatus(): {number}
googlefc.getConsentedProviderIds(): {!Array<string>}
- 现在,此方法在被调用时始终会返回一个空列表。
googlefc.showRevocationMessage(): {undefined}
清除当前的欧盟法规意见征求记录(如有),并再次显示欧盟法规消息,以便用户更改其同意情况。
示例 1:设置链接的简单示例,点击该链接时会显示撤消消息:
<a href="javascript:window.googlefc.showRevocationMessage();">Privacy and cookie settings</a>
<a href="javascript:window.googlefc.showRevocationMessage();" style="display: none;" id="revocation-link">Privacy and cookie settings</a>
<script>
window.googlefc = window.googlefc || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
window.googlefc.callbackQueue.push({
'CONSENT_API_READY':
() => {
// Update the revocation link so that it shows on the page.
const revocationLink = document.getElementById('revocation-link');
revocationLink.style.display = 'block';
}
});
</script>
示例 2:如果您只希望在欧盟法规适用于当前用户时显示链接,则可以使用 googlefc 回调队列和 TCF API,根据 gdprApplies
值(一旦确定)有条件地更新按钮的显示。为此,请使用 CONSENT_API_READY
API 密钥。
<a href="javascript:window.googlefc.showRevocationMessage();" style="display: none;" id="revocation-link">Privacy and cookie settings</a>
<script>
window.googlefc = window.googlefc || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
window.googlefc.callbackQueue.push({
'CONSENT_API_READY':
// Specifying "0" for the version parameter will result in the API call
// using the latest version of the TCF spec.
() => __tcfapi('addEventListener', 0, (tcdata, success) => {
const revocationLink = document.getElementById('revocation-link');
if (!success || !tcdata) {
// Something went wrong, don't show the revocation link.
revocationLink.style.display = 'none';
}
else if (tcdata.gdprApplies) {
revocationLink.style.display = 'block';
} else {
// GDPR does not apply so don't show the revocation link.
revocationLink.style.display = 'none';
}
})
});
</script>
googlefc.getAdBlockerStatus(): {number}
根据用户的广告拦截状态返回 AdBlockerStatusEnum 中的一个值。应为此函数指定的键是 AD_BLOCK_DATA_READY
。
示例:
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Queue the callback on the callbackQueue.
googlefc.callbackQueue.push({
'AD_BLOCK_DATA_READY':
() => {
switch (googlefc.getAdBlockerStatus()) {
case googlefc.AdBlockerStatusEnum.EXTENSION_LEVEL_AD_BLOCKER:
case googlefc.AdBlockerStatusEnum.NETWORK_LEVEL_AD_BLOCKER:
// Insert handling for cases where the user is blocking ads.
break;
case googlefc.AdBlockerStatusEnum.NO_AD_BLOCKER:
// Insert handling for cases where the user is not blocking ads.
break;
case googlefc.AdBlockerStatusEnum.UNKNOWN:
// Insert handling for unknown cases.
break;
}
}
});
</script>
googlefc.getAllowAdsStatus(): {number}
根据用户的广告允许状态,返回 AllowAdsStatusEnum
中的值。应为此函数指定的键是 AD_BLOCK_DATA_READY
。
示例:
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Queue the callback on the callbackQueue.
googlefc.callbackQueue.push({
'AD_BLOCK_DATA_READY':
() => {
switch (googlefc.getAllowAdsStatus()) {
case googlefc.AllowAdsStatusEnum.ADS_NOT_ALLOWED:
// Insert handling for cases where the user has not allowed ads.
// The user may have never been an ad blocker.
break;
case googlefc.AllowAdsStatusEnum.ADS_ALLOWED:
// Insert handling for cases where the user saw the ad blocking
// message and allowed ads on the site.
break;
case googlefc.AllowAdsStatusEnum.UNKNOWN:
// Insert handling for unknown cases.
break;
}
}
});
</script>
googlefc.usstatesoptout.getInitialUsStatesOptOutStatus(): {number}
根据用户的美国州级法规选择退出状态,返回 InitialUsStatesOptOutStatusEnum
中的一个值。应为此函数指定的键是 INITIAL_US_STATES_OPT_OUT_DATA_READY
。请注意,任何后续的美国州级法规数据请求都应通过直接调用 GPP API (__gpp
) 来获取。
如果您要替换“不出售或分享我的个人信息”链接,可以使用此方法来确定何时在您的网站上添加该链接。
示例:
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {}
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Queue the callback on the callbackQueue.
googlefc.callbackQueue.push({
'INITIAL_US_STATES_OPT_OUT_DATA_READY':
() => {
switch (googlefc.usstatesoptout.getInitialUsStatesOptOutStatus()) {
case googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum.DOES_NOT_APPLY:
// Insert handling for cases where no US state regulation applies to
// the user.
break;
case googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum.NOT_OPTED_OUT:
// Insert handling for cases where a US state regulation applies to
// the user, and the user has not opted out.
break;
case googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum.OPTED_OUT:
// Insert handling for cases where a US state regulation applies to the
// user, and the user has opted out.
break;
}
}
});
</script>
googlefc.usstatesoptout.openConfirmationDialog(function(boolean)): {undefined}
如果默认的“不出售我的个人信息”链接被替换,则打开美国州法规选择退出确认对话框。用户与确认对话框互动后,系统会调用提供的回调函数,如果用户决定选择不接收,则传递 true
,否则传递 false
。
示例:
<script>
// This callback will be called with the user's US state regulation opt-out
// decision.
const usStateRegCompletionCallback = (userOptedOut) => {
// Insert handling for user opt-out status here.
}
// Invoke the US state regulations confirmation dialog when the user clicks the
// link.
document.getElementById("your-custom-do-not-sell-link").addEventListener(
"click", () => googlefc.usstatesoptout.openConfirmationDialog(usStateRegCompletionCallback));
</script>
googlefc.getGoogleConsentModeValues(): {!Object}
返回一个 googlefc.GoogleFcConsentModeUserStatus
对象,其中包含根据用户意见征求决定得出的每种意见征求模式用途的当前值。
如需了解预期用途,请参阅将 Google 意见征求管理解决方案与支持欧盟法规的意见征求模式搭配使用。
googlefc.ccpa.getInitialCcpaStatus(): {number}
根据用户的美国州级法规选择退出状态,返回 InitialCcpaStatusEnum
中的一个值。应为此函数指定的键是 INITIAL_CCPA_DATA_READY
。请注意,任何后续的美国州法规数据请求都应通过直接调用 GPP API (__gpp
) 来获取。
示例:
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.ccpa = window.googlefc.ccpa || {}
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Queue the callback on the callbackQueue.
googlefc.callbackQueue.push({
'INITIAL_CCPA_DATA_READY':
() => {
switch (googlefc.ccpa.getInitialCcpaStatus()) {
case googlefc.ccpa.InitialCcpaStatusEnum.CCPA_DOES_NOT_APPLY:
// Insert handling for cases where no US state regulation applies to
// the user.
break;
case googlefc.ccpa.InitialCcpaStatusEnum.NOT_OPTED_OUT:
// Insert handling for cases where a US state regulation applies to
// the user, and the user has not opted out.
break;
case googlefc.ccpa.InitialCcpaStatusEnum.OPTED_OUT:
// Insert handling for cases where a US state regulation applies to the
// user, and the user has opted out.
break;
}
}
});
</script>
googlefc.ccpa.openConfirmationDialog(function(boolean)): {undefined}
如果默认的“不出售我的个人信息”链接被替换,则打开美国州法规选择退出确认对话框。用户与确认对话框互动后,如果用户决定选择不接收,则使用 true
调用所提供的回调函数;否则,使用 false
调用该函数。
示例:
<script>
// This callback will be called with the user's US state regulation opt-out
// decision.
const usStateRegCompletionCallback = (userOptedOut) => {
// Insert handling for user opt-out status here.
}
// Invoke the US state regulations confirmation dialog when the user clicks the
// link.
document.getElementById("your-custom-ccpa-do-not-sell-link").addEventListener(
"click", () => googlefc.ccpa.openConfirmationDialog(ccpaCompletionCallback));
</script>
将 Google 意见征求管理解决方案与 IAB TCF v2 搭配使用,以遵循 GDPR
如果您使用的是 Google 意见征求管理解决方案,并希望根据 IAB TCF v2 框架征求 GDPR 意见,则应使用 IAB TCF v2 API。
您可以使用 CONSENT_API_READY
回调队列键来确保仅当页面上定义了 IAB TCF v2 API 时,才会调用相应的回调。此方法应与 IAB TCF v2 API 的 'addEventListener'
命令结合使用。
示例:
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Queue the callback using the CONSENT_API_READY key on the callbackQueue.
window.googlefc.callbackQueue.push({
'CONSENT_API_READY':
() => __tcfapi('addEventListener', 2.2, (data, success) => {
// Do something with consent data value; this callback may be invoked
// multiple times as user completes consent flow.
})
});
</script>
您可以使用 CONSENT_DATA_READY
回调队列键来确保仅在通过 IAB TCF v2 API 收集并可访问用户意见征求数据时才调用相应回调。此命令可与 'addEventListener'
命令搭配使用 - 在首次调用您提供的回调时提供的数据将包含用户的意见征求选择(只要 TCF v2 适用于相应用户)。请注意,随着 TCF v2.2 的发布,'getTCData'
命令现已弃用。
示例:
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Queue the callback using the CONSENT_DATA_READY key on the callbackQueue.
window.googlefc.callbackQueue.push({
'CONSENT_DATA_READY':
() => __tcfapi('addEventListener', 2.2, (data, success) => {
// Do something with consent data value; this callback may be invoked
// multiple times if user consent selections change.
})
});
</script>
将 Google 意见征求管理解决方案与支持欧盟法规的意见征求模式搭配使用
Google 意见征求管理解决方案可以解读用户在欧盟法规方面的意见征求结果,以用于 Google 意见征求模式(如需了解详情,请参阅帮助中心)。
您可以按照 Google Ads 和 Google Analytics 文档中的说明,以基本模式或高级模式实现意见征求模式。 您应咨询法务部门,了解应实现哪种意见征求模式才能满足法律要求。
系统默认支持高级意见征求模式;在“隐私权和消息”界面中启用意见征求模式后,您无需进行任何额外操作。
如需使用 Google 意见征求管理解决方案实现基本意见征求模式,您可以使用 CONSENT_MODE_DATA_READY
回调队列键在意见征求模式数据可用后有条件地加载 Google Ads 和 Google Analytics 代码。在 Funding Choices 确定意见征求模式不适用于相应请求(例如,因为欧盟法规不适用于相应请求)后,或者在用户根据欧盟法规做出意见征求决定后,意见征求模式数据才会可用。您应咨询法务部门,了解在意见征求模式可用后,应使用哪些条件来确定是否可以加载代码。
例如,如需在意见征求模式数据可用时加载代码,无论最终用户的同意情况如何,请执行以下操作:
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Helper function to load Google Ads/Analytics tags once consent mode data is
// ready.
const loadGtagScript = () => {
// Load gtag.js script - code taken from
// https://developers.google.com/tag-platform/security/guides/consent?consentmode=basic#set_up_consent_mode
var gtagScript = document.createElement('script');
gtagScript.async = true;
gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=<Google tag ID>';
var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(gtagScript,firstScript);
}
// Queue the callback using the CONSENT_MODE_DATA_READY key on the callbackQueue.
window.googlefc.callbackQueue.push({
'CONSENT_MODE_DATA_READY':
() => {
loadGtagScript();
},
});
</script>
您还可以使用 googlefc.getGoogleConsentModeValues()
API 在意见征求模式数据可用时获取各个意见征求模式用途的值。此 API 会返回一个 GoogleFcConsentModeUserStatus
对象,该对象包含每个受支持的意见征求模式用途对应的字段,并且每个字段的值都是一个枚举值,用于指示相应意见征求模式用途的值。
例如,您可以仅在以下任一情况下使用 googlefc.getGoogleConsentModeValues()
来解除对 Google Ads 和 Google Analytics 代码的屏蔽:
- 最终用户根据欧盟法规做出的意见征求决定是同意所有意见征求模式用途,或者
- 所有意见征求模式用途均不适用于当前请求(如果欧盟法规不适用,或者未在“隐私权和消息”中针对一个或多个用途配置意见征求模式,则可能会出现这种情况)。
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Helper function to determine whether Google Ads and Analytics tags can be
// unblocked. Returns true if all consent mode purposes are set to GRANTED,
// NOT_APPLICABLE, or NOT_CONFIGURED.
const shouldUnblockConsentTags = (googleFcConsentModeStatus) => {
const allConsentModeValues = [
googleFcConsentModeStatus.adStoragePurposeConsentStatus,
googleFcConsentModeStatus.adUserDataPurposeConsentStatus,
googleFcConsentModeStatus.adPersonalizationPurposeConsentStatus,
googleFcConsentModeStatus.analyticsStoragePurposeConsentStatus
];
for (const consentModeValue of allConsentModeValues) {
switch (consentModeValue) {
case googlefc.ConsentModePurposeStatusEnum.CONSENT_MODE_PURPOSE_STATUS_UNKNOWN:
// Indicates either an error case or that consent mode data is not
// ready yet. Cannot unblock tags until consent data is ready and valid,
// so return false.
return false;
case googlefc.ConsentModePurposeStatusEnum.CONSENT_MODE_PURPOSE_STATUS_GRANTED:
// Consent is granted for this consent mode purpose.
break;
case googlefc.ConsentModePurposeStatusEnum.CONSENT_MODE_PURPOSE_STATUS_DENIED:
// Consent is denied for this consent mode purpose. Do not unblock tags.
return false;
case googlefc.ConsentModePurposeStatusEnum.CONSENT_MODE_PURPOSE_STATUS_NOT_APPLICABLE:
// Consent mode does not apply for this purpose.
break;
case googlefc.ConsentModePurposeStatusEnum.CONSENT_MODE_PURPOSE_STATUS_NOT_CONFIGURED:
// Consent mode not configured for this purpose.
// If you configured support for Ads purposes but not Analytics purposes in the
// Privacy & messaging UI, the value of `analyticsStoragePurposeConsentStatus` will
// always be set to NOT_CONFIGURED. If you do not enable any Consent Mode support
// in the Privacy & messaging UI, the values of all purposes will always be set to
// NOT_CONFIGURED.
break;
default:
console.log("Unexpected consent mode value encountered");
}
}
// If all prior checks pass, all consent mode values are either GRANTED,
// NOT_APPLICABLE, or NOT_CONFIGURED.
return true;
};
// Helper function to load Google Ads/Analytics tags.
const loadGtagScript = () => {
// Load gtag.js script - code taken from
// https://developers.google.com/tag-platform/security/guides/consent?consentmode=basic#set_up_consent_mode
var gtagScript = document.createElement('script');
gtagScript.async = true;
gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=<Google tag ID>';
var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(gtagScript,firstScript);
}
googlefc.callbackQueue.push({
CONSENT_MODE_DATA_READY: () => {
if (shouldUnblockConsentTags(googlefc.getGoogleConsentModeValues())) {
loadGtagScript();
}
},
});
</script>
将 Google 意见征求管理解决方案与 IAB GPP 框架搭配使用,以满足美国州级法规要求
如果您使用 Google 意见征求管理解决方案在 IAB GPP 框架下向最终用户提供美国州级法规选择退出消息,则应使用 IAB GPP API。
由于美国各州法规的退出性质,您可以使用 CONSENT_API_READY
或 CONSENT_DATA_READY
回调队列键,以确保在调用回调时,IAB GPP API 可调用并返回意见征求数据。
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Queue the callback on the callbackQueue.
window.googlefc.callbackQueue.push({
'CONSENT_DATA_READY':
() => __gpp('ping', (data, success) => {
// Do something with consent data value.
})
});
</script>
将 Google 意见征求管理解决方案与 IAB GPP 框架搭配使用,以遵守美国州级法规,并使用您自己的自定义“不出售/分享”链接
如果您使用 Google 意见征求管理解决方案在 IAB GPP 框架下向最终用户提供美国各州法规的“选择不出售/分享个人信息”消息,则可以通过将 googlefc.usstatesoptout.overrideDnsLink
标志设置为 true
来提供您自己的自定义“不出售/分享个人信息”链接。
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
// Signals that the default DNS link will be overridden.
window.googlefc.usstatesoptout.overrideDnsLink = true;
// Register the callback for the initial US state regulations data.
window.googlefc.callbackQueue.push({
'INITIAL_US_STATES_OPT_OUT_DATA_READY': () => {
if (googlefc.usstatesoptout.getInitialUsStatesOptOutStatus() ===
googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum.NOT_OPTED_OUT) {
// TODO: Display custom Do Not Sell or Share link here.
}
}
});
</script>
这样可确保默认的“不出售或不分享”链接不会呈现。然后,您需要通过调用美国州级法规选择退出确认对话框来处理用户与自定义“不出售/分享”链接的互动。
请注意,如果您使用自己的自定义“不出售/分享”链接,则有责任确保该链接符合美国州级法规。
<script>
// This callback will be called when the user makes a US state regulations
// decision.
const usStateRegCompletionCallback = (userOptedOut) => {
if (userOptedOut) {
// TODO: Hide custom Do Not Sell or Share link here.
}
}
// Invoke the US state regulations opt-out confirmation dialog when the user
// clicks the link.
document.getElementById("your-custom-do-not-sell-link").addEventListener(
"click", () => googlefc.usstatesoptout.openConfirmationDialog(usStateRegCompletionCallback));
</script>