Skip to main content

One post tagged with "cloudflare-workers"

View All Tags

Live "online users" on a static blog: GA4 Realtime + a Cloudflare Worker

· 10 min read
Charles Wang
DevOps / Backend Engineer

I wanted the homepage stats bar to show a current online users number, next to the build-time stats (posts, tags, days since last post). It sounds like a one-liner, but a static site fundamentally cannot call the GA4 Realtime API directly — the API needs a service-account private key, and anything you ship to the browser is public. This post is the whole path I took: the build-time-vs-runtime split, why a proxy is mandatory, the Cloudflare Worker that signs its own Google token, wiring the frontend, and the three traps I fell into along the way.