tldraw/www/utils/useGtag.ts
Steve Ruiz b68a4681e1
[improvement] repo shuffle (#214)
* move folders out of packages

* Remove custom yarn stuff, remove duplicate readme

* Remove stitches config

* Add README script.

* bump deps

* Fix script

* Update package.json
2021-11-02 11:46:25 +00:00

20 lines
514 B
TypeScript

/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import router from 'next/router'
import { useEffect } from 'react'
import * as gtag from 'utils/gtag'
function handleRouteChange(url: URL) {
gtag.pageview(url)
}
export default function useGtag() {
useEffect(() => {
if (process.env.NODE_ENV !== 'production') return
router.events.on('routeChangeComplete', handleRouteChange)
return () => {
router.events.off('routeChangeComplete', handleRouteChange)
}
}, [])
}