fix: send url to gtm.pageview (#21747)
`gtm.pageview` was called without sending an actual URL, while it is required here:
36aeca8f04/examples/with-google-tag-manager/lib/gtm.js (L3-L6)
This commit is contained in:
parent
4cadb68dfe
commit
e750f4378c
1 changed files with 2 additions and 6 deletions
|
@ -2,17 +2,13 @@ import { useEffect } from 'react'
|
|||
import { useRouter } from 'next/router'
|
||||
import * as gtm from '../lib/gtm'
|
||||
|
||||
const handleRouteChange = () => {
|
||||
gtm.pageview()
|
||||
}
|
||||
|
||||
const GoogleTagManager = ({ children }) => {
|
||||
const router = useRouter()
|
||||
|
||||
useEffect(() => {
|
||||
router.events.on('routeChangeComplete', handleRouteChange)
|
||||
router.events.on('routeChangeComplete', gtm.pageview)
|
||||
return () => {
|
||||
router.events.off('routeChangeComplete', handleRouteChange)
|
||||
router.events.off('routeChangeComplete', gtm.pageview)
|
||||
}
|
||||
}, [router.events])
|
||||
|
||||
|
|
Loading…
Reference in a new issue