How To Set Up Google AdSense Consent Mode (Advanced)

How Set Up Google AdSense Consent Mode (Advanced)Google Consent Mode allows you to adjust how Google tags behave based on the consent status

How Set Up Google AdSense Consent Mode (Advanced)


How To Set Up Google AdSense Consent Mode (Advanced)

Set Up Google AdSense Consent Mode 

in this article we will talk about Setting up Google AdSense Consent Mode is an advanced way to manage cookie consent for GDPR and CPRA compliance. 

This ensures that your Google Ads (including AdSense) are only triggered after the user has given consent. 

Here’s how you can set this up on your Blogger site:


How To Integrate Google Consent Mode

Google Consent Mode allows you to adjust how Google tags behave based on the consent status of your users. 

You will need to add the `gtag.js` library to your site.


How To Add the Global Site Tag (gtag.js)

  1.    - Go to your Blogger dashboard.
  2.    - Navigate to **Theme** > **Edit HTML**.
  3.    - Add the following script in the `<head>` section of your template, ideally just before the closing `</head>` tag:


```html

<script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_GA_MEASUREMENT_ID"></script>

<script>

  window.dataLayer = window.dataLayer || [];

  function gtag(){dataLayer.push(arguments);}

  gtag('consent', 'default', {

    'ad_storage': 'denied',

    'analytics_storage': 'denied'

  });

  gtag('js', new Date());


  gtag('config', 'YOUR_GA_MEASUREMENT_ID');

</script>

```


Replace `YOUR_GA_MEASUREMENT_ID` with your actual Google Analytics Measurement ID.


Modify Consent Preferences Based on User Input

After loading the page, you need to set consent preferences based on the user's choice (e.g., when they accept or decline cookies via the consent banner).


How To Add the Consent Management Script

Add the following script to handle consent updates:


```html

<script>

  function handleConsentUpdate(consentStatus) {

    gtag('consent', 'update', {

      'ad_storage': consentStatus,

      'analytics_storage': consentStatus

    });

  }


  // Example of how you might call this when the user gives consent

  document.getElementById('acceptCookies').onclick = function() {

    handleConsentUpdate('granted');

  };


  document.getElementById('rejectCookies').onclick = function() {

    handleConsentUpdate('denied');

  };

</script>

```


Note:You'll need to connect these actions with the actual consent buttons on your cookie consent banner.


Include the AdSense Code

Finally, ensure that your AdSense ads are only served if the user has granted consent.


```html

<script>

  if (consentStatus === 'granted') {

    (adsbygoogle = window.adsbygoogle || []).push({});

  }

</script>


<!-- Replace this with your actual AdSense code -->

<ins class="adsbygoogle"

     style="display:block"

     data-ad-client="ca-pub-XXXXX"

     data-ad-slot="XXXXXXX"></ins>

```


Testing and Deployment

Preview Changes:

Before publishing, preview the site to ensure everything is working correctly. 

Check that ads only display after consent is granted.


Publish Changes:

Once confirmed, save your template changes and publish them.


Monitor and Adjust

Regularly Review:

Monitor your site to ensure compliance and make adjustments as needed for any changes in privacy laws or Google policies.


Conclusion

With this setup, your Google AdSense ads will respect user consent, ensuring compliance with GDPR and CPRA. 

You’re also laying the groundwork for a more privacy-conscious user experience, which is increasingly important in today’s regulatory environment.

Copy Scripts to Clipboard

Script 1: Global Site Tag (gtag.js)

Script 2: Consent Management Script

Seo Tools Apps Welcome to WhatsApp chat
How can we help you?
Type here...