如何使用 Quantcast Choice 根据 IAB TCF v2.0 的同意显示或阻止个性化 Adsense 广告?

Sta*_*tan 6 javascript adsense gdprconsentform

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

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

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

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

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

<script>(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=1;</script>
Run Code Online (Sandbox Code Playgroud)

到目前为止没有问题。但是,我应该能够知道访问者是否同意供应商 Google。TCF v2.0 中 Google 的供应商 ID 是 755。我在 Quantcast 页面之一上发现了以下代码和文本的混合,但我不知道如何使用它。我应该把它放在 Quantcast Choice 脚本中的网页上还是……?(来源链接如下)

{{QC - __cmpConsents.iabVendorConsentIds}} matches the regular expression (^|,)755(,|$).
Run Code Online (Sandbox Code Playgroud)

因此,如果找到 ID 755,我应该致电:

(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=0
Run Code Online (Sandbox Code Playgroud)

如果没有找到 ID 755,我应该打电话:

(adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=1
(adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=0
Run Code Online (Sandbox Code Playgroud)

但是我怎么做这些“电话”呢?

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

我使用过的来源:

一个网站的例子似乎可以实现我想要实现的目标:carscoops.com

Rya*_*ron 3

为了帮助大家理解,2.1a Google IAB TCF v2 错误很可能是由于在设置/建立用户同意之前将 Google 广告产品标签添加到网站而引起的。这是一段简短的视频,显示了预期的行为,广告只有在用户同意后才会加载。如果您在用户选择同意之前看到广告在后台加载,那么您会收到 2.1a 错误,因为您在没有等待同意的情况下添加了 Google 标签。

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

谷歌标签管理器

如果您使用 Google 跟踪代码管理器将 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>
Run Code Online (Sandbox Code Playgroud)

编辑:添加了新的更新版本(8 月 18 日)


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

  2. 在获得同意之前,我们不会将https://pagead2.googlesynmination.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>
Run Code Online (Sandbox Code Playgroud)