Skip to content

feat(edge): add visit-analytics user-agent parser and range table - #1064

Closed
Brooooooklyn wants to merge 2 commits into
mainfrom
feat/visit-analytics-ua-parser
Closed

Brooooooklyn wants to merge 2 commits into
mainfrom
feat/visit-analytics-ua-parser

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

First step of visit analytics. This adds a shared helper that later PRs use in dispatch, the platform API, the dashboard and the CLI. Nothing imports it yet.

What's new

@void/edge/visit-analytics (its own subpath, so dispatch doesn't pull in the routing runtime):

parseUserAgent(ua, secChUaMobile?, secChUa?)
  → { device: desktop|mobile|tablet|bot|unknown,
      browser: 'Chrome' | 'Bot' | 'Other' | …,
      botLabel: 'GPTBot' | '' ,
      group: ai|search|social|seo|monitor|tool|other|'' }

VISIT_RANGES   24h (1h × 24) · 7d (6h × 28) · 30d (1d × 30) · 90d (1d × 90, hosted only)
botGroupName() friendly group names
isVisitRangeId()
  • No regex and no new dependency. It uses ordered token lists checked with includes(), and the first match wins.
  • AI bot names follow Cloudflare's AI Crawl Control list (GPTBot, ChatGPT-User, OAI-SearchBot, ClaudeBot, Claude-User, Claude-SearchBot, PerplexityBot, Meta-ExternalAgent, Applebot-Extended, …).
  • Bots are matched first, so a crawler that sends a Chrome-style UA is reported as bot / Bot.
  • The monitor group (UptimeRobot, Pingdom, Cloudflare Health Checks, …) is the one dispatch will drop as a probe.
  • Node's own fetch() UA (node) is matched as an exact string, so it counts as a tool, not a human.
  • packages/edge/vite.config.ts adds the second pack entry. dist/index.mjs is unchanged in size, and dist/visit-analytics.mjs (about 10 kB) imports nothing.

Tests

packages/edge/test/unit/visit-analytics.test.ts has 99 cases built from a table of real UAs: each AI and search bot, Edge vs Chrome vs Safari, CriOS, Samsung, Brave via Sec-CH-UA, Sec-CH-UA-Mobile: ?1, the Cubot phone (not a bot), empty UA, HeadlessChrome, Lighthouse and monitors.

  • vp test run packages/edge/test/unit/visit-analytics.test.ts: 99/99
  • vp check: clean
  • vp run test: 200/200 tasks

🤖 Generated with Claude Code

Brooooooklyn and others added 2 commits December 6, 2026 18:10
Add `@void/edge/visit-analytics`, a small pure module the platform will use
for visit analytics:

- parseUserAgent(ua, secChUaMobile?, secChUa?) returns device, browser,
  bot label and bot group (ai/search/social/seo/monitor/tool/other). It
  lowercases once and checks ordered token lists with includes(); the
  first match wins. No regex, no new dependency.
- VISIT_RANGES (24h, 7d, 30d, 90d hosted-only) and isVisitRangeId().
- botGroupName() friendly group names for the dashboard and CLI.

The module is its own pack entry and subpath export, so the dispatch
worker can import it without the routing and static-asset runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… archive.org_bot

- Node's built-in fetch() sends `User-Agent: node`; match that whole UA as a
  `tool` (not with includes(), so device names containing "node" stay human).
- Chrome-Lighthouse (PageSpeed Insights) is a tool, not a Chrome view.
- Cloudflare-Healthchecks is a monitor, so dispatch drops it as a probe.
- archive.org_bot gets a named token; the generic label cut it at the dot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Brooooooklyn
Brooooooklyn requested a review from a team as a code owner December 6, 2026 10:29
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-06T10:30:34.038944Z 90a3f5e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Cloudflare builds and deploys previews for this pull request. Learn more about Cloudflare previews.

Worker Status Deployment Commit
void-cloud Deployed Preview 90a3f5e

Updated: Dec 6, 2026, 10:29 UTC | Dashboard

@Brooooooklyn

Copy link
Copy Markdown
Member Author

Combined into #1067 (visit analytics, one PR). All commits from this PR are on that branch.

@Brooooooklyn
Brooooooklyn deleted the feat/visit-analytics-ua-parser branch December 6, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant