7

我选择 Quantcast Choice 作为我网站的同意管理平台。然而,在访问者同意相关供应商 (Google) 之前,他们的基本解决方案仍会向访问者投放 Google Adsense 广告。由于 2 天后,Adsense 中会收到确认此问题的通知,并且在 90 天的宽限期后将不再提供广告。错误消息:“ 2.1a:标签或 SDK 未收到 TC 字符串,因为 CMP 状态为存根、加载或错误。

我对脚本一点也不熟悉,但似乎我必须使用一些脚本才能使 Quantcast Choice 真正起作用。基本上我需要知道如何:

  • 在访问者同意 Google 之前不投放任何 Google 广告
  • 征得同意后投放个性化广告
  • 在未经同意的情况下投放非个性化广告

到目前为止我学到了什么:

在访问者同意之前,我可以将此脚本添加到我的 Google Adsense 代码中以不显示任何广告:

<script>(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=1;</script>

到目前为止没有问题。但是,我应该能够知道访问者是否已同意供应商 Google。Google 在 TCF v2.0 中的供应商 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

但是我该如何做这些“电话”呢?

所以我想我理解要遵循的步骤,只是我不知道如何实施这些步骤并连接点。任何帮助将非常感激!

我用过的来源:

似乎可以实现我想要实现的网站示例:carscoops.com

4

3 回答 3

3

我会推荐一个非常简单的解决方案。使用 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>
于 2020-09-18T07:52:37.683 回答
2

只是为了帮助大家理解,2.1a Google IAB TCF v2 错误可能是由于在设置/建立用户同意之前将 Google Advertise Product Tags 添加到网站造成的。这是一个展示预期行为的短视频,广告在用户同意后才会加载。如果您在用户选择同意之前看到广告在后台加载,那么您会收到 2.1a 错误,因为您在未等待同意的情况下添加 Google 标记。

此问题的解决方案将根据您将 Google 广告产品标签添加到您的网站的方式而有所不同,但希望以下信息和 Adsense 示例对您有所帮助。

谷歌标签管理器

如果您使用 Google Tag Manager 将 Choice 和 Google 标签添加到您的网站,您可以使用此处的指南https://help.quantcast.com/hc/en-us/articles/360051794434https://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 的正确同意信号的方式。

我没有机会对此进行全面测试,因此如果您对代码有任何问题,请告诉我,我将更新示例。

请参阅此代码块下方的更新版本

<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 日)


这可能是比上面更好的版本。这再次未经测试,因此如果您遇到问题,请进行测试并提供反馈。此更新版本的主要区别是:
  1. 我们不再检查 tcData. purpose.consents[3] 和 tcData. purpose.consents[4] 而是依靠谷歌来决定是否显示个性化广告。

  2. 在我们同意之前,我们不会将https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js添加到页面,防止添加任何不需要的 cookie,直到我们确定我们同意这样做。这也允许我们删除 (adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=1; 项目以及

  <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>
于 2020-08-17T17:04:53.207 回答
2

IMO,如果您想遵循 Quantcast Choice 和 Google Adsense 的官方说明,方法如下:

<head>在您的标签中添加所有这些:

谷歌的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', 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>
于 2021-02-19T13:49:25.007 回答