diff --git a/docs/site/.gitignore b/docs/site/.gitignore index 5b3ad33..5690274 100644 --- a/docs/site/.gitignore +++ b/docs/site/.gitignore @@ -1,2 +1,3 @@ .next/ node_modules/ +.envrc diff --git a/docs/site/lib/gtag.js b/docs/site/lib/gtag.js new file mode 100644 index 0000000..7b63539 --- /dev/null +++ b/docs/site/lib/gtag.js @@ -0,0 +1,15 @@ +export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GA_ID; + +export const pageview = (url) => { + window.gtag("config", GA_TRACKING_ID, { + page_path: url, + }); +}; + +export const event = ({ action, category, label, value }) => { + window.gtag("event", action, { + event_category: category, + event_label: label, + value: value, + }); +}; diff --git a/docs/site/pages/_app.mdx b/docs/site/pages/_app.mdx new file mode 100644 index 0000000..62720df --- /dev/null +++ b/docs/site/pages/_app.mdx @@ -0,0 +1,44 @@ +import Head from "next/head"; +import Script from 'next/script' +import { useEffect } from "react"; +import { useRouter } from "next/router"; +import * as gtag from "../lib/gtag"; + +export default function App({ Component, pageProps }) { + const router = useRouter(); + useEffect(() => { + const handleRouteChange = (url) => { + gtag.pageview(url); + }; + router.events.on("routeChangeComplete", handleRouteChange); + return () => { + router.events.off("routeChangeComplete", handleRouteChange); + }; + }, [router.events]); + +return ( + +<> +
+ + + {/* Global Site Tag (gtag.js) - Google Analytics */} + +