问题描述
我已经选择Quantcast Choice作为我网站的同意管理平台。但是,通过其基本解决方案,在访问者同意相关供应商(Google)之前,仍会向访问者投放Google Adsense广告。自2天以来,Adsense中已发布一条确认此问题的通知,并且在90天的宽限期之后,将不再投放任何广告。错误消息:“ 2.1a:由于CMP状态为存根,加载或错误,标记或SDK没有收到TC字符串。”
我对脚本一点都不熟悉,但是似乎我必须使用一些脚本才能使Quantcast Choice真正起作用。 基本上我需要知道如何:
- 在访问者同意Google之前不投放任何Google广告
- 同意后投放个性化广告
- 未经同意即可投放非个性化广告
到目前为止我学到的东西:
在访问者同意之前,我可以将此脚本添加到我的Google Adsense代码中,以不显示任何广告:
<script>(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=1;</script>
到目前为止没有问题。但是,那么我应该能够知道访问者是否已同意卖方Google。 TCF v2.0中Google的供应商ID为755。我在Quantcast页面之一上发现以下代码和文本的混合体,但我不知道该如何使用。我应该将它放在Quantcast Choice脚本中还是...上? (来源链接在下面)
{{QC - __cmpConsents.iabvendorConsentIds}} matches the regular expression (^|,)755(,|$).
因此,如果找到ID 755,我应该致电:
(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=0
如果找不到ID 755,我应该致电:
(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=1
(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=0
但是我该怎么做这些“电话”?
所以我认为我了解要遵循的步骤,只是我不知道如何实现这些步骤并连接点。任何帮助将不胜感激!
我使用的来源:
- https://support.google.com/adsense/answer/9042142
- https://help.quantcast.com/hc/en-us/articles/360051794434
似乎可以实现我想要实现的目标的网站示例:carscoops.com
解决方法
我建议一个简单的解决方案。使用TCF 2.0,您不必根据给定的同意手动配置Adsense参数(个性化广告等)。您只需要保证,就可以在成功加载同意书后开始加载广告。 Adsense库自动读取同意字符串,并根据给定的同意显示广告。
将Quantcast Choices与Adsense集成的示例代码:
<!-- Quantcast Choice. Consent Manager Tag v2.0 (for TCF 2.0) -->
...
<!-- End Quantcast Choice. Consent Manager Tag v2.0 (for TCF 2.0) -->
<script>
__tcfapi('addEventListener',2,function(tcData,success) {
if (success) {
if (tcData.eventStatus == 'useractioncomplete' || tcData.eventStatus == 'tcloaded') {
var hasStoreOnDeviceConsent = tcData.purpose.consents[1] || false;
if (hasStoreOnDeviceConsent) {
var adsbygoogle_script = document.createElement('script');
adsbygoogle_script.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
document.head.appendChild(adsbygoogle_script);
}
}
}
});
</script>
,
为了帮助大家理解, 2.1a Google IAB TCF v2错误可能是由于在设置/建立用户同意之前将Google广告产品标签添加到网站上引起的。这是简短的video,显示了预期的行为,只有在用户同意之后才能加载广告。如果您在用户选择同意之前看到广告在后台加载,则您将收到2.1a错误,因为您是在未等待同意的情况下添加Google标签的。
针对此问题的解决方案会有所不同,具体取决于您将Google Advertising Product标签添加到网站的方式,但希望以下信息和Adsense示例帮助。
Google跟踪代码管理器
如果您使用Google跟踪代码管理器将Choice和Google标记添加到您的网站,则可以在https://help.quantcast.com/hc/en-us/articles/360051794434和https://help.quantcast.com/hc/en-us/articles/360051794434-TCF-v2-GTM-Implementation-Guide-IAB-Vendor-Tag-Blocking这里使用该指南作为参考。
Adsense特定示例
以https://support.google.com/adsense/answer/9042142中的示例为例,我相信这是您需要重新制作示例以等待Quantcast Choice TCF v2.0发出的正确同意信号的方式。
我还没有机会进行全面测试,因此,如果您对代码有任何疑问,请告诉我,我将更新示例。
请参见此代码块以获取更新的版本
!=
编辑:添加了新的更新版本(8月18日)
这可能是比上面更好的版本。再次未经测试,因此如果遇到问题,请进行测试并提供反馈。此更新版本的主要区别在于:
-
我们不再检查tcData.purpose.consents [3]和tcData.purpose.consents [4],而是依靠Google来决定是否显示个性化广告。
-
在未获得我们的同意之前,我们不会将https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js添加到页面中,以防止在我们确定同意之前添加不需要的cookie。这也使我们可以删除(adsbygoogle = window.adsbygoogle || [])。pauseAdRequests = 1;物品
<html>
<head>
<title>Your site title</title>
</head>
<body>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
// Initially pause adsbygoogle (wait for consent to unpause)
(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=1;
</script>
<script>
( function() {
// Run this in an interval (every 0.1s) just in case we are still waiting for consent
var cnt = 0;
var consentSetInterval = setInterval(function(){
cnt += 1;
// Bail if we have not gotten a consent response after 60 seconds.
if( cnt === 600 )
clearInterval(consentSetInterval);
if( typeof window.__tcfapi !== 'undefined' ) { // Check if window.__tcfapi has been set
clearInterval( consentSetInterval );
window.__tcfapi( 'addEventListener',function( tcData,listenerSuccess ) {
if ( listenerSuccess ) {
if( tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete' ) {
if ( ! tcData.gdprApplies ) {
// GDPR DOES NOT APPLY,UnpauseAdRequests
// Set request non-personalized ads to false as GDPR does not apply.
(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=0;
// Unpause ads,as GDPR does not apply.
(adsbygoogle = window.adsbygoogle || []).pauseAdRequests=0;
}
else {
// GDPR DOES APPLY
// Purpose 1 refers to the storage and/or access of information on a device.
var hasDeviceStorageAndAccessConsent = tcData.purpose.consents[1] || false;
// Google Requires Consent for Purpose 1
if (hasDeviceStorageAndAccessConsent) {
// GLOBAL VENDOR LIST - https://iabeurope.eu/vendor-list-tcf-v2-0/
// CHECK FOR GOOGLE ADVERTISING PRODUCTS CONSENT. (IAB Vendor ID 755)
var hasGoogleAdvertisingProductsConsent = tcData.vendor.consents[755] || false;
// Check if the user gave Google Advertising Products consent (iab vendor 755)
if(hasGoogleAdvertisingProductsConsent) {
var hasPersonalizedProfileConsent = tcData.purpose.consents[3] || false;
var hasPersonalizedAdsConsent = tcData.purpose.consents[4] || false;
// Check if have add personalization consent Purpose 3 and 4
if( hasPersonalizedAdsConsent && hasPersonalizedProfileConsent ) {
// Set request non-personalized ads to false.
(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=0;
}
else {
// Set request non-personalized ads to true.
(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=1;
}
// Unpause ads,the user has granted consent for purpose 1 and given google consent.
(adsbygoogle = window.adsbygoogle || []).pauseAdRequests=0;
}
}
}
}
}
} );
}
cnt++;
},100);
})();
</script>
<!-- One test unit for GDPR -->
<ins class="adsbygoogle"
style="display:inline-block;width:970px;height:250px"
data-ad-client="ca-pubxxx"
data-ad-slot="slot_id">
</ins>
<!-- Another test unit for GDPR -->
<ins class="adsbygoogle"
style="display:inline-block;width:250px;height:250px"
data-ad-client="ca-pubxxx"
data-ad-slot="slot_id">
</ins>
<script>
// This will trigger the ad request if ads were unpaused in the CMP consent check above.
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</body>
</html>
,
IMO,如果您想遵循 Quantcast Choice 和 Google Adsense 的官方说明,方法如下:
将所有这些添加到您的 <head>
标签中:
google adsense
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
//pause all ad requests until further notice
(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=1;
(adsbygoogle=window.adsbygoogle||[]).push({
google_ad_client: "ca-pub-XXXXXXXXXXXXXXXX",enable_page_level_ads: true
});
</script>
针对 TCF 2.0 的 quantcast 选择 CMT
<script>
(function() {
var host = window.location.hostname;
var element = document.createElement('script');
var firstScript = document.getElementsByTagName('script')[0];
var url = 'https://quantcast.mgr.consensu.org'
.concat('/choice/',YOUR_QUANTCAST_ID_HERE,'/',host,'/choice.js')
var uspTries = 0;
var uspTriesLimit = 3;
element.async = true;
element.type = 'text/javascript';
element.src = url;
firstScript.parentNode.insertBefore(element,firstScript);
function makeStub() {
var TCF_LOCATOR_NAME = '__tcfapiLocator';
var queue = [];
var win = window;
var cmpFrame;
function addFrame() {
var doc = win.document;
var otherCMP = !!(win.frames[TCF_LOCATOR_NAME]);
if(!otherCMP) {
if(doc.body) {
var iframe = doc.createElement('iframe');
iframe.style.cssText = 'display:none';
iframe.name = TCF_LOCATOR_NAME;
doc.body.appendChild(iframe);
} else {
setTimeout(addFrame,5);
}
}
return !otherCMP;
}
function tcfAPIHandler() {
var gdprApplies;
var args = arguments;
if(!args.length) {
return queue;
} else if(args[0] === 'setGdprApplies') {
if(
args.length > 3 &&
args[2] === 2 &&
typeof args[3] === 'boolean'
) {
gdprApplies = args[3];
if(typeof args[2] === 'function') {
args[2]('set',true);
}
}
} else if(args[0] === 'ping') {
var retr = {
gdprApplies: gdprApplies,cmpLoaded: false,cmpStatus: 'stub'
};
if(typeof args[2] === 'function') {
args[2](retr);
}
} else {
queue.push(args);
}
}
function postMessageEventHandler(event) {
var msgIsString = typeof event.data === 'string';
var json = {};
try {
if(msgIsString) {
json = JSON.parse(event.data);
} else {
json = event.data;
}
} catch (ignore) {}
var payload = json.__tcfapiCall;
if(payload) {
window.__tcfapi(
payload.command,payload.version,function(retValue,success) {
var returnMsg = {
__tcfapiReturn: {
returnValue: retValue,success: success,callId: payload.callId
}
};
if(msgIsString) {
returnMsg = JSON.stringify(returnMsg);
}
event.source.postMessage(returnMsg,'*');
},payload.parameter
);
}
}
while (win) {
try {
if(win.frames[TCF_LOCATOR_NAME]) {
cmpFrame = win;
break;
}
} catch (ignore) {}
if(win === window.top) {
break;
}
win = win.parent;
}
if(!cmpFrame) {
addFrame();
win.__tcfapi = tcfAPIHandler;
win.addEventListener('message',postMessageEventHandler,false);
}
};
makeStub();
var uspStubFunction = function() {
var arg = arguments;
if(typeof window.__uspapi !== uspStubFunction) {
setTimeout(function() {
if(typeof window.__uspapi !== 'undefined') {
window.__uspapi.apply(window.__uspapi,arg);
}
},500);
}
};
var checkIfUspIsReady = function() {
uspTries++;
if(window.__uspapi === uspStubFunction && uspTries < uspTriesLimit) {
console.warn('USP is not accessible');
} else {
clearInterval(uspInterval);
}
};
if(typeof window.__uspapi === 'undefined') {
window.__uspapi = uspStubFunction;
var uspInterval = setInterval(checkIfUspIsReady,6000);
}
})();
</script>
TCF 2.0 API 监听器
<script>
window.__tcfapi('addEventListener',listenerSuccess) {
if(listenerSuccess) {
//check the eventstatus
if(tcData.eventStatus === 'useractioncomplete' || tcData.eventStatus === 'tcloaded') {
if(!tcData.gdprApplies) {
//GDPR does not apply to this user,load ads immediately
(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=0;
return;
}
//deal with parsing tcData for IAB Vendor consents
//deal with personalized/non-personalized Google ads
if((tcData.vendor.consents[755] || tcData.vendor.legitimateInterests[755]) && (tcData.purpose.consents[1] && tcData.purpose.consents[3] && tcData.purpose.consents[4] && tcData.purpose.legitimateInterests[2] && tcData.purpose.legitimateInterests[7] && tcData.purpose.legitimateInterests[9] && tcData.purpose.legitimateInterests[10])) {
//consent signals sufficient for personalized ads
//set personalized ads and unpause loading process
(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=0;
} else if((tcData.vendor.consents[755] || tcData.vendor.legitimateInterests[755]) && (tcData.purpose.consents[1] && tcData.purpose.legitimateInterests[2] && tcData.purpose.legitimateInterests[7] && tcData.purpose.legitimateInterests[9] && tcData.purpose.legitimateInterests[10])) {
//consent signals NOT sufficient for personalized ads
//set non-personalized ads and unpause loading process
(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=1;
}
(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=0;
}
}
});
</script>
,
感谢您的摘录。
有一个奇怪的问题。 在Chrome上,当我针对“选择基本广告”的合法利益目的提出异议时,重新加载页面时我仍然有广告。 在Firefox上,广告没有展示。
您有同样的问题吗?我找不到解决方法