zadigetvoltaire / nuxt-gtm

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

useGtm() is randomly undefined #14

Open realconvis opened 1 year ago

realconvis commented 1 year ago

The GTM snippet is always loaded and the TrackView Event via router sync is always fired.

But I have the problem, that useGtm() inside vue components is randomly undefined.

If I stop and start the development server (npm run dev) several times or clear the cache (npx nuxi cleanup), it eventually works again. When I then restart the development server again later, it doesn't work again.

What could be the problem.

realconvis commented 1 year ago

Now I've figured out how to reproduce the error explicitly. The error occurs whenever I run the "npx nuxi cleanup" command before the "npx nuxi dev". If I then stop and start the dev server without running the cleanup first, useGtm() is no longer undefined. Only when I run the cleanup again and start the dev server for the first time, useGtm() is undefined again. What could be the reason for this?

FilipEIG commented 1 year ago

Having same issue. Appears to be an issue only in dev environment though.

MooseSaeed commented 1 year ago

I got the same issue.

bibirock commented 1 year ago

I got the same issue. nuxt version: 3.2.3

marcel-wtfoxtrot commented 10 months ago

Same here with Nuxt 3.9. Any way to resovle this?

filiphazardous commented 10 months ago

It seems Vite does something unexpected when minifying code. (For me, it copied the useGtm function instead of importing it, but useGtm was relying on a locally scoped variable.) This PR upstream attempts to solve the problem: https://github.com/gtm-support/vue-gtm/pull/409