From 08399f288869e353eeb09d5a82fdbcf95a002ffe Mon Sep 17 00:00:00 2001 From: yyassif Date: Fri, 6 Sep 2024 23:22:06 -0400 Subject: [PATCH] fix/added-global-window-gtag --- src/app/layout.tsx | 12 +----------- src/app/providers.tsx | 27 +++++++++++++++++++++++++++ src/lib/gtag.ts | 8 +++++++- 3 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/app/providers.tsx diff --git a/src/app/layout.tsx b/src/app/layout.tsx index fbc1585..3b81705 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,7 +1,3 @@ -import Navbar from "@/components/navbar"; -import { ThemeProvider } from "@/components/theme-provider"; -import { TooltipProvider } from "@/components/ui/tooltip"; -import GoogleAnalytics from "@/components/google-analytics"; import { DATA } from "@/data/resume"; import { cn } from "@/lib/utils"; import type { Metadata } from "next"; @@ -63,13 +59,7 @@ export default function RootLayout({ fontSans.variable )} > - - - - {children} - - - + {children} ); diff --git a/src/app/providers.tsx b/src/app/providers.tsx new file mode 100644 index 0000000..f135cfc --- /dev/null +++ b/src/app/providers.tsx @@ -0,0 +1,27 @@ +"use client"; + +import { Fragment } from "react"; +import Navbar from "@/components/navbar"; +import { ThemeProvider } from "@/components/theme-provider"; +import { TooltipProvider } from "@/components/ui/tooltip"; +import GoogleAnalytics from "@/components/google-analytics"; + + +export interface ProvidersProps { + children: React.ReactNode; +} + +export function Providers({ children }: ProvidersProps) { + return ( + + + + + {children} + + + + + ); +} + diff --git a/src/lib/gtag.ts b/src/lib/gtag.ts index 42777ab..f05d7ec 100644 --- a/src/lib/gtag.ts +++ b/src/lib/gtag.ts @@ -1,5 +1,11 @@ +declare global { + interface Window { + gtag: (...args: any[]) => void; + } +} + export const pageview = (GA_MEASUREMENT_ID: string, url: string) => { - window.gtag("config", GA_MEASUREMENT_ID, { + window?.gtag("config", GA_MEASUREMENT_ID, { page_path: url, }); };