caelum0x 65acbbd9a3 feat(insights): page speed per app with deploy markers, a web package that measures it, and the join to errors (PY3.3)
RYP-G3 in Wave P.
- @railyard/insights-web: page views (with client-side route changes),
  events, identify, and LCP, INP, CLS, FCP and TTFB per page view, sent once
  when the page is hidden or the route changes; no cookies, no storage, Do
  Not Track and consent respected. src/metrics.ts adapts MIT-licensed code
  (NOTICE keeps the licence) with two changes that match Chrome's field
  reporting: LCP stops at the first input, and INP picks its percentile from
  the page's interaction count. On six worked fixtures (after-click paint,
  two shift windows with a post-input shift, prerender activation, 120
  interactions, multi-event interactions) every metric and the p75 are
  within 10% of Chrome's values.
- Edge collector and ingest carry `performance` events (the five metrics,
  in the upstream ranges) into upstream event type 5 rows.
- Insights GET /api/v1/tenants/{org}/vitals: p75 per app, per UTC day, and
  in the day before and after each given deploy time (up to 10); ratings
  from the published thresholds; org-scoped (SQL test with hand p75s).
- Console: the Page speed screen (only with RAILYARD_REPLAY_LIVE=1) and the
  Scribase bridge `insights` answer gain `vitals` (p75 cells and one marker
  per deploy from the console's own deploy records, so a deploy is marked on
  the next read); a vitals failure never hides the rest of the tab.

The Scribase Analytics sub-tab (carve-out) joins these markers to the
environment's error issues: "This deploy raised errors by N" links to the
Errors tab.

Tests: console 128/128 (view model, bridge marker, flag gate, copy lint),
insights-web 12/12 (fixtures, client, copy), insights fork 12/12, edge
19/19, tsc clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 04:05:42 +03:00
..

@railyard/insights-web

Railyard Insights for web apps: page views (including client-side route changes), custom events, identify, and five page-speed metrics for each page view. No cookies and no storage; nothing is sent when Do Not Track is on or when consent() returns false. No dependencies.

import { createInsightsWeb } from '@railyard/insights-web';

const insights = createInsightsWeb({
  site: 'ry_site_...',                    // public, like an anon key
  collector: 'https://collect.example',
});
insights.track('signup');
insights.identify(user.id, { plan: 'pro' });

Page speed

Each page view reports, once, when the page is hidden or the route changes:

Metric What it is
LCP when the largest text or image finished painting, up to the first click or key press
INP how long the page took to respond to input (the slowest, skipping one per 50 inputs)
CLS how much the layout moved (the worst burst of shifts)
FCP when the first text or image painted
TTFB when the server's first byte arrived

The numbers follow the definitions Chrome uses for its own field reporting (computeVitals in src/metrics.ts, tested against worked fixtures within 10%). Insights shows the 75th percentile per app and, for each deploy, how each metric moved from the day before to the day after.

The one-line page tag (/s.js) sends page views and events only; use this package to add page speed.

NOTICE lists the MIT-licensed source src/metrics.ts adapts.