tldraw/hooks/useGtag.ts

20 lines
468 B
TypeScript
Raw Normal View History

2021-06-19 09:00:44 +00:00
import router from 'next/router'
import { useEffect } from 'react'
import * as gtag from 'utils/gtag'
export default function useGtag() {
useEffect(() => {
if (process.env.NODE_ENV !== 'production') return
function handleRouteChange(url: URL) {
gtag.pageview(url)
}
router.events.on('routeChangeComplete', handleRouteChange)
return () => {
router.events.off('routeChangeComplete', handleRouteChange)
}
}, [router.events])
}