johannschopplich / nuxt-gtag

🔸 Google Tag integration for Nuxt: Google Analytics, Google Ads and more

Home Page:https://developers.google.com/tag-platform/gtagjs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automatic `page_view` events on router change

marchantweb opened this issue · comments

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

  • Would you be willing to help implement this feature?
  • Can you think of other implementations of this feature?

Final checks

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.

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

@notflip Correct. See the PR discussion: #38 (comment)

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!