Repository navigation
feat: visit analytics - #1067
Brooooooklyn wants to merge 18 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Cloudflare builds and deploys previews for this pull request. Learn more about Cloudflare previews.
Updated: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d666171ca
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
0745485 to
74f34c9
Compare
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>
Dispatch now marks a request as a page view and adds blobs 7-15 (kind, path, host, referrer host, country, device, browser, bot label, bot group) and doubles 4-5 ([.., 0, 1]) to the one usage row it already writes. Rows that are not views keep the 6-blob, 3-double shape, so billing is unchanged. - page-view.ts: classifyPageView (GET only, no previews, no prefetch markers, 2xx except 204/206 or 304, HTML document loads and Void Pages client navigations incl. /_void/pages/*.json, monitors dropped). - analytics-setting.ts: per-project off switch read from the project-analytics-off:<id> ROUTING key, cached 60s per isolate; a read error counts as off. - metering.ts: optional view; path capped at 512 bytes; path and referrer blank in minimal runtime-logs mode. - index.ts: still exactly one row per request; written from waitUntil only when the setting read is still pending. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tic deploys - A Void Pages client navigation that hits a redirect gets a 200 with X-VoidPages-Redirect and Location; the client then fetches the target. Do not count that 200 as a view of the source page. - output: "static" apps with no backend deploy as routing type static. Count their /_void/pages/*.json page-data fetches as nav views too. The X-VoidPages rule stays void-only: a static deploy answers it with HTML and the client follows with the page-data file. - Skip classifyPageView when the project is known to have analytics off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… page data An X-VoidPages request answered with HTML or the stale-build reload answer is followed by a page-data file fetch or a full page load, which is the counted view. Counting both counted one visit twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dynamic X-VoidPages prefetch already sends Purpose: prefetch, but the static /_void/pages/*.json fetch did not, both on the fast path and when the HTML answer has deferred props. Pass the purpose through loadStaticPageData and loadStaticPageDataFile so every prefetch request says so, and a visit never does. The header does not change the static file or its cache key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the fast-path static JSON fetch misses and the dynamic GET returns HTML, loadStaticPageData fetches the static file again. Run the HTML-first Purpose test with the fast path on too, so that retry must carry Purpose: prefetch for a prefetch and no Purpose for a visit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Pages navigation answered with a static HTML page often makes no other request: the client reads the page data embedded in the HTML. Count that answer as the view, and mark the page-data file fetch that can follow it with X-VoidPages-Followup so dispatch does not count the same navigation twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GET /projects/:id/analytics reads the dispatch page-view fields in void_requests (series by bot label, top pages, referrers, countries, devices, browsers) for 24h/7d/30d/90d with host, path and traffic filters. PUT /projects/:id/analytics/settings stores projects.analytics_enabled (migration 0068, default true) and the ROUTING marker dispatch reads; project deletion removes the marker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…past 0068 - Minimal runtime-log mode now hides referrers as well as paths: no referrer query is sent and `referrers` is null, so rows stored before the switch no longer show referrer hosts. - `traffic` filters only the five top lists. `totals.views`, `series[].views`, `documentViews` and `navViews` count humans and bots, so `views = humanViews + botViews` as the API contract says. - Record 1.13.0 and 1.13.1 (schema 0000..0067) as rollback-safe for migration 0068 and cover it in the upgrade compatibility test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add /projects/:slug/analytics: range links and a plain GET filter form (host, which visitors the top lists count), stat tiles with the sampled mark, views over time with bots shaded, a stacked bar per bucket for humans and each bot label, top lists, and the on/off switch for owners and admins. The loader drops a range, traffic or host the API would refuse before calling it; a hostname that is not one of the project's hosts falls back to all hosts with a notice. Charts are inline SVG with no new dependency: role="img" with a summary label, a legend, a "Show numbers" table, and colors as --chart-1..6 tokens with dark-mode steps. findProject moves to lib/projects.ts so the security and analytics pages share it, and both get project tabs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…le check - Read `?done=` from the copy's own keys only, so `?done=constructor` shows no notice instead of failing the page. - Name the chart's folded bot series "More bots", apart from the API's "Other bots" row in the list, and drop the "Other bots" group line from named bots in the `other` group. - Use the shared `canChangeSettings` on the security page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reads GET /projects/:id/analytics and prints totals, a trend line, top pages / referrers / countries (side by side when they fit), devices, browsers and AI & bots. `on` and `off` call the settings route. Every visitor-set string goes through cleanLine. Direct Cloudflare projects get a clear message for now; analytics.ts holds that branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e older double count Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…or direct deploys A direct Cloudflare deploy now reads page loads for its custom domains and zone routes from the user's own zone (httpRequestsAdaptiveGroups over GraphQL, one request per zone). It only reads: no binding, deploy step or entitlement probe, so Workers Free apps keep working. - OAuth logins need analytics.read; API tokens get a permission hint on authz; a Global API Key is refused by name. - 24h reads hours, 7d folds hours into 6h buckets, 30d reads days; 90d is refused (Cloudflare keeps 31 days). - Bots are split with the shared user-agent parser plus Cloudflare's verified bot category. - email-cloudflare exports zoneCandidates and the /zones?name= read without changing email behaviour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…deploys Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e --traffic wording Zone analytics filter by host, so a route such as example.com/blog/* would count every page on that host. Such a route is now skipped with a note unless a custom domain or a whole-host route covers the host. A custom domain set as the singular `route` is now read. The help text and docs now say that only the human count leaves out bots found by user agent, that `--traffic bots` lists only bots Cloudflare verifies, and that on/off stop with an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55369ae to
4e0ba1a
Compare
Server-side visit analytics for Void. This replaces #1064, #1065 and #1066, and the rest of the work lands on this branch too.
Decisions: server-side only (no browser script), page views only (no unique-visitor counting), on by default with a per-project off switch, no paths or referrers in
--runtime-logs minimalmode, and bot labels from the user agent.Steps
@void/edge/visit-analyticsexportsparseUserAgent()(device, browser, bot label, bot group; no regex, no new dependency) plusVISIT_RANGESandbotGroupName()./_void/pages/*.jsonprefetch now sendsPurpose: prefetch, like the dynamic prefetch already did, so the server can tell it from a visit.double5 = 1to the existing row. Rows that are not views keep today's exact shape, anddouble4stays 0 because the proxy uses it. Off switch: the ROUTING keyproject-analytics-off:<id>, cached 60s.GET /projects/:id/analytics(readpermission). Ranges are24h|7d|30d|90d, withhost,pathandtrafficfilters, validated before any Analytics Engine call. It returns totals, a series, the bot split, and top pages, referrers, countries, devices and browsers.PUT /projects/:id/analytics/settings(settingspermission) writesprojects.analytics_enabled(migration 0068, default true) and the KV off marker. Minimal mode hides paths and referrers, including older rows. A 1.13.x compatibility entry lets those installs upgrade past 0068./projects/:slug/analyticsadds stat tiles, an area chart of views, a stacked bar chart of humans vs bot labels, and top lists. The charts are inline SVG with a "Show numbers" table, they work without JS, and they have dark-mode tokens. The range, host and traffic filters use a plain GET form. Owners and admins get an on/off switch. The page handles the off, minimal-mode, empty and unavailable states. It adds an Analytics tab next to Security.void project analytics [on|off] [--range] [--host] [--path] [--traffic] [--json]. Every visitor string goes throughcleanLine. Docs: a new guidedocs/guide/analytics.md, the CLI reference, the help text and hint,setup.md(minimal mode), roles, and the skill.void deploy --platform cloudflareapps,void project analyticsreads the app's own zonehttpRequestsAdaptiveGroups(HTML GET 2xx,requestSource: eyeball) for the app's custom domains and whole-host zone routes. It shows page loads only, with no referrers (Free zones refuse that field) and 31 days of history. OAuth logins needanalytics.read; API tokens get a "Zone → Analytics → Read" hint. Read-only: no binding, deploy step or probe is added, so it stays Workers Free compatible. A regression test checks the native config is unchanged. Checked live, read-only, on the test zone.What counts as a view (step 3)
Purpose,Sec-Purpose,X-Moz,X-Purpose)/_void/pages/*.jsononvoidorstaticapps, mapped back to its pageX-VoidPages-Redirect)X-VoidPages-Followup)Tests
packages/edge/test/unit/visit-analytics.test.ts: 99 cases built from real UAspackages/void/test/unit/pages-client.test.ts: prefetch sendsPurpose, a visit doesn't (fast path off and on)platform/packages/dispatch: newpage-view.test.ts, plus updates tometering.test.tsandindex.test.ts; 913 passedvp check: cleanvp run test: 202/202 (one full run, 88% not from cache)🤖 Generated with Claude Code