{"mappings":";AAAA,OAAS,eAAAA,EAAa,wBAAAC,MAA4B,aAqBlD,eAAsBC,EAAMC,EAAMC,EAAOC,EAAS,CAC9C,IAAMC,GAAaH,GAAQ,IAAI,KAAK,EAGpC,GAFI,CAACG,GAED,OAAO,OAAW,IAClB,OACJ,IAAMC,EAAO,KAAK,UAAU,CACxB,KAAMD,EACN,IAAK,OAAO,UAAU,KACtB,MAAOF,GAAS,CAAC,CACrB,CAAC,EAGD,GAAI,CACA,GAAI,OAAO,UAAc,KAAe,OAAO,UAAU,YAAe,WAAY,CAChF,IAAMI,EAAUP,EAAqBI,CAAO,EAAE,QAAQ,QAAQ,OAAQ,EAAE,EAExE,GADW,UAAU,WAAW,GAAGG,CAAO,cAAe,IAAI,KAAK,CAACD,CAAI,EAAG,CAAE,KAAM,kBAAmB,CAAC,CAAC,EAEnG,MACR,CACJ,MACM,CAEN,CACA,GAAI,CACA,MAAMP,EAAY,cAAe,CAAE,OAAQ,OAAQ,UAAW,GAAM,KAAAO,CAAK,EAAGF,CAAO,CACvF,MACM,CAEN,CACJ","names":["requestJson","resolveTalizenConfig","track","name","props","options","eventName","body","baseUrl"],"sources":["../esm/npm/talizen@0.2.55/node_modules/talizen/analytics.js"],"sourcesContent":["import { requestJson, resolveTalizenConfig } from \"./core.js\";\n/**\n * Report a custom analytics event (\"埋点\") for the current site.\n *\n * Fire-and-forget and best-effort: it never throws on network/HTTP errors, so\n * analytics can't break the page. The site is resolved server-side from the\n * request host — you do not pass a site id. The current page URL is attached\n * automatically. Visitor identity (for unique counts) is handled by a\n * first-party cookie on the server.\n *\n * Delivery prefers `navigator.sendBeacon`, so the event is reliably recorded\n * even when the click navigates away (e.g. a link's onClick). Falls back to\n * `fetch` with `keepalive` when sendBeacon is unavailable.\n *\n * Call it from client code only (event handlers, effects); it is a no-op during\n * SSR since there is no `window`.\n *\n * @example\n * import { track } from \"talizen/analytics\"\n * track(\"click_buy\", { plan: \"pro\" })\n */\nexport async function track(name, props, options) {\n    const eventName = (name ?? \"\").trim();\n    if (!eventName)\n        return;\n    if (typeof window === \"undefined\")\n        return;\n    const body = JSON.stringify({\n        name: eventName,\n        url: window.location?.href,\n        props: props ?? {},\n    });\n    // Prefer sendBeacon: the browser queues it and delivers it even as the page\n    // unloads, so events survive a click that navigates away.\n    try {\n        if (typeof navigator !== \"undefined\" \u0026\u0026 typeof navigator.sendBeacon === \"function\") {\n            const baseUrl = resolveTalizenConfig(options).baseUrl.replace(/\\/+$/, \"\");\n            const ok = navigator.sendBeacon(`${baseUrl}/site_event`, new Blob([body], { type: \"application/json\" }));\n            if (ok)\n                return;\n        }\n    }\n    catch {\n        // fall through to fetch\n    }\n    try {\n        await requestJson(\"/site_event\", { method: \"POST\", keepalive: true, body }, options);\n    }\n    catch {\n        // Analytics is best-effort; swallow errors so tracking never breaks the UI.\n    }\n}\n"],"version":3}
