我选择了Quantcast选项作为我的网站的同意管理平台。然而,有了谷歌的基本解决方案,在访问者同意相关供应商(谷歌)之前,广告仍然会被提供给访问者。从2天起,有一个广告在广告中确认这一问题,并在90天的宽限期后,将不再提供广告。错误消息:"2.1a:由于CMP状态是存根、加载或错误,标记或SDK没有接收TC字符串。“
我对脚本一点也不熟悉,但似乎我不得不使用一些脚本来使Quantcast选项真正发挥作用。基本上我需要知道如何:
到目前为止我学到的东西:
在访问者同意之前,我可以将此脚本添加到我的Google Adsense代码中,以避免显示任何广告:
<script>(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=1;</script>到目前为止没问题。然而,我应该能够知道,如果一个访问者已经同意的供应商谷歌。Google在TCFv2.0中的供应商ID是755。我在一个Quantcast页面上发现了以下代码和文本的混合,但我不知道如何使用它。我应该把这个放在我的网页上的Quantcast选择脚本或.?(资料来源见下文)
{{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但是我怎么做这些“电话”呢?
所以我想我理解接下来的步骤,只是我不知道如何实现这些步骤并将这些点连接起来。任何帮助都将不胜感激!
我用过的资料来源:
一个似乎做了我想要实现的事情的网站的例子: carscoops.com
发布于 2020-09-18 07:52:37
我建议一个简单得多的解决方案。使用TCF2.0,您不必手动配置Adsense参数(个性化广告等)。基于给定的同意。您只需保证,您开始加载广告后,同意是成功加载。Adsense库自动读取同意字符串,并根据给定的同意显示广告。
将Quantcast选项与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>发布于 2020-08-17 17:04:53
为了帮助大家理解,2.1a Google v2 很可能是由于谷歌在设置/建立用户同意之前将产品标签添加到网站上而引起的。这是一个简短的视频,显示了预期的行为,在用户同意后才会加载广告。如果在用户选择同意之前,您在后台看到了加载广告,那么您将得到2.1a错误,因为您正在添加Google标记,而无需等待同意。
这一解决方案将有所不同,这取决于你是如何添加谷歌广告产品标签到您的网站,但希望下面的信息和广告的例子帮助。
Google标记管理器
如果您正在使用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 OptionTCFv2.0的适当同意信号。
我没有机会充分测试这一点,所以请告诉我,如果你对代码有任何问题,我会更新这个例子。
,请参阅下面的代码块,以获得更新的VERIONS
<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', 2, 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>
编辑:新增更新版本(8月18日)
这可能是一个比上面更好的版本。这是再次未经测试,所以请测试和反馈,如果你有问题。这一更新版本的主要区别是:
<html>
<head>
<title>Your site title</title>
</head>
<body>
<script>
( function() {
var insertAdsByGoogleJs = function() {
var element = document.createElement('script');
var firstScript = document.getElementsByTagName('script')[0];
var url = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js";
element.async = true;
element.type = 'text/javascript';
element.src = url;
firstScript.parentNode.insertBefore(element, firstScript);
};
// 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', 2, function( tcData,listenerSuccess ) {
if ( listenerSuccess ) {
if( tcData.eventStatus === 'tcloaded' || tcData.eventStatus === 'useractioncomplete' ) {
if ( ! tcData.gdprApplies ) {
// GDPR DOES NOT APPLY
// Insert adsbygoogle.js onto the page.
insertAdsByGoogleJs();
}
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) {
// Insert adsbygoogle.js onto the page.
insertAdsByGoogleJs();
}
}
}
}
}
} );
}
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>发布于 2021-02-19 13:49:25
海事组织,如果你想遵循Quantcast抉择和谷歌广告的官方指示,这就是方法:
将所有这些添加到<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>quantcast为TCF2.0选择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>TCF2.0API侦听器
<script>
window.__tcfapi('addEventListener', 2, function(tcData, 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>https://stackoverflow.com/questions/63440572
复制相似问题