Sveltekit Blog Engine
Guestbook
Login
Read in:
English日本語한국어

Dev Note: Why I Switched to Cloudflare Web Analytics Over the AdSense API

dev-notes • 2026-11-02 AM9:13:35 (GMT+9) • 👀 0 •
#SKBE#Cloudflare#WebAnalytics#SoloDev#DevNote#CFA
img-devnote-devnote-why-i-switched-to-cloudflare-web-analytics-ko-001

I was digging through the Google Cloud Console just to put a simple analytics chart on my blog admin dashboard when a massive wave of developer fatigue hit me.
Creating a project, enabling APIs, downloading service account JSON keys, wiring up IAM permissions...
The initial setup was messy enough, but the worst part was the chart breaking completely every time tokens or credentials expired down the road.
Having to jump back into the console each time to re-issue keys and tweak configs felt so tedious.
I just built this blog to quietly write posts—did I really need to suffer through all this maintenance just for a traffic chart?
That's when I started looking for a simpler, lower-maintenance alternative.

1. "Wait, isn't everything already on Cloudflare?"

Then it hit me: SKBE was already built to run on Cloudflare Pages and D1 database from day one.
And Cloudflare actually has its own built-in, completely free visitor analytics: Cloudflare Web Analytics (CFA).
Drop in a single site tag and token, and it quietly collects data in the background without worrying about OAuth expiration or periodic key rotations.
'My entire infrastructure already lives on Cloudflare anyway—why stress over expiring Google APIs when I can just make CFA my primary blog analytics?'

2. Starting Simple, Falling into Scope Creep

The original plan was dead simple: fetch the CFA API, display a few numbers and a single chart on the admin screen, and call it a day.
Naturally, once I touched the code, developer perfectionism kicked in and things spiraled out of control.

- Putting API Tokens Directly in Admin Felt Wrong:

To query CFA, you have to grant the Cloudflare API token Analytics Read permissions—and to be honest, I wasn't thrilled about adding yet another permission step during initial setup.
Worse, putting that token directly into Pages environment variables exposed to the web felt like a massive security compromise.
So I spun up an isolated, private cron Worker (cfa-sync) with no public route.
It quietly dumps hourly snapshots into D1 in the background, allowing the admin dashboard to read straight from D1 with zero API tokens. One less attack surface to worry about.

- Minimizing Worker Invocations at All Costs:

This was one of the things I cared about most during development.
I absolutely hated the idea of racking up unnecessary Worker invocations while pulling CFA API data and writing to D1.
So even when syncing 7 days of historical stats, everything is bundled cleanly inside a single Worker execution.

- Wait, Why Did 20 Visitors Drop to 0?:

During testing, I witnessed a bizarre bug where 20 visitors logged earlier in the day suddenly reset to 0 the next day.
On a quiet personal blog with barely any traffic, losing even my precious few visit counts was unacceptable. I added a monotonic guard that refuses to overwrite today's stats if the incoming number is smaller than the previous value.

- Exporting D1 Snapshots to Excel:

As daily snapshots piled up in D1, I wanted to download the data for local analysis.
Dumping everything into a single flat CSV felt messy because dimensions would get mixed up, so I integrated SheetJS to export clean, tab-separated multi-sheet XLSX files instead.

- Adding cfa-sync to the Sub-blog Pipeline:

The sync Worker had to be deployed to sub-accounts alongside the main blog, but deploying it manually to every account defeated the whole purpose of making things effortless.
So I slipped cfa-sync into the existing multi-account deployment script, allowing it to auto-deploy whenever an account is missing it.

3. Not Sure Anyone Will Actually Use This, But...

What started out as a petty desire to avoid managing Google API credentials ended up turning into a full v1.0.1.3 update.
Looking back, I tend to write code with the most intense focus not when pursuing grand ambitions, but when getting rid of friction that personally annoys me day-to-day.

Now I never have to touch Google Cloud Console, nor do I ever worry about token expirations.
Every hour on the hour, snapshots quietly land in D1, and whenever I want, I can export clean Excel reports with a single click.
I do laugh at myself a bit for meticulously separating multi-sheet Excel tabs when I don't even know how many people will ever fork this engine...
Still, since it's open source, I consider it a baseline duty. If even just one person finds it useful, that's enough.
Though whether that 'one person' actually exists is deeply questionable...

Share this post on social networks

0 Comments

Login is required to write comments.

This post is written in English.

Are you sure you want to delete?

This post is written in English.

Popular Tags

#API Token#AccountRestriction#AdSense#Admin#Animation#Anonymization#Architecture#AutoPublishing#AutomatedPosting#Automation
1 / 12

Popular Posts

  • Cloudflare Wrangler Login and API Token Configuration Guide in CLI Environments
    2026-07-15 PM9:17:34 (GMT+9)
  • Engineering SKBE: Multi-Slot Design, D1 Cache Optimization, and SEO Normalization (v1.0.0.11 ~ v1.0.0.13)
    2026-09-08 AM11:58:10 (GMT+9)
  • CMD One-Click Installation & Cloudflare Deployment Guide
    2026-07-15 PM9:19:35 (GMT+9)

Popular Tags

#API Token#AccountRestriction#AdSense#Admin#Animation#Anonymization#Architecture#AutoPublishing#AutomatedPosting#Automation
1 / 12

후원

Github

Categories

  • Admin Guide (5)
  • Detailed Manual (4)
  • DevLog (12)
  • DevNotes (8)
  • General Guide (3)
  • User Guide (3)

Recent Posts

  • Dev Note: Why I Switched to Cloudflare Web Analytics Over the AdSense API
    2026-11-02 AM9:13:35 (GMT+9)
  • SKBE v1.0.1.3 Update: Cloudflare Web Analytics Dashboard, Zero-Attack-Surface Sync Worker, and Multi-Account Deploy Pipeline
    2026-10-31 PM6:52:38 (GMT+9)
  • Node.js is on fire too (feat. Is Go or Rust the ultimate answer?)
    2026-10-29 AM1:48:00 (GMT+9)

Popular Posts

  • Cloudflare Wrangler Login and API Token Configuration Guide in CLI Environments
    2026-07-15 PM9:17:34 (GMT+9)
  • Engineering SKBE: Multi-Slot Design, D1 Cache Optimization, and SEO Normalization (v1.0.0.11 ~ v1.0.0.13)
    2026-09-08 AM11:58:10 (GMT+9)
  • CMD One-Click Installation & Cloudflare Deployment Guide
    2026-07-15 PM9:19:35 (GMT+9)

Support the project ☕

Github Link

AboutPrivacy PolicyContactTerms of Service

© 2026 스벨트킷 블로그 엔진 · Powered by Sveltekitblog Engine on Svelte 5

RSS SKBE v1.0.1.2 Share Design