feat: add Google Analytics integration component using Next.js Script

This commit is contained in:
Poyraz Avsever
2026-03-30 11:33:52 +03:00
parent 31da9f114b
commit 7b95ca43b7
+24
View File
@@ -0,0 +1,24 @@
import Script from "next/script";
const GA_ID = process.env.NEXT_PUBLIC_GA_ID;
export function GoogleAnalytics() {
if (!GA_ID) return null;
return (
<>
<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>
</>
);
}