nuxt-community / gtm-module

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

Support for Nuxt 3 #152

Open thoth3x opened 2 years ago

thoth3x commented 2 years ago

Hi,

It seems this plugin doesn't work on Nuxt 3 (v3.0.0-rc.1)

When I run npm run dev it says Cannot start nuxt: Invalid Version: null

Screenshot 2022-05-11 at 15 57 27

My nuxt.config.ts:

Screenshot 2022-05-11 at 15 58 42

Is there any workaround for that or do you planning on updating the plugin to work with Nuxt 3?

Thanks!

copostic commented 2 years ago

Would be very appreciated indeed. Any alternative until the release of a compatible version ?

acidjazz commented 1 year ago

@copostic

import { createGtm } from '@gtm-support/vue-gtm'

export default defineNuxtPlugin((nuxtApp) => {
  if (useRuntimeConfig().public.appEnv !== 'production') return
  nuxtApp.vueApp.use(createGtm({
    id: 'GTM-???????',
    defer: false,
    compatibility: false,
    enabled: true,
    debug: true,
    loadScript: true,
    vueRouter: useRouter(),
    trackOnNextTick: false,
  }))
})
copostic commented 1 year ago

Amazing, thanks @acidjazz I wasn't expecting anything anymore from this thread but what a great surprise on this monday morning !

Have a nice day 🌞

acidjazz commented 1 year ago

Amazing, thanks @acidjazz I wasn't expecting anything anymore from this thread but what a great surprise on this monday morning !

Have a nice day 🌞

no problem! make sure its client only: /plugins/gtm.client.ts

anton-reviakin commented 1 year ago

@copostic

import { createGtm } from '@gtm-support/vue-gtm'

export default defineNuxtPlugin((nuxtApp) => {
  if (useRuntimeConfig().public.appEnv !== 'production') return
  nuxtApp.vueApp.use(createGtm({
    id: 'GTM-???????',
    defer: false,
    compatibility: false,
    enabled: true,
    debug: true,
    loadScript: true,
    vueRouter: useRouter(),
    trackOnNextTick: false,
  }))
})

After install @gtm-support/vue-gtm I see request to https://vk.com/js/api/openapi.js?169 and https://connect.facebook.net/en_US/fbevents.js

niklasfjeldberg commented 1 year ago

Are anyone working on this?

acidjazz commented 1 year ago

@niklasfjeldberg https://github.com/johannschopplich/nuxt-gtag

iustin-gheorghe commented 1 year ago

@acidjazz nuxt-gtag seems to be a GA4 library for Nuxt, not GTM one.

acidjazz commented 1 year ago

@acidjazz nuxt-gtag seems to be a GA4 library for Nuxt, not GTM one.

nope, it's GTM. using it now w/ my tag on multiple setups.

GuillaumeDgr commented 11 months ago

@acidjazz nuxt-gtag seems to be a GA4 library for Nuxt, not GTM one.

nope, it's GTM. using it now w/ my tag on multiple setups.

Hi, could you pls provide an example how you are using GTM and GA4 tags in the same time ? Many thanks

memic84 commented 8 months ago

@copostic

import { createGtm } from '@gtm-support/vue-gtm'

export default defineNuxtPlugin((nuxtApp) => {
  if (useRuntimeConfig().public.appEnv !== 'production') return
  nuxtApp.vueApp.use(createGtm({
    id: 'GTM-???????',
    defer: false,
    compatibility: false,
    enabled: true,
    debug: true,
    loadScript: true,
    vueRouter: useRouter(),
    trackOnNextTick: false,
  }))
})

We have been using this implementation, but the vue-gtm seems only to add the script in the body, en not in the head. Data is received, but not everything is working correctly in GTM. Seems that the script needs to be added to the head as well. Anybody else had this before?

nodeexcel commented 6 months ago

modules: [ '@zadigetvoltaire/nuxt-gtm' ], gtm: { id: 'GTM-ID', enabled: true, debug: false, },

it's working fine

joeczucha commented 5 months ago

@acidjazz nuxt-gtag seems to be a GA4 library for Nuxt, not GTM one.

nope, it's GTM. using it now w/ my tag on multiple setups.

Are you sure it's GTM? Just checking as this suggests otherwise: https://github.com/johannschopplich/nuxt-gtag/issues/13

NikhilVerma commented 4 months ago

I have made a drop in replacement for this module - https://www.npmjs.com/package/gtm-nuxt3