import type { WebConfig } from "#lib/server/config.ts"; // best-effort: resolves either way, and does nothing without an api key export const capture = async ( config: WebConfig, event: string, distinctId: string, properties: Record = {} ): Promise => { if (!config.posthogApiKey) return; try { await fetch(`${config.posthogHost}/capture/`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ api_key: config.posthogApiKey, event, distinct_id: distinctId, properties: { ...properties, environment: config.posthogEnv }, timestamp: new Date().toISOString() }) }); } catch { // analytics never breaks the request it rides on } };