Skip to content

feat(dispatch): record page-view fields on the usage row - #1066

Closed
Brooooooklyn wants to merge 3 commits into
feat/visit-analytics-ua-parserfrom
feat/visit-analytics-dispatch
Closed

Brooooooklyn wants to merge 3 commits into
feat/visit-analytics-ua-parserfrom
feat/visit-analytics-dispatch

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Step 3 of visit analytics. Stacked on #1064 (the user-agent parser), so review and merge that first.

Dispatch now adds page-view fields to the void_requests row it already writes. There is still exactly one row per request, so billing and usage queries don't change.

visitor ─► dispatch ─► meter(response)
                        ├─ not a view / analytics off ─► same row as today (6 blobs, 3 doubles)
                        ├─ view, setting known: on    ─► row + blobs 7-15, double5 = 1
                        └─ view, setting loading      ─► ctx.waitUntil → one row

Row layout (new slots only)

Slot Field Example
blob7 view kind document / nav
blob8 path, no query, max 512 bytes ('' in minimal mode) /blog/hello
blob9 host shop.example.com
blob10 external referrer host ('' in minimal mode) news.ycombinator.com
blob11 country (request.cf.country) DE
blob12-13 device, browser mobile, Safari
blob14-15 bot label, bot group GPTBot, ai
double4 always 0 (the proxy's browser time uses it) 0
double5 1 for a page view 1

What counts as a view

Counted Not counted
HTML page load (GET, 2xx except 204/206, or 304) HEAD, POST, 404, 5xx
Pages client navigation answered with page data (X-VoidPages response) prefetch (Purpose, Sec-Purpose, X-Moz, X-Purpose)
/_void/pages/*.json on void or static apps, mapped back to its page Pages redirects (200 + X-VoidPages-Redirect)
a navigation answered with HTML (its follow-up request is the counted one)
private previews, uptime monitors

The view uses the visitor's URL before any rewrite, so rewrites and SPA fallbacks are counted under the page the visitor opened.

Off switch

Dispatch reads the ROUTING key project-analytics-off:<projectId> (projectAnalyticsOffKey), caches it for 60s per isolate, and treats a read error as off. Nothing writes the key yet; the API route comes in the next PR, so analytics is on for everyone by default.

Tests

  • New page-view.test.ts covers methods, statuses, Sec-Fetch, prefetch markers, X-VoidPages answers, page-data path mapping, redirects, static deploys and referrers.
  • metering.test.ts: the old row shape is unchanged; checks the view row shape, minimal-mode blanking and the cut of a long CJK path.
  • index.test.ts: ISR JSON hit, redirect rule, rewrite, SPA fallback, workers.dev alias, off marker, a KV or classifier error still writes one base row, private preview, and "meters exactly once".

Results:

  • vp test run platform/packages/dispatch: 913 passed
  • vp check: clean
  • vp run test: 200/200 tasks

🤖 Generated with Claude Code

Brooooooklyn and others added 3 commits December 6, 2026 18:48
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>
@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-06T11:27:45.617662Z c9c78a1 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 c9c78a1

Updated: Dec 6, 2026, 11:26 UTC | Dashboard

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9c78a1f5a

ℹ️ 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".

Comment on lines +158 to +160
if (pageDataPath !== null) {
kind = 'nav';
path = pageDataPath;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Mark static page-data prefetches before counting them as views

For output: "static" apps with the static-data fast path enabled, fetchPrefetchPageData() calls loadStaticPageDataFile() directly (packages/void/src/pages/navigation-engine.ts:722-724), whose fetch sends only Accept: application/json (lines 649-651), not the Purpose: prefetch header. Consequently, the prefetch filter does not recognize these requests, and this branch records hovering over or observing a prefetched link as a page view even if the visitor never opens it. Propagate a prefetch marker through the static-data loader and cover the actual client-generated request headers in a regression test.

Useful? React with 👍 / 👎.

Comment on lines +166 to +170
// Only a page-data answer carries `X-VoidPages`. Without it (HTML, or the
// stale-build reload answer) the client follows up with a page-data file
// fetch or a full page load, and that request is the counted view.
kind = 'nav';
} else if (!request.headers.has('X-VoidPages') && isDocumentRequest(request, response)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Account for static navigations that consume inline HTML page data

When an output: "static" app has routing rules, resolveStaticPageDataBuildOptions() disables the static-data fast path. Its client navigation can then receive HTML and successfully consume the embedded page data: loadNavigationShell() calls loadStaticPageData() with verification enabled (packages/void/src/pages/navigation-engine.ts:971-977), and that helper returns immediately without fetching a JSON file when there are no deferred props (lines 688-695). Thus the assumed follow-up request never occurs, while this classifier rejects the HTML response because the request carries X-VoidPages; successful client navigations in this supported flow produce no page-view row. Account for this flow rather than assuming every HTML answer results in a second request.

Useful? React with 👍 / 👎.

@Brooooooklyn Brooooooklyn mentioned this pull request Dec 6, 2026
7 tasks done
@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-dispatch branch December 6, 2026 12:14
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