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

The `useGtm` composable returns `undefined` on server #21

Open tibineagu opened 9 months ago

tibineagu commented 9 months ago

The original useGtm directive is returning essentially an instance of GtmSupport, which is built to handle server-side calls.

However, it will only return an object if it's been instantiated, and that only happens in the install method.

Because for your nuxt approach, you chose to only install the plugin on the client, this is breaking the server-side use of useGtm.

While i know that there is no actual utility of useGtm on the server-side, it would still be great if we didn't have to ensure all calls of gtm.* are done on the client side.

filiphazardous commented 8 months ago

We have a similar problem. In addition, it seems Vite is removing the gtm object entirely when minifying - since it isn't defined.