Info
Content

Enabling/disabling personalized ads with Google GPT, DFP or Google AdSense

If you are using Google GPT, DFP or Google AdSense, please see the following URL for further information how to stop the AdServer from requesting ads:

https://support.google.com/dfp_premium/answer/7678538?hl=en&ref_topic=9007190

In order to get notified when consent is given, you can use Events (see above). Here is a sample code how an integration with DFP can look like:

...
<body>
  ... CMP CODE ....
  <script> 
    function fireGoogle() 
    {  
      __cmp('getVendorConsents',null,function (x,y)  
       {   
        if(x.purposeConsents && x.purposeConsents[1] && x.purposeConsents[3]) //consent for prupose 1 + 3 exists?   
        {    
          googletag.pubads().setRequestNonPersonalizedAds(1);   
        }   
        else   
        {    
          googletag.pubads().setRequestNonPersonalizedAds(0);   
        }   
        googletag.pubads().refresh();  
      }); 
    } 
    __cmp("addEventListener",["consent",fireGoogle,false],null); //define event in order to get notification when consent data is ready
  </script>
  <script src="//www.googletagservices.com/tag/js/gpt.js"> 
    //... other DFP settings ... 
    googletag.pubads().disableInitialLoad(); //PAUSE calls to DFP 
    //... other DFP settings ...
  </script>
  ...

 

Here is an example how an integration with Google AdSense can look like:

...
<body>
  ... CMP CODE ....
  <script>  
    (adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=1;  
    function fireGoogleAdSense() 
    {  
      __cmp('getVendorConsents',null,function (x,y)  
       {   
        if(x.purposeConsents && x.purposeConsents[1] && x.purposeConsents[3]) //consent for prupose 1 + 3 exists?   
        {    
          (adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=0;   
        }   
        else   
        {    
          (adsbygoogle=window.adsbygoogle||[]).requestNonPersonalizedAds=1;   
        }   
        (adsbygoogle=window.adsbygoogle||[]).pauseAdRequests=0;   
        (adsbygoogle = window.adsbygoogle || []).push({});  
      }); 
    } 
    __cmp("addEventListener",["consent",fireGoogle,false],null); //define event in order to get notification when consent data is ready
  </script>
  <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
  <ins class="adsbygoogle"     style="display:inline-block;width:120px;height:600px"     data-ad-client="ca-pub-..."     data-ad-slot="..."></ins>
  <script>(adsbygoogle = window.adsbygoogle || []).push({});</script>
  ...
Back to top