Skip to content

Commit

Permalink
Use useRouter over Router for with-google-analytics example
Browse files Browse the repository at this point in the history
  • Loading branch information
chibicode committed Sep 4, 2020
1 parent 3c99206 commit 955e6f3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/with-google-analytics/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { useEffect } from 'react'
import Router from 'next/router'
import { useRouter } from 'next/router'
import * as gtag from '../lib/gtag'

const App = ({ Component, pageProps }) => {
const router = useRouter()
useEffect(() => {
const handleRouteChange = (url) => {
gtag.pageview(url)
}
Router.events.on('routeChangeComplete', handleRouteChange)
router.events.on('routeChangeComplete', handleRouteChange)
return () => {
Router.events.off('routeChangeComplete', handleRouteChange)
router.events.off('routeChangeComplete', handleRouteChange)
}
}, [])
}, [router.events])

return <Component {...pageProps} />
}
Expand Down

0 comments on commit 955e6f3

Please sign in to comment.