nuxt-community / google-analytics-module

Google Analytics Module for Nuxt 2
https://google-analytics.nuxtjs.org/
MIT License
638 stars 54 forks source link

Use on SSR #15

Closed metalanti closed 6 years ago

metalanti commented 6 years ago

can I use this module during SSR? how can I trigger GA events from the server side? eg: set the userId, or addImpression for ecommerce on a list of products. or where should I take those codes? :) thanks

This question is available on Nuxt.js community (#c14)
MatteoGabriele commented 6 years ago

Hi @metalanti You cannot trigger any Google Analytics events if the client is not ready. You still need to wait for javascript to kick in, then you can interact with it and send events.

metalanti commented 6 years ago

Can you give me an example for that wait? I am new with nuxt

MatteoGabriele commented 6 years ago

in SSR applications you have 2 phases: the server-rendered page kicks in first, so you have that quick render of your page that makes SSR so useful ( plus SEO and other advantages ), after that phase is completed, javascript kicks in ( when fully loaded ) and so you have access to the window object, the document objects, you can do fancy animations with TweenMax and so on. (just to make few examples)

Google Analytics needs that second face to work, but you don't have to do anything: just follow the vue-analytics documentation and you should be good to go.

https://matteogabriele.gitbooks.io/vue-analytics/content

I hope I explained it decently

metalanti commented 6 years ago

OK, thank you very much I need to read the docs :D

MatteoGabriele commented 6 years ago

Yeah that's always good practice :)

nachogarcia commented 4 years ago

Is there no plan on supporting enabling this module in SSR like GTM? https://github.com/nuxt-community/gtm-module/issues/7

Is there any way I would be able to help?