@@ -3,7 +3,9 @@ import { SessionContextProvider } from "@supabase/auth-helpers-react";
33import { Analytics } from "@vercel/analytics/react" ;
44import localFont from "next/font/local" ;
55import Head from "next/head" ;
6- import { useState } from "react" ;
6+ import { useRouter } from "next/router" ;
7+ import Script from "next/script" ;
8+ import { useEffect , useState } from "react" ;
79import "../styles/global.css" ;
810import { UserContextProvider } from "../utils/useUser" ;
911
@@ -24,6 +26,22 @@ export default function App({ Component, pageProps }) {
2426 const getLayout = Component . getLayout || ( ( page ) => page ) ;
2527 const [ supabaseClient ] = useState ( ( ) => createPagesBrowserClient ( ) ) ;
2628
29+ const router = useRouter ( ) ;
30+ const googleTagId = "AW-11500375049" ;
31+
32+ useEffect ( ( ) => {
33+ const handleRouteChange = ( url : string ) => {
34+ // @ts -ignore
35+ window . gtag ( "config" , googleTagId , {
36+ page_path : url ,
37+ } ) ;
38+ } ;
39+ router . events . on ( "routeChangeComplete" , handleRouteChange ) ;
40+ return ( ) => {
41+ router . events . off ( "routeChangeComplete" , handleRouteChange ) ;
42+ } ;
43+ } , [ router . events , googleTagId ] ) ;
44+
2745 return (
2846 < >
2947 < Head >
@@ -37,6 +55,24 @@ export default function App({ Component, pageProps }) {
3755 --geist-font: ${ geist . style . fontFamily } ;
3856 }
3957 ` } </ style >
58+ < Script
59+ strategy = "afterInteractive"
60+ src = { `https://www.googletagmanager.com/gtag/js?id=${ googleTagId } ` }
61+ />
62+ < Script
63+ id = "google-ads-init"
64+ strategy = "afterInteractive"
65+ dangerouslySetInnerHTML = { {
66+ __html : `
67+ window.dataLayer = window.dataLayer || [];
68+ function gtag(){dataLayer.push(arguments);}
69+ gtag('js', new Date());
70+ gtag('config', '${ googleTagId } ', {
71+ send_page_view: false
72+ });
73+ ` ,
74+ } }
75+ />
4076 < SessionContextProvider
4177 supabaseClient = { supabaseClient }
4278 initialSession = { pageProps . initialSession }
0 commit comments