"use client" import React, { useEffect, useState } from "react" import Script from "next/script" // import { Analytics as VercelAnalytics } from "@vercel/analytics/react" export function Analytics() { const gtmId = process.env.NEXT_PUBLIC_GTM_ID // GA measurement ID: prefer env var, fallback to the ID you provided const gaId = process.env.NEXT_PUBLIC_GA_AI_ID // Mode: 'ga' | 'gtm' | null (not decided yet) const [mode, setMode] = useState(null) useEffect(() => { try { const path = window.location.pathname || "" const isR = path.includes("/r/") const isUiView = path.startsWith("/ui/view") if (isUiView) { // Disable analytics for /ui/view routes setMode(null) return } if (isR) { setMode("ga") } else { setMode("gtm") } } catch { // noop setMode("gtm") } }, []) // Not ready yet if (!mode) return null return ( <> {mode === "gtm" && gtmId && ( <> )} {/* If you also want Vercel Analytics, uncomment the import above and add here. */} ) }