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

useGtm() is randomly undefined #14

Open realconvis opened 9 months ago

realconvis commented 9 months 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 9 months 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 9 months ago

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

MooseSaeed commented 9 months ago

I got the same issue.

bibirock commented 8 months ago

I got the same issue. nuxt version: 3.2.3

marcel-wtfoxtrot commented 6 months ago

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

filiphazardous commented 5 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