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:
Balázs Orbán 2021-02-03 16:28:25 +01:00 committed by GitHub
parent 4cadb68dfe
commit e750f4378c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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])