24 lines
623 B
TypeScript
24 lines
623 B
TypeScript
import Script from "next/script";
|
|
|
|
const DEFAULT_GA_ID = "G-TJBKHZLR7J";
|
|
const GA_ID = process.env.NEXT_PUBLIC_GA_ID?.trim() || DEFAULT_GA_ID;
|
|
|
|
export function GoogleAnalytics() {
|
|
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>
|
|
</>
|
|
);
|
|
}
|