From 33d57e88cf63774923c2f786443dec7a9624a636 Mon Sep 17 00:00:00 2001 From: Ricardo Casares <84963+ricardocasares@users.noreply.github.com> Date: Tue, 31 Aug 2021 17:01:51 +0200 Subject: [PATCH] feat: use google analytics script (#183) --- package.json | 1 - src/pages/_app.tsx | 15 +- src/pages/_document.tsx | 16 ++ yarn.lock | 321 +++++++++++++++++----------------------- 4 files changed, 165 insertions(+), 188 deletions(-) diff --git a/package.json b/package.json index ee609203..187b287f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,6 @@ "dependencies": { "@geist-ui/react-icons": "^1.0.0", "@genql/runtime": "2.6.0", - "@next/plugin-google-analytics": "^10.0.6", "@next/plugin-sentry": "ricardocasares/next-plugin-sentry", "@stitches/react": "^1.0.0", "@vercel/fetch": "^6.1.0", diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index db750b6f..6aa1d9d1 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,16 +1,29 @@ +import { useEffect } from "react"; import { AppProps } from "next/app"; +import { useRouter } from "next/router"; import { DefaultSeo } from "next-seo"; import { Providers } from "@/lib/providers"; import { Layout } from "@/components/Layout"; import { Header } from "@/components/Header"; import { Scrollable } from "@/components/Scrollable"; import { Player } from "@/components/Player"; -import seoProps from "@/config/seo"; import { globalStyles } from "@/css/global"; +import { pageview } from "@/lib/utils"; +import seoProps from "@/config/seo"; + export function BembaApp({ Component, pageProps }: AppProps) { globalStyles(); + const router = useRouter(); + + useEffect(() => { + const handleRouteChange = (url: string) => pageview(url); + router.events.on("routeChangeComplete", handleRouteChange); + + return () => router.events.off("routeChangeComplete", handleRouteChange); + }, [router.events]); + return ( diff --git a/src/pages/_document.tsx b/src/pages/_document.tsx index 8140aeba..76f63cd2 100644 --- a/src/pages/_document.tsx +++ b/src/pages/_document.tsx @@ -7,6 +7,22 @@ export default class Document extends NextDocument {