songs2vid/components/GoogleAnalytics.tsx

29 lines
883 B
TypeScript

import Script from "next/script";
/** Primary GA4 property (songs2vid.com). */
const GA_MEASUREMENT_ID = "G-9XCHRS7LJR";
/** Additional GA4 property — both must remain configured. */
const GA_MEASUREMENT_ID_SECONDARY = "G-2V3FSMMPQX";
/**
* Google Analytics 4 (gtag.js) for songs2vid.com / songs2yt.com.
* Loaded once from the root layout; both measurement IDs stay active.
*/
export function GoogleAnalytics() {
return (
<>
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${GA_MEASUREMENT_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_MEASUREMENT_ID}');
gtag('config', '${GA_MEASUREMENT_ID_SECONDARY}');
`}</Script>
</>
);
}