const METRICS_ENDPOINT = 'https://misc-functions.vercel.app/api/metrics' type FrontendMetricName = 'pageview' | 'global_crash' /** * Fire-and-forget frontend metric. Sent as text/plain so the request stays * CORS-simple (no preflight). Failures are intentionally swallowed. */ export function sendFrontendMetric(metricName: FrontendMetricName): void { try { fetch(METRICS_ENDPOINT, { method: 'POST', keepalive: true, credentials: 'omit', headers: { 'Content-Type': 'text/plain' }, body: JSON.stringify({ environment: 'staging', events: [{ metric_name: metricName, value: 1, metadata: { app: 'studio' } }], }), }).catch(() => {}) } catch { // fetch can throw synchronously (e.g. invalid arguments); never surface it } }