zadigetvoltaire / nuxt-gtm

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

Can I manually init GTM? #31

Open DmytroIvantsov opened 6 months ago

DmytroIvantsov commented 6 months ago

Can I manually init GTM? For example, init GTM if the user has allowed this in the cookie settings

devonik commented 6 months ago

Thats a very good request. I didnt found a way to do it with this plugin. So I switched to the under the hood vue plugin vue-gtm.

import { type VueGtmUseOptions, createGtm } from '@gtm-support/vue-gtm' The createGtm you can call to initialise the instance

Would be awesome when the author can put here his aproach when its possible with this library

DmytroIvantsov commented 6 months ago

I solved this issue in the following way:

set enabled: false by default: gtm: { ... enabled: false, ... }

manually make it active when needed:

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

devonik commented 6 months ago

Nice! And what is gtm in ?

gtm.enable(true); config.public.gtm.enable(true) ?

DmytroIvantsov commented 6 months ago

const gtm = useGtm();

this is a variable provided by the @zadigetvoltaire/nuxt-gtm module

nuxt-config.ts

modules: [
    ...
    "@zadigetvoltaire/nuxt-gtm",
    ...
  ]