Public: anyone can read this; the crew can change it.

First-party measurement: visitors, users and real page speed, built into the forge and the app template #2688

Parked opened this in answer to
Closed without merging

Every forge page and every new app from the template now measures itself, first party. A page view lands in the store with its vitals, the home KPI counts it, and no address or raw path is kept. The new tests, the touched suites and tsc on the forge pass.

Notes

stopped parked by the crew deploy b5dfbcf

opened this

Every forge page and every new app from the template now measures itself, first party. A page view lands in the store with its vitals, the home KPI counts it, and no address or raw path is kept. The new tests, the touched suites and tsc on the forge pass. I did not run the forge's full check, which will run on the push. In the scaffold type-check test, the check that types the generated app fails here with bun is unable to write files to tempdir (sandbox). I ran tsc on the generated app by hand and it was clean.

What changed

  • Beacon. src/web/vitals_client.ts is about 1 KB and has no dependencies. It sends route, load, TTFB, LCP, INP and CLS to POST /_vitals when the page is hidden. It is served content-addressed and immutable, and every page links it.
  • Store. Migration 20261019130000-vitals adds pageview, vitals_salt and route_timing. src/core/vitals.ts validates the beacon (size, finite numbers in range, no control bytes) and rate-limits each visitor.
  • Privacy.
    • Only the route pattern is stored, never the path, so a private repo name never lands.
    • The visitor is a hash salted per UTC day. Only the current day's salt is kept and views older than 90 days are deleted, so nobody can be followed across days.
    • The door refuses cross-origin posts and honours DNT, Sec-GPC and a forge_measure=off cookie.
  • Server timing. Every response from the forge or a hosted child carries Server-Timing: app;dur=…. Server time per route and hour is a histogram in route_timing, written in bulk.
  • Boards. There are two new admin-only sources, views and timings. The visitor hash is not a listed column, so no query can group by it.
  • Home. Admins get a "Measured here" card with users, active today and over 7 days, visitors today and over 7 days, and p75 page load and p75 interaction time.
  • App template. New apps get the same static/vitals.js and a view table with its salt. They also get POST /_vitals (own rate limit, exempt from the write limit), Server-Timing, a test, and bun run src/measure.ts to print the numbers.
  • README. Documents all of this.

Chosen and left out

  • Visitors, 7 days. This is each day's uniques summed (labelled "daily uniques summed"), not true weekly uniques. The daily salt makes a true weekly count impossible, and that is the privacy trade.
  • INP. This is the slowest interaction seen, not the spec's 98th percentile.
  • Template visitors. Apps behind the forge proxy don't see client addresses, so a template visitor is a hash of user-agent and signed-in user. It is coarser than the forge's.
  • Template histogram. The template has the Server-Timing header but no route histogram.
  • Opt-out switch. There is no UI for the opt-out; it is the cookie, DNT or GPC.
  • Admin-only. Only admins see the KPIs.
  • #2665. I did not look at #2665; the card sits in the home feed column.

Try it

  • Run bun run src/main.ts and open any page.
  • Read curl -i localhost:3000/signin for Server-Timing.
  • Post a beacon: curl -XPOST localhost:3000/_vitals -d '{"p":"/","load":900}'.
  • Sign in as an admin to see the home card, or query the views source on a board.
  • Tests are in test/measurement.test.ts and, for the template, src/measure.test.ts.

🤖 Generated with Claude Code

Closes #2674

commented

Every forge page and every new app from the template now measures itself, first party. A page view lands in the store with its vitals, the home KPI counts it, and no address or raw path is kept. The new tests, the touched suites and tsc on the forge pass. I did not run the forge's full check, which will run on the push. In the scaffold type-check test, the check that types the generated app fails here with bun is unable to write files to tempdir (sandbox). I ran tsc on the generated app by hand and it was clean.

What changed

  • Beacon. src/web/vitals_client.ts is about 1 KB and has no dependencies. It sends route, load, TTFB, LCP, INP and CLS to POST /_vitals when the page is hidden. It is served content-addressed and immutable, and every page links it.
  • Store. Migration 20261019130000-vitals adds pageview, vitals_salt and route_timing. src/core/vitals.ts validates the beacon (size, finite numbers in range, no control bytes) and rate-limits each visitor.
  • Privacy.
    • Only the route pattern is stored, never the path, so a private repo name never lands.
    • The visitor is a hash salted per UTC day. Only the current day's salt is kept and views older than 90 days are deleted, so nobody can be followed across days.
    • The door refuses cross-origin posts and honours DNT, Sec-GPC and a forge_measure=off cookie.
  • Server timing. Every response from the forge or a hosted child carries Server-Timing: app;dur=…. Server time per route and hour is a histogram in route_timing, written in bulk.
  • Boards. There are two new admin-only sources, views and timings. The visitor hash is not a listed column, so no query can group by it.
  • Home. Admins get a "Measured here" card with users, active today and over 7 days, visitors today and over 7 days, and p75 page load and p75 interaction time.
  • App template. New apps get the same static/vitals.js and a view table with its salt. They also get POST /_vitals (own rate limit, exempt from the write limit), Server-Timing, a test, and bun run src/measure.ts to print the numbers.
  • README. Documents all of this.

Chosen and left out

  • Visitors, 7 days. This is each day's uniques summed (labelled "daily uniques summed"), not true weekly uniques. The daily salt makes a true weekly count impossible, and that is the privacy trade.
  • INP. This is the slowest interaction seen, not the spec's 98th percentile.
  • Template visitors. Apps behind the forge proxy don't see client addresses, so a template visitor is a hash of user-agent and signed-in user. It is coarser than the forge's.
  • Template histogram. The template has the Server-Timing header but no route histogram.
  • Opt-out switch. There is no UI for the opt-out; it is the cookie, DNT or GPC.
  • Admin-only. Only admins see the KPIs.
  • #2665. I did not look at #2665; the card sits in the home feed column.

Try it

  • Run bun run src/main.ts and open any page.
  • Read curl -i localhost:3000/signin for Server-Timing.
  • Post a beacon: curl -XPOST localhost:3000/_vitals -d '{"p":"/","load":900}'.
  • Sign in as an admin to see the home card, or query the views source on a board.
  • Tests are in test/measurement.test.ts and, for the template, src/measure.test.ts.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("apps: identity, and a deploy that never answers > identity: a granted person is named to the app, signed with the app's key; a client's own claim is dropped; the two doors work") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs