zadigetvoltaire / nuxt-gtm

Nuxt 3 module for Google Tag Manager
https://www.npmjs.com/package/@zadigetvoltaire/nuxt-gtm
MIT License
59 stars 3 forks source link

Enabling the plugin while application is working has no effect #16

Open bart-iimpcoll opened 9 months ago

bart-iimpcoll commented 9 months ago

Hello!

I implemented your plugin and I start the application with the plugin turned off by default. User needs to consent to cookies to enable the plugin. When I set the: config.public.gtm.enabled = true; nothing happens. The setup works if that value is true from the beginning. Any suggestion about what am I doing wrong?

My runtimeConfig:

runtimeConfig: {
    public: {
      ga_cookie: process.env.GA_COOKIE_NAME,
      gtm: {
        id: process.env.GTM_TAG,
        defer: false,
        compatibility: false,
        nonce: '2726c7f26c',
        enabled: false,
        debug: true,
        loadScript: true,
        enableRouterSync: true,
        trackOnNextTick: false,
        devtools: true,
      }
    }
  }, 
bart-iimpcoll commented 9 months ago

I made it work using this following code in my application, in one of Components (I'm using composition API):

    config.public.gtm.enabled = true;
    useGtm()?.enable(true)

it only works if both of them are included. It feels not correct though, is there a better way to achieve what I want to do?