I am a Software Engineer and Developer Advocate who loves sharing knowledge via writing, videos, mentorship, and working out. Please Subscribe: https://www.youtube.com/channel/UCcz5Bvr4kGHPFAjvnRhIQ4g
I just tested and it does not register pageviews on all navigation changes, just the initial load. You may have a "history change trigger" set up in Google Tag Manager. That will register a pageview on all history changes. But without that, just adding the GA code to <Head> will not register pageviews on navigation. This is because nextjs doesn't reload the page, it just does a prop update and lets React re-render as it needs to. To get pageviews on navigation changes, you need to do something like listen for the routeChangeComplete nextjs router event and push a pageview when it triggers.
Also, to be clear, nextjs will do a refresh if you use a plain <a> for links, instead of using next/link. So this issue only applies to next/link clicks or pushing onto the router.
I am a Software Engineer and Developer Advocate who loves sharing knowledge via writing, videos, mentorship, and working out. Please Subscribe: https://www.youtube.com/channel/UCcz5Bvr4kGHPFAjvnRhIQ4g
I wouldn’t be too sure but I think it does because from the report on my dashboard, it shows visits to individual pages
I just tested and it does not register pageviews on all navigation changes, just the initial load. You may have a "history change trigger" set up in Google Tag Manager. That will register a pageview on all history changes. But without that, just adding the GA code to
<Head>
will not register pageviews on navigation. This is because nextjs doesn't reload the page, it just does a prop update and lets React re-render as it needs to. To get pageviews on navigation changes, you need to do something like listen for therouteChangeComplete
nextjs router event and push a pageview when it triggers.Also, to be clear, nextjs will do a refresh if you use a plain
<a>
for links, instead of usingnext/link
. So this issue only applies tonext/link
clicks or pushing onto the router.Thank you for this update.
I will check it out