nuxt-community / gtm-module

Google Tag Manager Module for Nuxt.js
MIT License
326 stars 69 forks source link

Setting data-cookieconsent to ignore #81

Open markbok opened 3 years ago

markbok commented 3 years ago

Hi there,

I'm trying to use Cookiebot on my site along with your plugin.

In order to successfully use Cookiebot with Google Tag Manager, the data-cookieconsent value needs to be set to ignore on the GTM script. Is there a way to set this on your plugin? And if not, can you think of an alternative way to set it within Nuxt?

Many thanks,

Mark

antonioperez commented 3 years ago

@markbok I was able to add the data-cookieconsent data attribute to the GTM script tag by creating a Nuxt plugin.

// plugins/gtm.js
export default function({ app, beforeNuxtRender }) {

    if (process.server) {
        beforeNuxtRender(() => {
            const gtmScript = app.head.script.find(s => s.hid == 'gtm-script');
            gtmScript['data-cookieconsent'] = 'ignore';
        });
    }
}
// Add to plugins array
{ src: '~/plugins/gtm' }
Screen Shot 2021-01-14 at 6 23 15 PM