/** Silent client telemetry for feedback — admin-only; never shown in UI. */ import { getGuestId } from "./api"; import { getSocialSession } from "./socialSession"; export type FeedbackClientMeta = Record; function safeLocal(key: string): string { try { return (localStorage.getItem(key) || "").trim(); } catch { return ""; } } export function collectFeedbackClientMeta( extra?: Record, ): FeedbackClientMeta { if (typeof window === "undefined") { return { ...(extra || {}), collectedAt: new Date().toISOString() }; } const session = getSocialSession(); const nav = window.navigator; const conn = (nav as Navigator & { connection?: Record }).connection || null; const screen = window.screen; return { collectedAt: new Date().toISOString(), guestId: getGuestId(), email: session?.email || "", name: session?.name || "", href: window.location.href, pathname: window.location.pathname, search: window.location.search, hash: window.location.hash, referrer: document.referrer || "", title: document.title || "", locale: document.documentElement.lang || "", language: nav.language || "", languages: Array.from(nav.languages || []), userAgent: nav.userAgent || "", platform: nav.platform || "", vendor: nav.vendor || "", cookieEnabled: nav.cookieEnabled, onLine: nav.onLine, maxTouchPoints: nav.maxTouchPoints || 0, hardwareConcurrency: nav.hardwareConcurrency || 0, deviceMemory: (nav as Navigator & { deviceMemory?: number }).deviceMemory || null, timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || "", timezoneOffsetMin: new Date().getTimezoneOffset(), screen: { width: screen.width, height: screen.height, availWidth: screen.availWidth, availHeight: screen.availHeight, colorDepth: screen.colorDepth, pixelDepth: screen.pixelDepth, orientation: screen.orientation?.type || "", }, viewport: { innerWidth: window.innerWidth, innerHeight: window.innerHeight, outerWidth: window.outerWidth, outerHeight: window.outerHeight, devicePixelRatio: window.devicePixelRatio || 1, }, connection: conn ? { type: conn.type ?? null, effectiveType: conn.effectiveType ?? null, downlink: conn.downlink ?? null, rtt: conn.rtt ?? null, saveData: conn.saveData ?? null, } : null, accountFlags: { paidType: safeLocal("paidType"), joinPaid: safeLocal("social-join-paid") || (() => { try { return sessionStorage.getItem("social-join-paid") || ""; } catch { return ""; } })(), profileDone: safeLocal("social-join-profile-done"), }, ...(extra || {}), }; }