Google Ads

How to authorize and deny custom ads based on the user consent

In its last version, Google Ads ask for consent in accordance with GDPR, and it's necessary to have this consent before launching the script.

In that case, it is necessary to add this script to your page :

<script type="text/javascript">
(adsbygoogle = window.adsbygoogle || []).pauseAdRequests = 1;
(_axcb = window._axcb || []).push(function(sdk) {
  sdk.on('cookies:complete', function(choices) {
    if (!choices['Google Ads']) {   
        window.adsbygoogle.requestNonPersonalizedAds = 1;
    }
    window.adsbygoogle.pauseAdRequests = 0;
  });
});
</script>

You will need to load this script preferably in the <head> section of your site, independently of Google Ads. As soon as the user will give his consent, the Google script will go back to its usual behavior and will send the ad requests to its servers.

This script is a simple adaptation of the documentation given by Google here at the following address : https://support.google.com/adsense/answer/9042142?hl=en&ref_topic=7670012

Last updated