From da52b8ab73efbdb276b9b30412b1b2fc9e84d34b Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 9 Nov 2026 06:40:01 +0800 Subject: [PATCH] site: leave Cloudflare's Web Analytics beacon to Cloudflare Web Analytics had counted no visits for usemagpie.ai in 30 days. Every page carried two beacons: the worker's manual one and the one Cloudflare now injects into worker responses itself. The manual one loaded first, took the page, and posted to cloudflareinsights.com/cdn-cgi/rum, which answers 404 for this site's token. Cloudflare's own (r:1) posts to usemagpie.ai/cdn-cgi/rum, which answers 204 for the same payload. The worker now adds only PostHog. Run: node --test worker.test.mjs install.test.mjs on mote, 68 pass. The contributors test now fails if the worker adds cloudflareinsights again. Checked by hand: curl with browser headers shows Cloudflare's injected beacon on /, /zh/ and /docs/; the same-origin POST answers 204. --- site/worker.js | 11 +++++++---- site/worker.test.mjs | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/site/worker.js b/site/worker.js index 4a69c01a1..2890f7561 100644 --- a/site/worker.js +++ b/site/worker.js @@ -365,9 +365,12 @@ export async function relay(req, url) { } } -// beacon adds Cloudflare Web Analytics and PostHog's Web Analytics to a page. -// The dashboard's automatic injection skips whatever a worker returns, and -// every page passes through this one. PostHog's requests go through RELAY +// beacon adds PostHog's Web Analytics to a page; every page passes through +// this one. Cloudflare Web Analytics is not added here: Cloudflare injects +// its own beacon into worker responses now, and that one reports to this +// site's /cdn-cgi/rum. A second, manual beacon loaded first and won, and +// reported to cloudflareinsights.com, which answers 404 for this site's +// token, so Web Analytics counted no visits at all. PostHog's requests go through RELAY // on this site. PostHog keeps its visitor id in // localStorage, never a cookie: these pages vary on Cookie (the lang // cookie), and a per-visitor cookie would ride on every request. It isn't @@ -379,7 +382,7 @@ export async function relay(req, url) { // flags aren't turned off. Nothing is loaded under Do Not Track or Global // Privacy Control. Its project is the daily count's. const WEB_ANALYTICS = ``; -const BEACON = `` + WEB_ANALYTICS; +const BEACON = WEB_ANALYTICS; // The contributors page: its #wall gets the table credits-cli.mjs rendered // for that language at deploy. Without it (a deploy that couldn't build diff --git a/site/worker.test.mjs b/site/worker.test.mjs index b3d131e58..3b3d9d0b0 100644 --- a/site/worker.test.mjs +++ b/site/worker.test.mjs @@ -647,7 +647,8 @@ test("contributors: each language's page gets its own table, and keeps its line assert.match(html, /
/, path); assert.ok(html.includes(head), `${path} has the ${lang} table`); assert.ok(html.includes("packinggoodsllc_07668") && html.includes("v0.1.2581"), path); - assert.match(html, /static\.cloudflareinsights\.com/, `${path} keeps the beacon`); + assert.match(html, /posthog\.init\(/, `${path} keeps the analytics`); + assert.doesNotMatch(html, /cloudflareinsights/, `${path} leaves Cloudflare's beacon to Cloudflare`); } fragments = false; const bare = await get("/docs/zh/contributors");