Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 37 ยท Projects and Practice

Project: A Tiny Real-User Monitor

Build a small real-user monitoring script that collects navigation timing, LCP, CLS and slow interactions, batches them, and summarizes p75 values like a dashboard.

In this project you will build a tiny real-user monitor in three parts: a collector that runs in the page, a batcher that sends data efficiently, and an aggregator that turns many visits into p75 numbers, the way a real dashboard does. The server and the database are simulated in memory, so everything runs in the browser.

Architecture

flowchart LR
  P["Page: collector"] --> B["Batcher<br/>one beacon"]
  B -->|"POST /rum"| S["Server (simulated)"]
  S --> A["Aggregator<br/>p50 / p75 per page"]

Collect small, batch, send once, aggregate on the server.

Step 1: the collector

The collector observes the key metrics and keeps the latest values in a plain object. Each metric has its own observer. The browser does not report all of them in every sandbox, so the code only records what it receives.

The collector

Click the button a few times and watch slowestInteraction change where the browser supports the Event Timing API. Entries your browser does not support simply stay at their default values.

Step 2: the batcher

Never send one request per metric. The batcher gathers a payload and sends it once when the page is hidden. This version simulates the network so we can test it anywhere:

JS The batcher

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice three design decisions: it sends once, it supports sampling for busy sites, and it includes the release to correlate regressions with deployments.

Step 3: the aggregator

On the server, many payloads are combined into percentiles per page. Here is a complete aggregator over a synthetic set of visits, with a seeded pseudo-random generator so the output is deterministic:

JS The aggregator

Press Run (or Ctrl + Enter) to see the console output here.

No output.

You should see that mobile has a clearly worse p75 than desktop, which is the pattern that makes segmenting so valuable. (The exact numbers come from the seeded generator and are stable.)

Extending the project

  1. Use the real web-vitals library instead of hand-written observers (onLCP, onINP, onCLS).
  2. Add attribution: record the LCP element selector and the slowest interaction target, so reports say what was slow.
  3. Add device info: navigator.deviceMemory, navigator.hardwareConcurrency, navigator.connection?.effectiveType.
  4. Store payloads on a real server (a Node or PHP endpoint) and chart p75 per day.
  5. Alert when a day's p75 is 20 percent worse than the 7-day baseline, as in the monitoring lesson.

Privacy checklist

  • Do not collect names, e-mails or full URLs with query strings.
  • Do not send more than you need; aggregate rather than record full sessions.
  • Respect consent and do-not-track rules that apply to your audience.
  • Sample on high-traffic sites.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does the batcher send one payload instead of one request per metric?

    A single small beacon is cheaper and more reliable when the page is closing.
  2. 2. What does sampling do?

    A sample rate of 0.1 records about 10 percent of visits.
  3. 3. Why include the release version in each payload?

    Release tags make regressions traceable.
  4. 4. Why does the aggregator report p75 rather than the average?

    Percentiles reveal what slower users experience.

Summary

  • A RUM system has a collector, a batcher and an aggregator.
  • Collect with PerformanceObserver, send once with sendBeacon, and aggregate into percentiles by segment.
  • Include release and segment data, sample on busy sites and protect privacy.

Next: Practice: A Performance Audit Checklist