-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Closed
Labels
examplesIssue was opened via the examples template.Issue was opened via the examples template.good first issueEasy to fix issues, good for newcomersEasy to fix issues, good for newcomers
Description
Bug report
Describe the bug
with-google-analytics example double counts page_views. The code
const router = useRouter()
useEffect(() => {
const handleRouteChange = (url) => {
gtag.pageview(url)
}
router.events.on('routeChangeComplete', handleRouteChange)
return () => {
router.events.off('routeChangeComplete', handleRouteChange)
}
}, [router.events])
is not necessary.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Go to with-google-analytics example and run it.
- Enable Chrome Extension: GA Debugger
- Look at Google Analytics events.
- See

Expected behavior
Page views are tracked once.
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: [e.g. macOS, Windows]
- Browser (if applies) [e.g. chrome, safari]
- Version of Next.js: [e.g. 10.0.1]
- Version of Node.js: [e.g. 12.0.0]
- Deployment: [e.g. next start, next export, Vercel, other platform]
Additional context
Add any other context about the problem here.
ulasakdeniz, frankjwu, msadakov, tarunama and zifeo
Metadata
Metadata
Assignees
Labels
examplesIssue was opened via the examples template.Issue was opened via the examples template.good first issueEasy to fix issues, good for newcomersEasy to fix issues, good for newcomers