/** * Optional Umami tracker. Unset env vars mean no script ships. * Cookie-free mode is an Umami server setting, not this snippet. * * Values are read by key at request time so Cloudron `env set` works * without rebuilding the image (`NEXT_PUBLIC_*` is otherwise inlined * at `next build`). */ function readEnv(name: string): string { return process.env[name]?.trim() ?? ""; } export function umamiTracker(): { src: string; websiteId: string } | null { const src = readEnv("NEXT_PUBLIC_UMAMI_SRC"); const websiteId = readEnv("NEXT_PUBLIC_UMAMI_WEBSITE_ID"); if (!src || !websiteId) return null; try { const url = new URL(src); if (url.protocol !== "https:" && url.protocol !== "http:") return null; return { src: url.href, websiteId }; } catch { return null; } }