-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy path_app.tsx
47 lines (40 loc) · 1.12 KB
/
_app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { AppProps } from "next/app"
import { Roboto_Flex, Roboto_Mono } from "next/font/google"
import { useRouter } from "next/router"
import { useEffect } from "react"
import "@/globals.css"
import "@/codemirror.less"
const robotoFlex = Roboto_Flex({
subsets: ["latin"],
})
const robotoMono = Roboto_Mono({
subsets: ["latin"],
})
const gaId = process.env.NEXT_PUBLIC_GA_ID
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
function handleRouteChange(url: string) {
;(window as any).gtag("config", gaId, { page_path: url })
}
export default function App({ Component, pageProps }: AppProps) {
const router = useRouter()
useEffect(() => {
if (!gaId) return
router.events.on("routeChangeComplete", handleRouteChange)
return () => {
router.events.off("routeChangeComplete", handleRouteChange)
}
}, [])
return (
<>
<style jsx global>{`
html {
font-family: ${robotoFlex.style.fontFamily};
}
.roboto-mono {
font-family: ${robotoMono.style.fontFamily};
}
`}</style>
<Component {...pageProps} />
</>
)
}