-
Notifications
You must be signed in to change notification settings - Fork 0
feat(frontend): add Google Analytics tracking #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,13 @@ | ||
| import type { Metadata } from "next"; | ||
| import { Geist, Geist_Mono, Playfair_Display, Cinzel } from "next/font/google"; | ||
| import Script from "next/script"; | ||
| import "./globals.css"; | ||
| import { AuthProvider } from "@/contexts/AuthContext"; | ||
| import { AuthWrapper } from "@/components/AuthWrapper"; | ||
| import { SiteHeader } from "@/components/SiteHeader"; | ||
|
|
||
| const GA_ID = "G-65HJEVF1M4"; | ||
|
|
||
| const geistSans = Geist({ | ||
| variable: "--font-geist-sans", | ||
| subsets: ["latin"], | ||
|
|
@@ -47,6 +50,18 @@ export default function RootLayout({ | |
| }>) { | ||
| return ( | ||
| <html lang="en"> | ||
| <Script | ||
| src={`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`} | ||
| strategy="afterInteractive" | ||
| /> | ||
| <Script id="google-analytics" strategy="afterInteractive"> | ||
| {` | ||
| window.dataLayer = window.dataLayer || []; | ||
| function gtag(){dataLayer.push(arguments);} | ||
| gtag('js', new Date()); | ||
| gtag('config', '${GA_ID}'); | ||
| `} | ||
| </Script> | ||
|
Comment on lines
+53
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These analytics scripts will run in all environments, including local development. This can pollute your analytics data with development activity. It's recommended to only enable analytics in the production environment and to ensure the tracking ID is configured before attempting to load the scripts. |
||
| <body | ||
| className={`${geistSans.variable} ${geistMono.variable} ${playfair.variable} ${cinzel.variable} antialiased`} | ||
| > | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Google Analytics ID is hardcoded. It's a best practice to store configuration values like this in environment variables. This allows for different configurations across environments (development, staging, production) without code changes. For Next.js, you should use a public environment variable by prefixing it with
NEXT_PUBLIC_and adding it to a.env.localfile.