diff --git a/lib/utils.ts b/lib/utils.ts index 74b729962..f8381747b 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -7,7 +7,6 @@ import remarkPrism from "remark-prism"; import autolink from "remark-autolink-headings"; import GitHubSlugger from "github-slugger"; import imgLinks from "@pondorasti/remark-img-links"; -import semverCompare from "semver-compare"; import { getHaystackReleaseTagNames, getStargazersCount } from "./github"; import { MDXRemoteSerializeResult } from "next-mdx-remote"; diff --git a/pages/_app.tsx b/pages/_app.tsx index 0b3a67060..53434acf8 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -2,7 +2,31 @@ import "../styles/global.css"; import "../styles/prism-theme.css"; import type { AppProps } from "next/app"; +import { useEffect } from 'react' +import { useRouter } from 'next/router' + +declare const window: any; + function MyApp({ Component, pageProps }: AppProps) { + const router = useRouter() + + useEffect(() => { + const handleRouteChange = (url: any) => { + window.gtag('config', process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS, { + page_path: url, + }); + } + //When the component is mounted, subscribe to router changes + //and log those page views + router.events.on('routeChangeComplete', handleRouteChange) + + // If the component is unmounted, unsubscribe + // from the event with the `off` method + return () => { + router.events.off('routeChangeComplete', handleRouteChange) + } + }, [router.events]) + return ; } export default MyApp; diff --git a/pages/_document.tsx b/pages/_document.tsx index 5820bec6a..88014b2b4 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -15,7 +15,24 @@ class MyDocument extends Document { render() { return ( - + +