@bmnova/web-analytics 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/bots.ts","../src/shared/channel.ts","../src/shared/privacy.ts","../src/shared/ua.ts"],"sourcesContent":["export type BotKind =\n | \"ai_training\" // crawls content to train models\n | \"ai_user\" // fetches a page because a person asked an assistant\n | \"ai_search\" // builds an AI search index\n | \"search\"\n | \"social\" // link previews\n | \"seo\"\n | \"monitor\"\n | \"other\";\n\nexport interface Bot {\n name: string;\n kind: BotKind;\n}\n\n// Order matters: the first match wins, so specific tokens come before generic ones.\nconst BOTS: Array<[RegExp, string, BotKind]> = [\n // OpenAI\n [/ChatGPT-User/i, \"ChatGPT-User\", \"ai_user\"],\n [/OAI-SearchBot/i, \"OAI-SearchBot\", \"ai_search\"],\n [/GPTBot/i, \"GPTBot\", \"ai_training\"],\n // Anthropic\n [/Claude-User/i, \"Claude-User\", \"ai_user\"],\n [/Claude-SearchBot/i, \"Claude-SearchBot\", \"ai_search\"],\n [/Claude-Web/i, \"Claude-Web\", \"ai_user\"],\n [/ClaudeBot/i, \"ClaudeBot\", \"ai_training\"],\n [/anthropic-ai/i, \"anthropic-ai\", \"ai_training\"],\n // Perplexity\n [/Perplexity-User/i, \"Perplexity-User\", \"ai_user\"],\n [/PerplexityBot/i, \"PerplexityBot\", \"ai_search\"],\n // Others\n [/MistralAI-User/i, \"MistralAI-User\", \"ai_user\"],\n [/DuckAssistBot/i, \"DuckAssistBot\", \"ai_user\"],\n [/Meta-ExternalFetcher/i, \"Meta-ExternalFetcher\", \"ai_user\"],\n [/meta-externalagent/i, \"meta-externalagent\", \"ai_training\"],\n [/Google-CloudVertexBot/i, \"Google-CloudVertexBot\", \"ai_training\"],\n [/Bytespider/i, \"Bytespider\", \"ai_training\"],\n [/CCBot/i, \"CCBot\", \"ai_training\"],\n [/Amazonbot/i, \"Amazonbot\", \"ai_training\"],\n [/cohere-ai|cohere-training-data-crawler/i, \"cohere-ai\", \"ai_training\"],\n [/Diffbot/i, \"Diffbot\", \"ai_training\"],\n [/YouBot/i, \"YouBot\", \"ai_search\"],\n [/PhindBot/i, \"PhindBot\", \"ai_search\"],\n [/Timpibot/i, \"Timpibot\", \"ai_training\"],\n [/AI2Bot/i, \"AI2Bot\", \"ai_training\"],\n [/omgili/i, \"omgili\", \"ai_training\"],\n // Search engines\n [/Googlebot|Google-InspectionTool|Storebot-Google/i, \"Googlebot\", \"search\"],\n [/GoogleOther/i, \"GoogleOther\", \"other\"],\n [/bingbot|BingPreview/i, \"Bingbot\", \"search\"],\n [/Applebot/i, \"Applebot\", \"search\"],\n [/YandexBot|YandexMobileBot/i, \"YandexBot\", \"search\"],\n [/Baiduspider/i, \"Baiduspider\", \"search\"],\n [/DuckDuckBot/i, \"DuckDuckBot\", \"search\"],\n [/PetalBot/i, \"PetalBot\", \"search\"],\n [/Yeti\\//i, \"NaverYeti\", \"search\"],\n [/SeznamBot/i, \"SeznamBot\", \"search\"],\n // Link previews\n [/facebookexternalhit|facebookcatalog/i, \"Facebook\", \"social\"],\n [/Twitterbot/i, \"Twitterbot\", \"social\"],\n [/LinkedInBot/i, \"LinkedInBot\", \"social\"],\n [/Slackbot|Slack-ImgProxy/i, \"Slackbot\", \"social\"],\n [/Discordbot/i, \"Discordbot\", \"social\"],\n [/TelegramBot/i, \"TelegramBot\", \"social\"],\n [/WhatsApp/i, \"WhatsApp\", \"social\"],\n [/Pinterestbot/i, \"Pinterestbot\", \"social\"],\n [/redditbot/i, \"redditbot\", \"social\"],\n // SEO tools\n [/AhrefsBot|AhrefsSiteAudit/i, \"AhrefsBot\", \"seo\"],\n [/SemrushBot/i, \"SemrushBot\", \"seo\"],\n [/MJ12bot/i, \"MJ12bot\", \"seo\"],\n [/DotBot/i, \"DotBot\", \"seo\"],\n [/DataForSeoBot/i, \"DataForSeoBot\", \"seo\"],\n [/Screaming Frog/i, \"ScreamingFrog\", \"seo\"],\n // Monitoring\n [/UptimeRobot/i, \"UptimeRobot\", \"monitor\"],\n [/Pingdom/i, \"Pingdom\", \"monitor\"],\n [/Better ?Uptime|BetterStack/i, \"BetterStack\", \"monitor\"],\n [/vercel-(screenshot|favicon)/i, \"Vercel\", \"monitor\"],\n];\n\nconst GENERIC =\n /bot\\b|crawler|spider|crawl|slurp|headlesschrome|phantomjs|puppeteer|playwright|python-requests|python-urllib|aiohttp|httpx|go-http-client|curl\\/|wget\\/|axios\\/|node-fetch|undici|okhttp|java\\/|libwww|scrapy/i;\n\n/** Returns the bot behind a user agent, or null for a (probable) human browser. */\nexport function detectBot(userAgent: string | null | undefined): Bot | null {\n if (!userAgent) return { name: \"empty-ua\", kind: \"other\" };\n for (const [re, name, kind] of BOTS) {\n if (re.test(userAgent)) return { name, kind };\n }\n if (GENERIC.test(userAgent)) return { name: \"generic\", kind: \"other\" };\n return null;\n}\n\nexport const AI_BOT_KINDS: ReadonlySet<BotKind> = new Set([\"ai_training\", \"ai_user\", \"ai_search\"]);\n","export type Channel =\n | \"ai\"\n | \"search\"\n | \"social\"\n | \"email\"\n | \"paid\"\n | \"campaign\"\n | \"referral\"\n | \"internal\"\n | \"direct\";\n\nexport interface ChannelInput {\n utmSource?: string | null;\n utmMedium?: string | null;\n /** Full referrer URL or bare host. */\n referrer?: string | null;\n /** Host of the site itself; a referrer on this host is internal navigation. */\n selfHost?: string | null;\n}\n\nexport interface ChannelResult {\n channel: Channel;\n source: string | null;\n referrerHost: string | null;\n}\n\n// Hosts are matched exactly or as a parent domain (sub.example.com matches example.com).\nconst AI_HOSTS = [\n \"chatgpt.com\",\n \"chat.openai.com\",\n \"openai.com\",\n \"perplexity.ai\",\n \"claude.ai\",\n \"gemini.google.com\",\n \"bard.google.com\",\n \"aistudio.google.com\",\n \"notebooklm.google.com\",\n \"copilot.microsoft.com\",\n \"copilot.cloud.microsoft\",\n \"deepseek.com\",\n \"grok.com\",\n \"meta.ai\",\n \"chat.mistral.ai\",\n \"you.com\",\n \"phind.com\",\n \"poe.com\",\n \"kimi.com\",\n \"kimi.moonshot.cn\",\n \"chat.qwen.ai\",\n \"duck.ai\",\n];\n\nconst AI_SOURCE_WORDS = /^(chatgpt|openai|perplexity|claude|gemini|copilot|deepseek|grok|mistral|le-chat|meta-ai|you|phind|poe)$/i;\n\nconst SEARCH_HOSTS = [\n \"bing.com\",\n \"duckduckgo.com\",\n \"search.yahoo.com\",\n \"yahoo.com\",\n \"yandex.ru\",\n \"yandex.com\",\n \"yandex.com.tr\",\n \"baidu.com\",\n \"ecosia.org\",\n \"search.brave.com\",\n \"startpage.com\",\n \"qwant.com\",\n \"naver.com\",\n \"seznam.cz\",\n \"kagi.com\",\n];\n\nconst SOCIAL_HOSTS = [\n \"facebook.com\",\n \"fb.com\",\n \"instagram.com\",\n \"t.co\",\n \"x.com\",\n \"twitter.com\",\n \"linkedin.com\",\n \"lnkd.in\",\n \"reddit.com\",\n \"youtube.com\",\n \"youtu.be\",\n \"tiktok.com\",\n \"pinterest.com\",\n \"threads.net\",\n \"threads.com\",\n \"bsky.app\",\n \"mastodon.social\",\n \"news.ycombinator.com\",\n \"producthunt.com\",\n \"medium.com\",\n \"quora.com\",\n \"discord.com\",\n \"t.me\",\n \"telegram.org\",\n \"web.whatsapp.com\",\n \"wa.me\",\n];\n\nconst EMAIL_HOSTS = [\"mail.google.com\", \"outlook.live.com\", \"outlook.office.com\", \"mail.yahoo.com\", \"mail.proton.me\"];\n\nconst GOOGLE = /^(?:[a-z0-9-]+\\.)*google\\.[a-z]{2,3}(?:\\.[a-z]{2})?$/;\n\n/** Lowercase host without \"www.\" for a URL or bare host; null when unparseable. */\nexport function hostOf(value: string | null | undefined): string | null {\n if (!value) return null;\n const raw = value.trim().toLowerCase();\n if (!raw) return null;\n let host: string;\n try {\n host = new URL(raw.includes(\"://\") ? raw : `https://${raw}`).hostname;\n } catch {\n return null;\n }\n if (!host || !host.includes(\".\")) return host || null;\n return host.replace(/^www\\./, \"\");\n}\n\nfunction matches(host: string, list: readonly string[]): string | null {\n for (const d of list) if (host === d || host.endsWith(`.${d}`)) return d;\n return null;\n}\n\n/** Classify a host into a channel, or null when it is an ordinary referral. */\nfunction classifyHost(host: string): { channel: Channel; source: string } | null {\n const ai = matches(host, AI_HOSTS);\n if (ai) return { channel: \"ai\", source: ai };\n const mail = matches(host, EMAIL_HOSTS);\n if (mail) return { channel: \"email\", source: mail };\n if (GOOGLE.test(host)) return { channel: \"search\", source: \"google\" };\n const search = matches(host, SEARCH_HOSTS);\n if (search) return { channel: \"search\", source: search };\n const social = matches(host, SOCIAL_HOSTS);\n if (social) return { channel: \"social\", source: social.replace(/^(m|l|lm)\\./, \"\") };\n return null;\n}\n\nconst PAID = /^(cpc|ppc|paid|paidsearch|paid_search|paid-social|paid_social|paidsocial|display|cpm|banner|ads?)$/i;\nconst EMAIL_MEDIUM = /^(e-?mail|newsletter)$/i;\nconst SOCIAL_MEDIUM = /^(social|social-network|social-media|sm|organic_social)$/i;\n\n/**\n * Work out where a visit came from. UTM tags win over the referrer, because AI\n * assistants (e.g. ChatGPT adds utm_source=chatgpt.com) often send no referrer.\n */\nexport function classifyChannel(input: ChannelInput): ChannelResult {\n const referrerHost = hostOf(input.referrer);\n const selfHost = hostOf(input.selfHost);\n const utmSource = input.utmSource?.trim().toLowerCase() || null;\n const utmMedium = input.utmMedium?.trim().toLowerCase() || null;\n\n if (utmSource || utmMedium) {\n const srcHost = utmSource ? hostOf(utmSource) : null;\n const byHost = srcHost && srcHost.includes(\".\") ? classifyHost(srcHost) : null;\n const source = byHost?.source ?? utmSource;\n if (byHost?.channel === \"ai\" || (utmSource && AI_SOURCE_WORDS.test(utmSource))) {\n return { channel: \"ai\", source, referrerHost };\n }\n if (utmMedium && PAID.test(utmMedium)) return { channel: \"paid\", source, referrerHost };\n if (utmMedium && EMAIL_MEDIUM.test(utmMedium)) return { channel: \"email\", source, referrerHost };\n if (utmMedium && SOCIAL_MEDIUM.test(utmMedium)) return { channel: \"social\", source, referrerHost };\n if (byHost) return { channel: byHost.channel, source, referrerHost };\n return { channel: \"campaign\", source, referrerHost };\n }\n\n if (!referrerHost) return { channel: \"direct\", source: null, referrerHost: null };\n if (selfHost && (referrerHost === selfHost || referrerHost.endsWith(`.${selfHost}`) || selfHost.endsWith(`.${referrerHost}`))) {\n return { channel: \"internal\", source: null, referrerHost };\n }\n const byHost = classifyHost(referrerHost);\n if (byHost) return { ...byHost, referrerHost };\n return { channel: \"referral\", source: referrerHost, referrerHost };\n}\n","import { LIMITS, type Props, type PropValue } from \"./schema.js\";\n\n/**\n * Prop keys that must never be stored. Matched case-insensitively as substrings,\n * so \"user_email\" and \"totalAmount\" are dropped too.\n */\nconst DENY = [\n \"email\",\n \"e_mail\",\n \"phone\",\n \"password\",\n \"passwd\",\n \"secret\",\n \"token\",\n \"apikey\",\n \"api_key\",\n \"auth\",\n \"cookie\",\n \"session_token\",\n \"card\",\n \"iban\",\n \"cvv\",\n \"ssn\",\n \"tckn\",\n \"address\",\n \"amount\",\n \"revenue\",\n \"income\",\n \"salary\",\n \"price\",\n \"balance\",\n \"file_content\",\n \"content\",\n \"ip\",\n];\n\nconst DENY_EXACT = new Set([\"ip\", \"name\", \"first_name\", \"last_name\", \"full_name\", \"fullname\"]);\n\nexport function isDeniedKey(key: string): boolean {\n const k = key.toLowerCase();\n if (DENY_EXACT.has(k)) return true;\n // \"ip\" as substring would block \"tooltip\"/\"zip\"; only match it as a whole segment.\n return DENY.some((d) => (d === \"ip\" ? /(^|_)ip(_|$)/.test(k) : k.includes(d)));\n}\n\nconst EMAIL_LIKE = /[^\\s@]+@[^\\s@]+\\.[^\\s@]+/;\n\n/** Drop denied keys and unsafe values, and cap sizes. Returns null when nothing is left. */\nexport function sanitizeProps(input: unknown): Props | null {\n if (!input || typeof input !== \"object\" || Array.isArray(input)) return null;\n const out: Props = {};\n let n = 0;\n for (const [key, value] of Object.entries(input as Record<string, unknown>)) {\n if (n >= LIMITS.propKeys) break;\n if (!LIMITS.propKey.test(key) || isDeniedKey(key)) continue;\n const v = cleanValue(value);\n if (v === undefined) continue;\n out[key] = v;\n n++;\n }\n return n ? out : null;\n}\n\nfunction cleanValue(value: unknown): PropValue | undefined {\n if (value === null) return null;\n if (typeof value === \"boolean\") return value;\n if (typeof value === \"number\") return Number.isFinite(value) ? value : undefined;\n if (typeof value === \"string\") {\n if (EMAIL_LIKE.test(value)) return undefined;\n return value.slice(0, LIMITS.propStringLength);\n }\n return undefined;\n}\n\n/** Keep only the path: drop query string and hash (they can carry tokens or personal data). */\nexport function cleanPath(path: string | null | undefined): string | null {\n if (!path) return null;\n let p = path.trim();\n const cut = p.search(/[?#]/);\n if (cut >= 0) p = p.slice(0, cut);\n if (!p.startsWith(\"/\")) {\n try {\n p = new URL(p).pathname;\n } catch {\n return null;\n }\n }\n return p.slice(0, LIMITS.pathLength) || \"/\";\n}\n","export interface UaInfo {\n device: \"mobile\" | \"tablet\" | \"desktop\" | null;\n browser: string | null;\n os: string | null;\n}\n\n/** Small, dependency-free user-agent parser. Good enough for dashboards, not for fingerprinting. */\nexport function parseUa(ua: string | null | undefined): UaInfo {\n if (!ua) return { device: null, browser: null, os: null };\n\n const os = /iPhone|iPad|iPod/.test(ua)\n ? \"iOS\"\n : /Android/.test(ua)\n ? \"Android\"\n : /Windows/.test(ua)\n ? \"Windows\"\n : /CrOS/.test(ua)\n ? \"ChromeOS\"\n : /Mac OS X|Macintosh/.test(ua)\n ? \"macOS\"\n : /Linux/.test(ua)\n ? \"Linux\"\n : null;\n\n const browser = /Edg(e|A|iOS)?\\//.test(ua)\n ? \"Edge\"\n : /OPR\\/|Opera/.test(ua)\n ? \"Opera\"\n : /SamsungBrowser/.test(ua)\n ? \"Samsung Internet\"\n : /YaBrowser/.test(ua)\n ? \"Yandex\"\n : /Firefox|FxiOS/.test(ua)\n ? \"Firefox\"\n : /Chrome|CriOS/.test(ua)\n ? \"Chrome\"\n : /Safari/.test(ua)\n ? \"Safari\"\n : null;\n\n const device = /iPad|Tablet|(Android(?!.*Mobile))/.test(ua)\n ? \"tablet\"\n : /Mobi|iPhone|iPod|Android/.test(ua)\n ? \"mobile\"\n : \"desktop\";\n\n return { device, browser, os };\n}\n"],"mappings":";;;;;AAgBA,IAAM,OAAyC;AAAA;AAAA,EAE7C,CAAC,iBAAiB,gBAAgB,SAAS;AAAA,EAC3C,CAAC,kBAAkB,iBAAiB,WAAW;AAAA,EAC/C,CAAC,WAAW,UAAU,aAAa;AAAA;AAAA,EAEnC,CAAC,gBAAgB,eAAe,SAAS;AAAA,EACzC,CAAC,qBAAqB,oBAAoB,WAAW;AAAA,EACrD,CAAC,eAAe,cAAc,SAAS;AAAA,EACvC,CAAC,cAAc,aAAa,aAAa;AAAA,EACzC,CAAC,iBAAiB,gBAAgB,aAAa;AAAA;AAAA,EAE/C,CAAC,oBAAoB,mBAAmB,SAAS;AAAA,EACjD,CAAC,kBAAkB,iBAAiB,WAAW;AAAA;AAAA,EAE/C,CAAC,mBAAmB,kBAAkB,SAAS;AAAA,EAC/C,CAAC,kBAAkB,iBAAiB,SAAS;AAAA,EAC7C,CAAC,yBAAyB,wBAAwB,SAAS;AAAA,EAC3D,CAAC,uBAAuB,sBAAsB,aAAa;AAAA,EAC3D,CAAC,0BAA0B,yBAAyB,aAAa;AAAA,EACjE,CAAC,eAAe,cAAc,aAAa;AAAA,EAC3C,CAAC,UAAU,SAAS,aAAa;AAAA,EACjC,CAAC,cAAc,aAAa,aAAa;AAAA,EACzC,CAAC,2CAA2C,aAAa,aAAa;AAAA,EACtE,CAAC,YAAY,WAAW,aAAa;AAAA,EACrC,CAAC,WAAW,UAAU,WAAW;AAAA,EACjC,CAAC,aAAa,YAAY,WAAW;AAAA,EACrC,CAAC,aAAa,YAAY,aAAa;AAAA,EACvC,CAAC,WAAW,UAAU,aAAa;AAAA,EACnC,CAAC,WAAW,UAAU,aAAa;AAAA;AAAA,EAEnC,CAAC,oDAAoD,aAAa,QAAQ;AAAA,EAC1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,MAAI,OAAO,EAAG,KAAI,EAAE,MAAM,GAAG,GAAG;AAChC,MAAI,CAAC,EAAE,WAAW,GAAG,GAAG;AACtB,QAAI;AACF,UAAI,IAAI,IAAI,CAAC,EAAE;AAAA,IACjB,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO,EAAE,MAAM,GAAG,OAAO,UAAU,KAAK;AAC1C;;;ACjFO,SAAS,QAAQ,IAAuC;AAC7D,MAAI,CAAC,GAAI,QAAO,EAAE,QAAQ,MAAM,SAAS,MAAM,IAAI,KAAK;AAExD,QAAM,KAAK,mBAAmB,KAAK,EAAE,IACjC,QACA,UAAU,KAAK,EAAE,IACf,YACA,UAAU,KAAK,EAAE,IACf,YACA,OAAO,KAAK,EAAE,IACZ,aACA,qBAAqB,KAAK,EAAE,IAC1B,UACA,QAAQ,KAAK,EAAE,IACb,UACA;AAEd,QAAM,UAAU,kBAAkB,KAAK,EAAE,IACrC,SACA,cAAc,KAAK,EAAE,IACnB,UACA,iBAAiB,KAAK,EAAE,IACtB,qBACA,YAAY,KAAK,EAAE,IACjB,WACA,gBAAgB,KAAK,EAAE,IACrB,YACA,eAAe,KAAK,EAAE,IACpB,WACA,SAAS,KAAK,EAAE,IACd,WACA;AAEhB,QAAM,SAAS,oCAAoC,KAAK,EAAE,IACtD,WACA,2BAA2B,KAAK,EAAE,IAChC,WACA;AAEN,SAAO,EAAE,QAAQ,SAAS,GAAG;AAC/B;","names":["byHost"]}
@@ -0,0 +1,19 @@
1
+ // src/shared/schema.ts
2
+ var LIMITS = {
3
+ bodyBytes: 8192,
4
+ eventsPerBatch: 25,
5
+ eventName: /^[a-zA-Z0-9_.:-]{1,64}$/,
6
+ site: /^[a-zA-Z0-9_.-]{1,64}$/,
7
+ id: /^[a-zA-Z0-9_.:@-]{1,128}$/,
8
+ pathLength: 512,
9
+ titleLength: 200,
10
+ utmLength: 150,
11
+ propKeys: 20,
12
+ propKey: /^[a-zA-Z0-9_]{1,40}$/,
13
+ propStringLength: 200
14
+ };
15
+
16
+ export {
17
+ LIMITS
18
+ };
19
+ //# sourceMappingURL=chunk-PD4SX2FD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/schema.ts"],"sourcesContent":["/** Consent level of the visitor when the event was recorded. */\nexport type Consent = \"basic\" | \"full\";\n\n/** Where a row was produced. */\nexport type Via = \"client\" | \"server\" | \"proxy\";\n\nexport interface Utm {\n source?: string;\n medium?: string;\n campaign?: string;\n term?: string;\n content?: string;\n}\n\nexport type PropValue = string | number | boolean | null;\nexport type Props = Record<string, PropValue>;\n\n/** One event as the browser tracker sends it to the collector. */\nexport interface ClientEvent {\n event: string;\n ts?: number;\n path: string;\n title?: string;\n referrer?: string;\n utm?: Utm;\n props?: Props;\n consent: Consent;\n visitor_id?: string;\n session_id?: string;\n user_id?: string;\n}\n\nexport interface ClientBatch {\n site: string;\n events: ClientEvent[];\n}\n\n/** One row of the BigQuery `events` table. Keep in sync with sql/01_events.sql. */\nexport interface EventRow {\n ts: string;\n site: string;\n event: string;\n via: Via;\n visitor_hash: string | null;\n visitor_id: string | null;\n session_id: string | null;\n user_id: string | null;\n consent: Consent | null;\n host: string | null;\n path: string | null;\n title: string | null;\n referrer_host: string | null;\n channel: string | null;\n source: string | null;\n utm_source: string | null;\n utm_medium: string | null;\n utm_campaign: string | null;\n utm_term: string | null;\n utm_content: string | null;\n country: string | null;\n region: string | null;\n device: string | null;\n browser: string | null;\n os: string | null;\n is_bot: boolean;\n bot_name: string | null;\n bot_kind: string | null;\n user_agent: string | null;\n props: string | null;\n}\n\nexport const LIMITS = {\n bodyBytes: 8192,\n eventsPerBatch: 25,\n eventName: /^[a-zA-Z0-9_.:-]{1,64}$/,\n site: /^[a-zA-Z0-9_.-]{1,64}$/,\n id: /^[a-zA-Z0-9_.:@-]{1,128}$/,\n pathLength: 512,\n titleLength: 200,\n utmLength: 150,\n propKeys: 20,\n propKey: /^[a-zA-Z0-9_]{1,40}$/,\n propStringLength: 200,\n} as const;\n"],"mappings":";AAuEO,IAAM,SAAS;AAAA,EACpB,WAAW;AAAA,EACX,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,YAAY;AAAA,EACZ,aAAa;AAAA,EACb,WAAW;AAAA,EACX,UAAU;AAAA,EACV,SAAS;AAAA,EACT,kBAAkB;AACpB;","names":[]}
@@ -0,0 +1,39 @@
1
+ import { C as Consent, P as Props } from '../schema-1Re1Bw-P.js';
2
+
3
+ interface TrackerOptions {
4
+ /** Site label written on every row, e.g. "bmnova". */
5
+ site: string;
6
+ /** Collector URL (default "/api/collect"). */
7
+ endpoint?: string;
8
+ /** Honour Global Privacy Control / Do Not Track by staying in basic mode (default true). */
9
+ respectPrivacySignals?: boolean;
10
+ /** Capture window errors and unhandled rejections (default true). */
11
+ trackErrors?: boolean;
12
+ /** Log events to the console. */
13
+ debug?: boolean;
14
+ }
15
+ /** Send queued events. Uses sendBeacon when the page is going away. */
16
+ declare function flush(beacon?: boolean): void;
17
+ /** Start tracking. Safe to call more than once; later calls are ignored. */
18
+ declare function init(options: TrackerOptions): void;
19
+ /** Record a custom event, e.g. track("signup_started", { plan: "pro" }). */
20
+ declare function track(event: string, props?: Props): void;
21
+ /** Attach a signed-in user id (sent only with full consent). Pass null on sign-out. */
22
+ declare function identify(userId: string | null): void;
23
+ /** Record the visitor's consent choice. */
24
+ declare function setConsent(level: Consent): void;
25
+
26
+ /** The visitor's saved choice, or null if they have not chosen yet (show the banner). */
27
+ declare function getConsentChoice(): Consent | null;
28
+ /** Global Privacy Control / Do Not Track signals force basic mode. */
29
+ declare function privacySignal(): boolean;
30
+ declare function effectiveConsent(respectSignals?: boolean): Consent;
31
+ /**
32
+ * Save the visitor's choice. Remembering the choice itself is strictly necessary
33
+ * storage; ids are only created after "full".
34
+ */
35
+ declare function saveConsentChoice(level: Consent): void;
36
+ declare function onConsentChange(fn: (c: Consent) => void): () => void;
37
+
38
+ export { Consent, Props, effectiveConsent, flush, getConsentChoice, identify, init, onConsentChange, privacySignal, saveConsentChoice, setConsent, track };
39
+ export type { TrackerOptions };
@@ -0,0 +1,318 @@
1
+ import {
2
+ LIMITS
3
+ } from "../chunk-PD4SX2FD.js";
4
+
5
+ // src/client/consent.ts
6
+ var KEY = "wa_consent";
7
+ var listeners = /* @__PURE__ */ new Set();
8
+ function storage() {
9
+ try {
10
+ return typeof localStorage === "undefined" ? null : localStorage;
11
+ } catch {
12
+ return null;
13
+ }
14
+ }
15
+ function getConsentChoice() {
16
+ const v = storage()?.getItem(KEY);
17
+ return v === "full" || v === "basic" ? v : null;
18
+ }
19
+ function privacySignal() {
20
+ if (typeof navigator === "undefined") return false;
21
+ const n = navigator;
22
+ return n.globalPrivacyControl === true || n.doNotTrack === "1";
23
+ }
24
+ function effectiveConsent(respectSignals = true) {
25
+ if (respectSignals && privacySignal()) return "basic";
26
+ return getConsentChoice() ?? "basic";
27
+ }
28
+ function saveConsentChoice(level) {
29
+ const s = storage();
30
+ try {
31
+ s?.setItem(KEY, level);
32
+ if (level === "basic") {
33
+ s?.removeItem("wa_vid");
34
+ s?.removeItem("wa_sid");
35
+ }
36
+ } catch {
37
+ }
38
+ for (const fn of listeners) fn(level);
39
+ }
40
+ function onConsentChange(fn) {
41
+ listeners.add(fn);
42
+ return () => listeners.delete(fn);
43
+ }
44
+
45
+ // src/client/tracker.ts
46
+ var state = null;
47
+ var SESSION_IDLE_MS = 30 * 6e4;
48
+ function uuid() {
49
+ if (typeof crypto !== "undefined" && "randomUUID" in crypto) return crypto.randomUUID();
50
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
51
+ }
52
+ function local() {
53
+ try {
54
+ return localStorage;
55
+ } catch {
56
+ return null;
57
+ }
58
+ }
59
+ function ids() {
60
+ if (!state || state.consent !== "full") return {};
61
+ if (getConsentChoice() !== "full") {
62
+ state.consent = "basic";
63
+ return {};
64
+ }
65
+ const s = local();
66
+ if (!s) return {};
67
+ try {
68
+ let vid = s.getItem("wa_vid");
69
+ if (!vid) {
70
+ vid = uuid();
71
+ s.setItem("wa_vid", vid);
72
+ }
73
+ const now = Date.now();
74
+ let sess = null;
75
+ try {
76
+ sess = JSON.parse(s.getItem("wa_sid") ?? "null");
77
+ } catch {
78
+ sess = null;
79
+ }
80
+ if (!sess || now - sess.last > SESSION_IDLE_MS) sess = { id: uuid(), last: now };
81
+ sess.last = now;
82
+ s.setItem("wa_sid", JSON.stringify(sess));
83
+ return { visitor_id: vid, session_id: sess.id };
84
+ } catch {
85
+ return {};
86
+ }
87
+ }
88
+ function utmFromUrl() {
89
+ const q = new URLSearchParams(location.search);
90
+ const utm = {};
91
+ for (const k of ["source", "medium", "campaign", "term", "content"]) {
92
+ const v = q.get(`utm_${k}`);
93
+ if (v) utm[k] = v.slice(0, LIMITS.utmLength);
94
+ }
95
+ if (!utm.source) {
96
+ if (q.has("gclid")) utm.source = "google", utm.medium = utm.medium ?? "cpc";
97
+ else if (q.has("fbclid")) utm.source = "facebook";
98
+ else if (q.get("ref")) utm.source = q.get("ref").slice(0, LIMITS.utmLength);
99
+ }
100
+ return Object.keys(utm).length ? utm : void 0;
101
+ }
102
+ function enqueue(event, props, extra = {}) {
103
+ if (!state) return;
104
+ const e = {
105
+ event,
106
+ ts: Date.now(),
107
+ path: location.pathname,
108
+ title: document.title.slice(0, LIMITS.titleLength) || void 0,
109
+ consent: state.consent,
110
+ ...ids(),
111
+ ...state.consent === "full" && state.userId ? { user_id: state.userId } : {},
112
+ ...props ? { props } : {},
113
+ ...extra
114
+ };
115
+ if (state.opts.debug) console.log("[web-analytics]", e);
116
+ state.queue.push(e);
117
+ if (state.queue.length >= 10) flush();
118
+ else if (!state.timer) state.timer = setTimeout(() => flush(), 2e3);
119
+ }
120
+ function flush(beacon = false) {
121
+ if (!state) return;
122
+ if (state.timer) clearTimeout(state.timer);
123
+ state.timer = null;
124
+ while (state.queue.length) {
125
+ const events = state.queue.splice(0, 10);
126
+ let body = JSON.stringify({ site: state.opts.site, events });
127
+ while (body.length > LIMITS.bodyBytes && events.length > 1) {
128
+ state.queue.unshift(events.pop());
129
+ body = JSON.stringify({ site: state.opts.site, events });
130
+ }
131
+ if (body.length > LIMITS.bodyBytes) continue;
132
+ const url = state.opts.endpoint;
133
+ try {
134
+ if (beacon && navigator.sendBeacon?.(url, new Blob([body], { type: "application/json" }))) continue;
135
+ void fetch(url, {
136
+ method: "POST",
137
+ body,
138
+ headers: { "content-type": "application/json" },
139
+ keepalive: true,
140
+ credentials: "same-origin"
141
+ }).catch(() => {
142
+ });
143
+ } catch {
144
+ }
145
+ }
146
+ }
147
+ function engagedNow() {
148
+ if (!state) return 0;
149
+ return state.engagedMs + (state.visibleSince ? Date.now() - state.visibleSince : 0);
150
+ }
151
+ function sendExit() {
152
+ if (!state || state.exitSent || !state.path) return;
153
+ state.exitSent = true;
154
+ enqueue("page_exit", { engaged_ms: Math.round(engagedNow()), scroll_pct: state.maxScroll }, { path: state.path, title: state.title ?? void 0 });
155
+ }
156
+ function pageview() {
157
+ if (!state) return;
158
+ const path = location.pathname;
159
+ if (path === state.path) return;
160
+ if (state.path) sendExit();
161
+ const referrer = state.firstView ? document.referrer || void 0 : state.href ?? void 0;
162
+ state.path = path;
163
+ state.href = location.href;
164
+ state.firstView = false;
165
+ state.engagedMs = 0;
166
+ state.visibleSince = document.visibilityState === "visible" ? Date.now() : null;
167
+ state.maxScroll = 0;
168
+ state.exitSent = false;
169
+ state.errors = 0;
170
+ state.errorMessages.clear();
171
+ state.title = document.title.slice(0, LIMITS.titleLength) || null;
172
+ enqueue("pageview", void 0, { referrer, utm: utmFromUrl() });
173
+ onScroll();
174
+ }
175
+ function onScroll() {
176
+ if (!state) return;
177
+ const doc = document.documentElement;
178
+ const max = doc.scrollHeight - window.innerHeight;
179
+ const pct = max <= 0 ? 100 : Math.min(100, Math.round(window.scrollY / max * 100));
180
+ if (pct > state.maxScroll) state.maxScroll = pct;
181
+ }
182
+ function onClick(ev) {
183
+ if (!state) return;
184
+ const target = ev.target;
185
+ if (!target?.closest) return;
186
+ const tracked = target.closest("[data-track]");
187
+ if (tracked) {
188
+ const props = {};
189
+ for (const [k, v] of Object.entries(tracked.dataset)) {
190
+ if (k.startsWith("track") && k !== "track" && v !== void 0) {
191
+ const key = k.slice(5).replace(/^./, (c) => c.toLowerCase()).replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
192
+ props[key] = v;
193
+ }
194
+ }
195
+ const name = tracked.dataset.track;
196
+ if (LIMITS.eventName.test(name)) enqueue(name, Object.keys(props).length ? props : void 0);
197
+ return;
198
+ }
199
+ const a = target.closest("a[href]");
200
+ if (!a) return;
201
+ const href = a.getAttribute("href") ?? "";
202
+ if (/^mailto:/i.test(href)) return enqueue("contact_click", { type: "email" });
203
+ if (/^tel:/i.test(href)) return enqueue("contact_click", { type: "phone" });
204
+ try {
205
+ const url = new URL(a.href, location.href);
206
+ if (/^https?:$/.test(url.protocol) && url.host !== location.host) {
207
+ enqueue("outbound_click", { host: url.host.replace(/^www\./, ""), path: url.pathname.slice(0, 120) });
208
+ }
209
+ } catch {
210
+ }
211
+ }
212
+ function onError(message, source, line) {
213
+ if (!state || state.errors >= 5) return;
214
+ const msg = message.slice(0, 200);
215
+ if (state.errorMessages.has(msg)) return;
216
+ state.errors++;
217
+ state.errorMessages.add(msg);
218
+ const file = source ? source.split("?")[0].split("/").pop().slice(0, 80) : null;
219
+ enqueue("error", { kind: "client", message: msg, source: file, line: line ?? null });
220
+ }
221
+ function patchHistory() {
222
+ const w = window;
223
+ if (w.__waPatched) return;
224
+ w.__waPatched = true;
225
+ for (const method of ["pushState", "replaceState"]) {
226
+ const original = history[method];
227
+ history[method] = function(...args) {
228
+ const result = original.apply(this, args);
229
+ setTimeout(pageview, 100);
230
+ return result;
231
+ };
232
+ }
233
+ addEventListener("popstate", () => pageview());
234
+ }
235
+ function init(options) {
236
+ if (typeof window === "undefined" || state) return;
237
+ const opts = {
238
+ endpoint: "/api/collect",
239
+ respectPrivacySignals: true,
240
+ trackErrors: true,
241
+ debug: false,
242
+ ...options
243
+ };
244
+ state = {
245
+ opts,
246
+ consent: effectiveConsent(opts.respectPrivacySignals),
247
+ userId: null,
248
+ queue: [],
249
+ timer: null,
250
+ path: null,
251
+ title: null,
252
+ href: null,
253
+ firstView: true,
254
+ visibleSince: null,
255
+ engagedMs: 0,
256
+ maxScroll: 0,
257
+ exitSent: false,
258
+ errors: 0,
259
+ errorMessages: /* @__PURE__ */ new Set()
260
+ };
261
+ onConsentChange(() => {
262
+ if (state) state.consent = effectiveConsent(state.opts.respectPrivacySignals);
263
+ });
264
+ patchHistory();
265
+ addEventListener("scroll", onScroll, { passive: true });
266
+ addEventListener("click", onClick, { capture: true });
267
+ document.addEventListener("visibilitychange", () => {
268
+ if (!state) return;
269
+ if (document.visibilityState === "hidden") {
270
+ if (state.visibleSince) state.engagedMs += Date.now() - state.visibleSince;
271
+ state.visibleSince = null;
272
+ sendExit();
273
+ flush(true);
274
+ } else {
275
+ state.visibleSince = Date.now();
276
+ state.exitSent = false;
277
+ }
278
+ });
279
+ addEventListener("pagehide", () => {
280
+ sendExit();
281
+ flush(true);
282
+ });
283
+ if (opts.trackErrors) {
284
+ addEventListener("error", (e) => {
285
+ if (e instanceof ErrorEvent && e.message) onError(e.message, e.filename, e.lineno);
286
+ });
287
+ addEventListener("unhandledrejection", (e) => {
288
+ const r = e.reason;
289
+ onError(`Unhandled rejection: ${r?.message ?? String(e.reason)}`);
290
+ });
291
+ }
292
+ window.webAnalytics = { track, identify, setConsent };
293
+ pageview();
294
+ }
295
+ function track(event, props) {
296
+ if (!LIMITS.eventName.test(event)) return;
297
+ enqueue(event, props);
298
+ }
299
+ function identify(userId) {
300
+ if (!state) return;
301
+ state.userId = userId && LIMITS.id.test(userId) ? userId : null;
302
+ }
303
+ function setConsent(level) {
304
+ saveConsentChoice(level);
305
+ }
306
+ export {
307
+ effectiveConsent,
308
+ flush,
309
+ getConsentChoice,
310
+ identify,
311
+ init,
312
+ onConsentChange,
313
+ privacySignal,
314
+ saveConsentChoice,
315
+ setConsent,
316
+ track
317
+ };
318
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/consent.ts","../../src/client/tracker.ts"],"sourcesContent":["import type { Consent } from \"../shared/schema.js\";\n\nconst KEY = \"wa_consent\";\nconst listeners = new Set<(c: Consent) => void>();\n\nfunction storage(): Storage | null {\n try {\n return typeof localStorage === \"undefined\" ? null : localStorage;\n } catch {\n return null;\n }\n}\n\n/** The visitor's saved choice, or null if they have not chosen yet (show the banner). */\nexport function getConsentChoice(): Consent | null {\n const v = storage()?.getItem(KEY);\n return v === \"full\" || v === \"basic\" ? v : null;\n}\n\n/** Global Privacy Control / Do Not Track signals force basic mode. */\nexport function privacySignal(): boolean {\n if (typeof navigator === \"undefined\") return false;\n const n = navigator as Navigator & { globalPrivacyControl?: boolean };\n return n.globalPrivacyControl === true || n.doNotTrack === \"1\";\n}\n\nexport function effectiveConsent(respectSignals = true): Consent {\n if (respectSignals && privacySignal()) return \"basic\";\n return getConsentChoice() ?? \"basic\";\n}\n\n/**\n * Save the visitor's choice. Remembering the choice itself is strictly necessary\n * storage; ids are only created after \"full\".\n */\nexport function saveConsentChoice(level: Consent) {\n const s = storage();\n try {\n s?.setItem(KEY, level);\n if (level === \"basic\") {\n s?.removeItem(\"wa_vid\");\n s?.removeItem(\"wa_sid\");\n }\n } catch {\n // storage blocked: the choice lasts for this page only\n }\n for (const fn of listeners) fn(level);\n}\n\nexport function onConsentChange(fn: (c: Consent) => void): () => void {\n listeners.add(fn);\n return () => listeners.delete(fn);\n}\n","import { LIMITS, type ClientEvent, type Consent, type Props, type Utm } from \"../shared/schema.js\";\nimport { effectiveConsent, getConsentChoice, onConsentChange, saveConsentChoice } from \"./consent.js\";\n\nexport interface TrackerOptions {\n /** Site label written on every row, e.g. \"bmnova\". */\n site: string;\n /** Collector URL (default \"/api/collect\"). */\n endpoint?: string;\n /** Honour Global Privacy Control / Do Not Track by staying in basic mode (default true). */\n respectPrivacySignals?: boolean;\n /** Capture window errors and unhandled rejections (default true). */\n trackErrors?: boolean;\n /** Log events to the console. */\n debug?: boolean;\n}\n\ninterface State {\n opts: Required<TrackerOptions>;\n consent: Consent;\n userId: string | null;\n queue: ClientEvent[];\n timer: ReturnType<typeof setTimeout> | null;\n path: string | null;\n title: string | null;\n href: string | null;\n firstView: boolean;\n visibleSince: number | null;\n engagedMs: number;\n maxScroll: number;\n exitSent: boolean;\n errors: number;\n errorMessages: Set<string>;\n}\n\nlet state: State | null = null;\nconst SESSION_IDLE_MS = 30 * 60_000;\n\nfunction uuid(): string {\n if (typeof crypto !== \"undefined\" && \"randomUUID\" in crypto) return crypto.randomUUID();\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;\n}\n\nfunction local(): Storage | null {\n try {\n return localStorage;\n } catch {\n return null;\n }\n}\n\n/** Persistent ids exist only with full consent. */\nfunction ids(): { visitor_id?: string; session_id?: string } {\n if (!state || state.consent !== \"full\") return {};\n // Re-check the saved choice: storage may have been cleared while the page was open.\n if (getConsentChoice() !== \"full\") {\n state.consent = \"basic\";\n return {};\n }\n const s = local();\n if (!s) return {};\n try {\n let vid = s.getItem(\"wa_vid\");\n if (!vid) {\n vid = uuid();\n s.setItem(\"wa_vid\", vid);\n }\n const now = Date.now();\n let sess: { id: string; last: number } | null = null;\n try {\n sess = JSON.parse(s.getItem(\"wa_sid\") ?? \"null\");\n } catch {\n sess = null;\n }\n if (!sess || now - sess.last > SESSION_IDLE_MS) sess = { id: uuid(), last: now };\n sess.last = now;\n s.setItem(\"wa_sid\", JSON.stringify(sess));\n return { visitor_id: vid, session_id: sess.id };\n } catch {\n return {};\n }\n}\n\nfunction utmFromUrl(): Utm | undefined {\n const q = new URLSearchParams(location.search);\n const utm: Utm = {};\n for (const k of [\"source\", \"medium\", \"campaign\", \"term\", \"content\"] as const) {\n const v = q.get(`utm_${k}`);\n if (v) utm[k] = v.slice(0, LIMITS.utmLength);\n }\n // Common non-UTM click ids still tell us the source.\n if (!utm.source) {\n if (q.has(\"gclid\")) utm.source = \"google\", (utm.medium = utm.medium ?? \"cpc\");\n else if (q.has(\"fbclid\")) utm.source = \"facebook\";\n else if (q.get(\"ref\")) utm.source = q.get(\"ref\")!.slice(0, LIMITS.utmLength);\n }\n return Object.keys(utm).length ? utm : undefined;\n}\n\nfunction enqueue(event: string, props?: Props, extra: Partial<ClientEvent> = {}) {\n if (!state) return;\n const e: ClientEvent = {\n event,\n ts: Date.now(),\n path: location.pathname,\n title: document.title.slice(0, LIMITS.titleLength) || undefined,\n consent: state.consent,\n ...ids(),\n ...(state.consent === \"full\" && state.userId ? { user_id: state.userId } : {}),\n ...(props ? { props } : {}),\n ...extra,\n };\n if (state.opts.debug) console.log(\"[web-analytics]\", e);\n state.queue.push(e);\n if (state.queue.length >= 10) flush();\n else if (!state.timer) state.timer = setTimeout(() => flush(), 2000);\n}\n\n/** Send queued events. Uses sendBeacon when the page is going away. */\nexport function flush(beacon = false) {\n if (!state) return;\n if (state.timer) clearTimeout(state.timer);\n state.timer = null;\n while (state.queue.length) {\n const events = state.queue.splice(0, 10);\n let body = JSON.stringify({ site: state.opts.site, events });\n while (body.length > LIMITS.bodyBytes && events.length > 1) {\n state.queue.unshift(events.pop()!);\n body = JSON.stringify({ site: state.opts.site, events });\n }\n if (body.length > LIMITS.bodyBytes) continue; // a single oversized event is dropped\n const url = state.opts.endpoint;\n try {\n if (beacon && navigator.sendBeacon?.(url, new Blob([body], { type: \"application/json\" }))) continue;\n void fetch(url, {\n method: \"POST\",\n body,\n headers: { \"content-type\": \"application/json\" },\n keepalive: true,\n credentials: \"same-origin\",\n }).catch(() => {});\n } catch {\n // analytics must never break the page\n }\n }\n}\n\nfunction engagedNow(): number {\n if (!state) return 0;\n return state.engagedMs + (state.visibleSince ? Date.now() - state.visibleSince : 0);\n}\n\nfunction sendExit() {\n if (!state || state.exitSent || !state.path) return;\n state.exitSent = true;\n enqueue(\"page_exit\", { engaged_ms: Math.round(engagedNow()), scroll_pct: state.maxScroll }, { path: state.path, title: state.title ?? undefined });\n}\n\nfunction pageview() {\n if (!state) return;\n const path = location.pathname;\n if (path === state.path) return;\n if (state.path) sendExit();\n const referrer = state.firstView ? document.referrer || undefined : (state.href ?? undefined);\n state.path = path;\n state.href = location.href;\n state.firstView = false;\n state.engagedMs = 0;\n state.visibleSince = document.visibilityState === \"visible\" ? Date.now() : null;\n state.maxScroll = 0;\n state.exitSent = false;\n state.errors = 0;\n state.errorMessages.clear();\n state.title = document.title.slice(0, LIMITS.titleLength) || null;\n enqueue(\"pageview\", undefined, { referrer, utm: utmFromUrl() });\n onScroll();\n}\n\nfunction onScroll() {\n if (!state) return;\n const doc = document.documentElement;\n const max = doc.scrollHeight - window.innerHeight;\n const pct = max <= 0 ? 100 : Math.min(100, Math.round((window.scrollY / max) * 100));\n if (pct > state.maxScroll) state.maxScroll = pct;\n}\n\nfunction onClick(ev: MouseEvent) {\n if (!state) return;\n const target = ev.target as Element | null;\n if (!target?.closest) return;\n const tracked = target.closest<HTMLElement>(\"[data-track]\");\n if (tracked) {\n const props: Props = {};\n for (const [k, v] of Object.entries(tracked.dataset)) {\n if (k.startsWith(\"track\") && k !== \"track\" && v !== undefined) {\n const key = k.slice(5).replace(/^./, (c) => c.toLowerCase()).replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);\n props[key] = v;\n }\n }\n const name = tracked.dataset.track!;\n if (LIMITS.eventName.test(name)) enqueue(name, Object.keys(props).length ? props : undefined);\n return;\n }\n const a = target.closest<HTMLAnchorElement>(\"a[href]\");\n if (!a) return;\n const href = a.getAttribute(\"href\") ?? \"\";\n if (/^mailto:/i.test(href)) return enqueue(\"contact_click\", { type: \"email\" });\n if (/^tel:/i.test(href)) return enqueue(\"contact_click\", { type: \"phone\" });\n try {\n const url = new URL(a.href, location.href);\n if (/^https?:$/.test(url.protocol) && url.host !== location.host) {\n enqueue(\"outbound_click\", { host: url.host.replace(/^www\\./, \"\"), path: url.pathname.slice(0, 120) });\n }\n } catch {\n // ignore malformed links\n }\n}\n\nfunction onError(message: string, source?: string, line?: number) {\n if (!state || state.errors >= 5) return;\n const msg = message.slice(0, 200);\n if (state.errorMessages.has(msg)) return;\n state.errors++;\n state.errorMessages.add(msg);\n const file = source ? source.split(\"?\")[0]!.split(\"/\").pop()!.slice(0, 80) : null;\n enqueue(\"error\", { kind: \"client\", message: msg, source: file, line: line ?? null });\n}\n\nfunction patchHistory() {\n const w = window as Window & { __waPatched?: boolean };\n if (w.__waPatched) return;\n w.__waPatched = true;\n for (const method of [\"pushState\", \"replaceState\"] as const) {\n const original = history[method];\n history[method] = function (this: History, ...args: Parameters<History[\"pushState\"]>) {\n const result = original.apply(this, args);\n setTimeout(pageview, 100);\n return result;\n } as History[\"pushState\"];\n }\n addEventListener(\"popstate\", () => pageview());\n}\n\n/** Start tracking. Safe to call more than once; later calls are ignored. */\nexport function init(options: TrackerOptions) {\n if (typeof window === \"undefined\" || state) return;\n const opts: Required<TrackerOptions> = {\n endpoint: \"/api/collect\",\n respectPrivacySignals: true,\n trackErrors: true,\n debug: false,\n ...options,\n };\n state = {\n opts,\n consent: effectiveConsent(opts.respectPrivacySignals),\n userId: null,\n queue: [],\n timer: null,\n path: null,\n title: null,\n href: null,\n firstView: true,\n visibleSince: null,\n engagedMs: 0,\n maxScroll: 0,\n exitSent: false,\n errors: 0,\n errorMessages: new Set(),\n };\n\n onConsentChange(() => {\n if (state) state.consent = effectiveConsent(state.opts.respectPrivacySignals);\n });\n patchHistory();\n addEventListener(\"scroll\", onScroll, { passive: true });\n addEventListener(\"click\", onClick, { capture: true });\n document.addEventListener(\"visibilitychange\", () => {\n if (!state) return;\n if (document.visibilityState === \"hidden\") {\n if (state.visibleSince) state.engagedMs += Date.now() - state.visibleSince;\n state.visibleSince = null;\n sendExit();\n flush(true);\n } else {\n state.visibleSince = Date.now();\n state.exitSent = false; // a later hide reports the updated engagement\n }\n });\n addEventListener(\"pagehide\", () => {\n sendExit();\n flush(true);\n });\n if (opts.trackErrors) {\n addEventListener(\"error\", (e) => {\n if (e instanceof ErrorEvent && e.message) onError(e.message, e.filename, e.lineno);\n });\n addEventListener(\"unhandledrejection\", (e) => {\n const r = e.reason as { message?: string } | undefined;\n onError(`Unhandled rejection: ${r?.message ?? String(e.reason)}`);\n });\n }\n (window as Window & { webAnalytics?: unknown }).webAnalytics = { track, identify, setConsent };\n pageview();\n}\n\n/** Record a custom event, e.g. track(\"signup_started\", { plan: \"pro\" }). */\nexport function track(event: string, props?: Props) {\n if (!LIMITS.eventName.test(event)) return;\n enqueue(event, props);\n}\n\n/** Attach a signed-in user id (sent only with full consent). Pass null on sign-out. */\nexport function identify(userId: string | null) {\n if (!state) return;\n state.userId = userId && LIMITS.id.test(userId) ? userId : null;\n}\n\n/** Record the visitor's consent choice. */\nexport function setConsent(level: Consent) {\n saveConsentChoice(level);\n}\n"],"mappings":";;;;;AAEA,IAAM,MAAM;AACZ,IAAM,YAAY,oBAAI,IAA0B;AAEhD,SAAS,UAA0B;AACjC,MAAI;AACF,WAAO,OAAO,iBAAiB,cAAc,OAAO;AAAA,EACtD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGO,SAAS,mBAAmC;AACjD,QAAM,IAAI,QAAQ,GAAG,QAAQ,GAAG;AAChC,SAAO,MAAM,UAAU,MAAM,UAAU,IAAI;AAC7C;AAGO,SAAS,gBAAyB;AACvC,MAAI,OAAO,cAAc,YAAa,QAAO;AAC7C,QAAM,IAAI;AACV,SAAO,EAAE,yBAAyB,QAAQ,EAAE,eAAe;AAC7D;AAEO,SAAS,iBAAiB,iBAAiB,MAAe;AAC/D,MAAI,kBAAkB,cAAc,EAAG,QAAO;AAC9C,SAAO,iBAAiB,KAAK;AAC/B;AAMO,SAAS,kBAAkB,OAAgB;AAChD,QAAM,IAAI,QAAQ;AAClB,MAAI;AACF,OAAG,QAAQ,KAAK,KAAK;AACrB,QAAI,UAAU,SAAS;AACrB,SAAG,W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AAK,IAAI,IAAI,MAAM;AAC9D,YAAM,eAAe;AACrB,eAAS;AACT,YAAM,IAAI;AAAA,IACZ,OAAO;AACL,YAAM,eAAe,KAAK,IAAI;AAC9B,YAAM,WAAW;AAAA,IACnB;AAAA,EACF,CAAC;AACD,mBAAiB,YAAY,MAAM;AACjC,aAAS;AACT,UAAM,IAAI;AAAA,EACZ,CAAC;AACD,MAAI,KAAK,aAAa;AACpB,qBAAiB,SAAS,CAAC,MAAM;AAC/B,UAAI,aAAa,cAAc,EAAE,QAAS,SAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM;AAAA,IACnF,CAAC;AACD,qBAAiB,sBAAsB,CAAC,MAAM;AAC5C,YAAM,IAAI,EAAE;AACZ,cAAQ,wBAAwB,GAAG,WAAW,OAAO,EAAE,MAAM,CAAC,EAAE;AAAA,IAClE,CAAC;AAAA,EACH;AACA,EAAC,OAA+C,eAAe,EAAE,OAAO,UAAU,WAAW;AAC7F,WAAS;AACX;AAGO,SAAS,MAAM,OAAe,OAAe;AAClD,MAAI,CAAC,OAAO,UAAU,KAAK,KAAK,EAAG;AACnC,UAAQ,OAAO,KAAK;AACtB;AAGO,SAAS,SAAS,QAAuB;AAC9C,MAAI,CAAC,MAAO;AACZ,QAAM,SAAS,UAAU,OAAO,GAAG,KAAK,MAAM,IAAI,SAAS;AAC7D;AAGO,SAAS,WAAW,OAAgB;AACzC,oBAAkB,KAAK;AACzB;","names":[]}
@@ -0,0 +1,30 @@
1
+ import { TrackerOptions } from '@bmnova/web-analytics/client';
2
+ export { getConsentChoice, identify, setConsent, track } from '@bmnova/web-analytics/client';
3
+ import * as react from 'react';
4
+ import { ReactNode } from 'react';
5
+
6
+ interface AnalyticsProps extends TrackerOptions {
7
+ /** Microsoft Clarity project id. Loaded only after the visitor gives full consent. */
8
+ clarityId?: string;
9
+ }
10
+ /** Mount once in the root layout: <Analytics site="mysite" /> */
11
+ declare function Analytics({ clarityId, ...options }: AnalyticsProps): null;
12
+
13
+ interface ConsentBannerProps {
14
+ message?: ReactNode;
15
+ acceptLabel?: string;
16
+ rejectLabel?: string;
17
+ policyHref?: string;
18
+ policyLabel?: string;
19
+ /** Drop the built-in inline styles and style via the wa-consent* class names. */
20
+ unstyled?: boolean;
21
+ className?: string;
22
+ }
23
+ /**
24
+ * Shown until the visitor chooses. Both buttons are equally prominent, and
25
+ * rejecting keeps the cookieless basic mode (no storage besides the choice).
26
+ */
27
+ declare function ConsentBanner({ message, acceptLabel, rejectLabel, policyHref, policyLabel, unstyled, className, }: ConsentBannerProps): react.JSX.Element | null;
28
+
29
+ export { Analytics, ConsentBanner };
30
+ export type { AnalyticsProps, ConsentBannerProps };
@@ -0,0 +1,106 @@
1
+ "use client";
2
+
3
+ // src/react/Analytics.tsx
4
+ import { useEffect, useState } from "react";
5
+ import { init } from "@bmnova/web-analytics/client";
6
+ import { effectiveConsent, onConsentChange } from "@bmnova/web-analytics/client";
7
+ var CLARITY_ID = /^[a-z0-9]{6,20}$/i;
8
+ function loadClarity(id) {
9
+ if (!CLARITY_ID.test(id) || document.getElementById("wa-clarity")) return;
10
+ const w = window;
11
+ w.clarity = w.clarity || function(...args) {
12
+ (w.clarity.q = w.clarity.q || []).push(args);
13
+ };
14
+ const s = document.createElement("script");
15
+ s.id = "wa-clarity";
16
+ s.async = true;
17
+ s.src = `https://www.clarity.ms/tag/${id}`;
18
+ document.head.appendChild(s);
19
+ }
20
+ function Analytics({ clarityId, ...options }) {
21
+ const [full, setFull] = useState(false);
22
+ useEffect(() => {
23
+ init(options);
24
+ const respect = options.respectPrivacySignals ?? true;
25
+ setFull(effectiveConsent(respect) === "full");
26
+ return onConsentChange(() => setFull(effectiveConsent(respect) === "full"));
27
+ }, []);
28
+ useEffect(() => {
29
+ if (full && clarityId) loadClarity(clarityId);
30
+ }, [full, clarityId]);
31
+ return null;
32
+ }
33
+
34
+ // src/react/ConsentBanner.tsx
35
+ import { useEffect as useEffect2, useState as useState2 } from "react";
36
+ import { getConsentChoice, privacySignal, saveConsentChoice } from "@bmnova/web-analytics/client";
37
+ import { jsx, jsxs } from "react/jsx-runtime";
38
+ var styles = {
39
+ root: {
40
+ position: "fixed",
41
+ insetInline: "16px",
42
+ bottom: "16px",
43
+ zIndex: 2147483e3,
44
+ maxWidth: "560px",
45
+ marginInline: "auto",
46
+ padding: "14px 16px",
47
+ borderRadius: "12px",
48
+ background: "rgba(20,20,22,0.96)",
49
+ color: "#f5f5f5",
50
+ font: "14px/1.45 system-ui, -apple-system, Segoe UI, sans-serif",
51
+ boxShadow: "0 8px 30px rgba(0,0,0,.25)",
52
+ display: "flex",
53
+ flexWrap: "wrap",
54
+ gap: "12px",
55
+ alignItems: "center"
56
+ },
57
+ text: { flex: "1 1 260px", margin: 0 },
58
+ link: { color: "inherit", textDecoration: "underline" },
59
+ actions: { display: "flex", gap: "8px", flexShrink: 0 },
60
+ reject: { padding: "8px 14px", borderRadius: "8px", border: "1px solid #666", background: "transparent", color: "inherit", cursor: "pointer", font: "inherit" },
61
+ accept: { padding: "8px 14px", borderRadius: "8px", border: 0, background: "#f5f5f5", color: "#111", cursor: "pointer", font: "inherit", fontWeight: 600 }
62
+ };
63
+ function ConsentBanner({
64
+ message = "We use privacy-friendly analytics. With your OK we also remember your visits to understand how the site is used.",
65
+ acceptLabel = "Accept",
66
+ rejectLabel = "Reject",
67
+ policyHref,
68
+ policyLabel = "Privacy policy",
69
+ unstyled = false,
70
+ className
71
+ }) {
72
+ const [open, setOpen] = useState2(false);
73
+ useEffect2(() => {
74
+ setOpen(getConsentChoice() === null && !privacySignal());
75
+ }, []);
76
+ if (!open) return null;
77
+ const s = (k) => unstyled ? void 0 : styles[k];
78
+ const choose = (level) => {
79
+ saveConsentChoice(level);
80
+ setOpen(false);
81
+ };
82
+ return /* @__PURE__ */ jsxs("div", { role: "dialog", "aria-live": "polite", "aria-label": "Analytics consent", className: ["wa-consent", className].filter(Boolean).join(" "), style: s("root"), children: [
83
+ /* @__PURE__ */ jsxs("p", { className: "wa-consent__text", style: s("text"), children: [
84
+ message,
85
+ " ",
86
+ policyHref ? /* @__PURE__ */ jsx("a", { className: "wa-consent__link", href: policyHref, style: s("link"), children: policyLabel }) : null
87
+ ] }),
88
+ /* @__PURE__ */ jsxs("div", { className: "wa-consent__actions", style: s("actions"), children: [
89
+ /* @__PURE__ */ jsx("button", { type: "button", className: "wa-consent__reject", style: s("reject"), onClick: () => choose("basic"), children: rejectLabel }),
90
+ /* @__PURE__ */ jsx("button", { type: "button", className: "wa-consent__accept", style: s("accept"), onClick: () => choose("full"), children: acceptLabel })
91
+ ] })
92
+ ] });
93
+ }
94
+
95
+ // src/react/index.ts
96
+ import { track, identify, setConsent } from "@bmnova/web-analytics/client";
97
+ import { getConsentChoice as getConsentChoice2 } from "@bmnova/web-analytics/client";
98
+ export {
99
+ Analytics,
100
+ ConsentBanner,
101
+ getConsentChoice2 as getConsentChoice,
102
+ identify,
103
+ setConsent,
104
+ track
105
+ };
106
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/react/Analytics.tsx","../../src/react/ConsentBanner.tsx","../../src/react/index.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport { init, type TrackerOptions } from \"@bmnova/web-analytics/client\";\nimport { effectiveConsent, onConsentChange } from \"@bmnova/web-analytics/client\";\n\nexport interface AnalyticsProps extends TrackerOptions {\n /** Microsoft Clarity project id. Loaded only after the visitor gives full consent. */\n clarityId?: string;\n}\n\nconst CLARITY_ID = /^[a-z0-9]{6,20}$/i;\n\nfunction loadClarity(id: string) {\n if (!CLARITY_ID.test(id) || document.getElementById(\"wa-clarity\")) return;\n const w = window as Window & { clarity?: ((...a: unknown[]) => void) & { q?: unknown[] } };\n w.clarity =\n w.clarity ||\n function (...args: unknown[]) {\n (w.clarity!.q = w.clarity!.q || []).push(args);\n };\n const s = document.createElement(\"script\");\n s.id = \"wa-clarity\";\n s.async = true;\n s.src = `https://www.clarity.ms/tag/${id}`;\n document.head.appendChild(s);\n}\n\n/** Mount once in the root layout: <Analytics site=\"mysite\" /> */\nexport function Analytics({ clarityId, ...options }: AnalyticsProps) {\n const [full, setFull] = useState(false);\n\n useEffect(() => {\n init(options);\n const respect = options.respectPrivacySignals ?? true;\n setFull(effectiveConsent(respect) === \"full\");\n return onConsentChange(() => setFull(effectiveConsent(respect) === \"full\"));\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n useEffect(() => {\n if (full && clarityId) loadClarity(clarityId);\n }, [full, clarityId]);\n\n return null;\n}\n","import { useEffect, useState, type CSSProperties, type ReactNode } from \"react\";\nimport { getConsentChoice, privacySignal, saveConsentChoice } from \"@bmnova/web-analytics/client\";\n\nexport interface ConsentBannerProps {\n message?: ReactNode;\n acceptLabel?: string;\n rejectLabel?: string;\n policyHref?: string;\n policyLabel?: string;\n /** Drop the built-in inline styles and style via the wa-consent* class names. */\n unstyled?: boolean;\n className?: string;\n}\n\nconst styles: Record<string, CSSProperties> = {\n root: {\n position: \"fixed\",\n insetInline: \"16px\",\n bottom: \"16px\",\n zIndex: 2147483000,\n maxWidth: \"560px\",\n marginInline: \"auto\",\n padding: \"14px 16px\",\n borderRadius: \"12px\",\n background: \"rgba(20,20,22,0.96)\",\n color: \"#f5f5f5\",\n font: \"14px/1.45 system-ui, -apple-system, Segoe UI, sans-serif\",\n boxShadow: \"0 8px 30px rgba(0,0,0,.25)\",\n display: \"flex\",\n flexWrap: \"wrap\",\n gap: \"12px\",\n alignItems: \"center\",\n },\n text: { flex: \"1 1 260px\", margin: 0 },\n link: { color: \"inherit\", textDecoration: \"underline\" },\n actions: { display: \"flex\", gap: \"8px\", flexShrink: 0 },\n reject: { padding: \"8px 14px\", borderRadius: \"8px\", border: \"1px solid #666\", background: \"transparent\", color: \"inherit\", cursor: \"pointer\", font: \"inherit\" },\n accept: { padding: \"8px 14px\", borderRadius: \"8px\", border: 0, background: \"#f5f5f5\", color: \"#111\", cursor: \"pointer\", font: \"inherit\", fontWeight: 600 },\n};\n\n/**\n * Shown until the visitor chooses. Both buttons are equally prominent, and\n * rejecting keeps the cookieless basic mode (no storage besides the choice).\n */\nexport function ConsentBanner({\n message = \"We use privacy-friendly analytics. With your OK we also remember your visits to understand how the site is used.\",\n acceptLabel = \"Accept\",\n rejectLabel = \"Reject\",\n policyHref,\n policyLabel = \"Privacy policy\",\n unstyled = false,\n className,\n}: ConsentBannerProps) {\n const [open, setOpen] = useState(false);\n\n useEffect(() => {\n setOpen(getConsentChoice() === null && !privacySignal());\n }, []);\n\n if (!open) return null;\n const s = (k: string) => (unstyled ? undefined : styles[k]);\n const choose = (level: \"full\" | \"basic\") => {\n saveConsentChoice(level);\n setOpen(false);\n };\n\n return (\n <div role=\"dialog\" aria-live=\"polite\" aria-label=\"Analytics consent\" className={[\"wa-consent\", className].filter(Boolean).join(\" \")} style={s(\"root\")}>\n <p className=\"wa-consent__text\" style={s(\"text\")}>\n {message}{\" \"}\n {policyHref ? (\n <a className=\"wa-consent__link\" href={policyHref} style={s(\"link\")}>\n {policyLabel}\n </a>\n ) : null}\n </p>\n <div className=\"wa-consent__actions\" style={s(\"actions\")}>\n <button type=\"button\" className=\"wa-consent__reject\" style={s(\"reject\")} onClick={() => choose(\"basic\")}>\n {rejectLabel}\n </button>\n <button type=\"button\" className=\"wa-consent__accept\" style={s(\"accept\")} onClick={() => choose(\"full\")}>\n {acceptLabel}\n </button>\n </div>\n </div>\n );\n}\n","export { Analytics, type AnalyticsProps } from \"./Analytics.js\";\nexport { ConsentBanner, type ConsentBannerProps } from \"./ConsentBanner.js\";\nexport { track, identify, setConsent } from \"@bmnova/web-analytics/client\";\nexport { getConsentChoice } from \"@bmnova/web-analytics/client\";\n"],"mappings":";;;AAAA,SAAS,WAAW,gBAAgB;AACpC,SAAS,YAAiC;AAC1C,SAAS,kBAAkB,uBAAuB;AAOlD,IAAM,aAAa;AAEnB,SAAS,YAAY,IAAY;AAC/B,MAAI,CAAC,WAAW,KAAK,EAAE,KAAK,SAAS,eAAe,YAAY,E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