johannschopplich / nuxt-gtag

🔸 Google Analytics & Ads integration made easy
https://developers.google.com/tag-platform/gtagjs
MIT License
302 stars 9 forks source link

Automatic `page_view` events on router change #37

Closed marchantweb closed 10 months ago

marchantweb commented 10 months ago

Describe the feature

Hey!

Are you open to the idea of calling useTrackEvent('page_view') (perhaps with route metadata) automatically on route change?

I'm thinking it's optional, disabled by default but you can opt-in via nuxt.config. This would have the module act a little more like a typical GA site tracker, where every page view is tracked automatically.

If this makes sense for the module, I can submit a PR. Thoughts?

P.S. Happy New Year

Additional information

Final checks

johannschopplich commented 10 months ago

Great idea! PR happily welcome. 🙂

I'm not sure if a Nuxt hook is the best choice of just using the useRouter().afterEach method. Maybe you can look into that. Thanks in advance.

Dito, happy New Year to you too.

notflip commented 10 months ago

Isn’t page tracking done by default already with the default setup (before this PR?)

johannschopplich commented 10 months ago

@notflip Correct. See the PR discussion: https://github.com/johannschopplich/nuxt-gtag/pull/38#issuecomment-1874356691

Closing this for now, since enhanced management will already watch for history state changes, which should cover most use cases. Kudos to @marchantweb for the PR tho!