diff --git a/.env.example b/.env.example index c539b6a..dded42e 100644 --- a/.env.example +++ b/.env.example @@ -8,5 +8,5 @@ NEXT_PUBLIC_APP_URL=https://btc.eh-aye.net # API endpoints (if needed) # NEXT_PUBLIC_API_URL=https://api.eh-aye.net -# Analytics (optional) -# NEXT_PUBLIC_GA_ID=G-XXXXXXXXXX \ No newline at end of file +# Google Analytics (optional) +# NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX \ No newline at end of file diff --git a/src/components/GoogleAnalytics.tsx b/src/components/GoogleAnalytics.tsx new file mode 100644 index 0000000..ed22c78 --- /dev/null +++ b/src/components/GoogleAnalytics.tsx @@ -0,0 +1,28 @@ +import Script from "next/script"; + +export function GoogleAnalytics() { + const gaMeasurementId = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID; + + if (!gaMeasurementId) { + return null; + } + + return ( + <> + {/* Google tag (gtag.js) */} + + + ); +} diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index d04ba06..c552952 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -3,6 +3,7 @@ import type { AppProps } from "next/app"; import "../styles/globals.css"; import { Toaster } from "@/components/ui/toaster"; import { ThemeProvider } from "@/providers/theme-provider"; +import { GoogleAnalytics } from "@/components/GoogleAnalytics"; export default function App({ Component, pageProps }: AppProps) { useEffect(() => { @@ -35,6 +36,7 @@ export default function App({ Component, pageProps }: AppProps) { enableSystem disableTransitionOnChange > +