"use client"; import Script from "next/script"; import { useConsent } from "../lib/useConsent"; import type { TrackingCode } from "../lib/payload"; // Renders one next/script per active tracking code, but only once consent // actually allows it — `necessary` always renders (nothing in that // category exists yet, but the field exists for future use, e.g. a // consent-management/CMP script itself); `analytics`/`marketing` both gate // on the same single useConsent() flag (see that hook's own comment on why // there's no separate marketing toggle yet). Fetched server-side // (getTrackingCodes(), passed in as a prop from layout.tsx) since this // component itself is a client component and can't call that fetcher // directly without losing the 60s ISR cache. export function TrackingScripts({ codes }: { codes: TrackingCode[] }) { const { consent, loaded } = useConsent(); if (!loaded) return null; const allowed = codes.filter((code) => code.consentCategory === "necessary" || consent?.analytics === true); return ( <> {allowed.map((code) => { if (code.provider === "google-analytics" && code.measurementId) { return (