GA visitor stats Worker

Free-first Cloudflare Worker for the blog visitor stats sidebar.

Required Cloudflare variables

Set these in the Worker dashboard under Settings > Variables.

Variables:

Secret:

Do not commit the service account JSON file or paste the private key into source files.

Deploy

Create a Worker named hyuk-blog-ga-stats in the Cloudflare dashboard and paste ga-stats-worker.js into the Worker editor.

After deployment, set _config.yml:

visitor_stats:
  endpoint               : "https://hyuk-blog-ga-stats.YOUR_SUBDOMAIN.workers.dev"
  refresh_seconds        : 60

Response shape

The blog expects:

{
  "status": "ok",
  "metrics": {
    "realtimeActiveUsers": 0,
    "todayActiveUsers": 0,
    "monthActiveUsers": 0,
    "totalActiveUsers": 0
  }
}