Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
# Google Analytics (optional)
# NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX
28 changes: 28 additions & 0 deletions src/components/GoogleAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -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) */}
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${gaMeasurementId}`}
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '${gaMeasurementId}');
`}
</Script>
</>
);
}
2 changes: 2 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -35,6 +36,7 @@ export default function App({ Component, pageProps }: AppProps) {
enableSystem
disableTransitionOnChange
>
<GoogleAnalytics />
<Component {...pageProps} />
<Toaster />
</ThemeProvider>
Expand Down
Loading