Skip to content

Commit

Permalink
fix/added-global-window-gtag
Browse files Browse the repository at this point in the history
  • Loading branch information
yyassif committed Sep 7, 2024
1 parent ab706dd commit 08399f2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
12 changes: 1 addition & 11 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -63,13 +59,7 @@ export default function RootLayout({
fontSans.variable
)}
>
<GoogleAnalytics GA_MEASUREMENT_ID={process.env.NEXT_PUBLIC_GOOGLE_ID as string} />
<ThemeProvider attribute="class" defaultTheme="light">
<TooltipProvider delayDuration={0}>
{children}
<Navbar />
</TooltipProvider>
</ThemeProvider>
{children}
</body>
</html>
);
Expand Down
27 changes: 27 additions & 0 deletions src/app/providers.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Fragment>
<GoogleAnalytics GA_MEASUREMENT_ID={process.env.NEXT_PUBLIC_GOOGLE_ID as string} />
<ThemeProvider attribute="class" defaultTheme="light">
<TooltipProvider delayDuration={0}>
{children}
<Navbar />
</TooltipProvider>
</ThemeProvider>
</Fragment>
);
}

8 changes: 7 additions & 1 deletion src/lib/gtag.ts
Original file line number Diff line number Diff line change
@@ -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,
});
};

0 comments on commit 08399f2

Please sign in to comment.