gtm-support / vue-gtm

Simple implementation of Google Tag Manager for Vue
https://www.npmjs.com/package/@gtm-support/vue-gtm
MIT License
198 stars 23 forks source link

SSR support? #357

Open yooouuri opened 1 year ago

yooouuri commented 1 year ago

Request / Idea

Inject the needed scripts (in the head and body tag) in SSR, so the server wil render the tags.

Additional Context

Use https://github.com/vueuse/head to inject script to the head tag.

Of course this needs some work in the frontend, because you have to get the injected head and merge with your index.html, see: https://github.com/vueuse/head#ssr-rendering

There seems no plugin available to inject stuff into the body, as Evan You states: You should not teleport an element to the body because SSR don't know how to hydrate it. Maybe exposing a function, returning the code to add to the body, and implement it in the SSR implementation live mentioned in the vueuse link.

Im going to need this, so expect a PR soon!