A 10-module progressive tutorial that takes you from a minimal beacon to a production-ready, configurable, extensible analytics collector script. Each module builds on the last — by the end, you'll understand how tools like Google Analytics and Plausible work under the hood.
Send your first analytics beacon:
navigator.sendBeacon()Collect browser and device data:
Analytics without custom JavaScript:
Build a collection server:
sendBeacon → fetch(keepalive) fallbackMeasure page load performance:
Core Web Vitals collection:
Catch and report errors:
Refactor into a library:
init/track/set/identify APIBuild a plugin system:
collector.use() registrationShip it:
collector.js — 565-line implementationThe reference collector.js contains the functions you will build across these modules. Use this table to see where each piece fits:
| Existing Function | Tutorial Module |
|---|---|
initialBrowserData() |
Module 02 |
getNavigatorInfo() |
Module 02 |
getNetworkInformation() |
Module 02 |
getNavigationTiming() |
Module 05 |
initResourceTiming() |
Module 05 |
initPerformanceObserver() |
Module 06 |
initLargestContentfulPaint() |
Module 06 |
initLayoutShift() |
Module 06 |
initFirstInputDelay() → INP |
Module 06 |
getVitalsScore() |
Module 06 |
reportError() |
Module 07 |
reportPerf() / pushTask() |
Module 08 |
config object |
Module 08 |