Skip to content

chore(site): allow the Cloudflare Web Analytics beacon through the CSP - #201

Merged
dvcdsys merged 1 commit into
developfrom
feat/site-web-analytics
Jul 27, 2026
Merged

chore(site): allow the Cloudflare Web Analytics beacon through the CSP#201
dvcdsys merged 1 commit into
developfrom
feat/site-web-analytics

Conversation

@dvcdsys

@dvcdsys dvcdsys commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Why

The site has no analytics of any kind, so we cannot tell whether the
promotion work is reaching real people or which pages they read. This is
P0 of the promotion plan: measurement before promotion.

Cloudflare Web Analytics is the right first tool here — the site already
runs on Cloudflare Pages, it is cookie-free (no consent banner), and its
first-party beacon is not blocked as widely as Google Analytics by the ad
blockers a developer audience runs.

What

One line in site/public/_headers:

  • script-src += https://static.cloudflareinsights.com — the beacon that
    the Pages project injects into every HTML response at the edge.
  • connect-src += https://cloudflareinsights.com — where the beacon POSTs
    its measurements.

Without this the current script-src 'self' blocks the injected tag and the
analytics dashboard would just report zero forever.

Nothing else is widened: no cookies, no ad network, no third-party images or
styles.

Ordering

This has to land on main before the Web Analytics toggle is flipped in
the Cloudflare dashboard, otherwise the beacon is dead on arrival. A
develop -> main promotion PR follows.

Test plan

  • npm run build in site/ — passes, and dist/_headers carries the new
    policy verbatim (Cloudflare _headers supports # comments).
  • After deploy: curl -sI https://codeindex.app | grep -i content-security shows
    the two new hosts, and the browser console reports no CSP violation.

🤖 Generated with Claude Code

The site ships no analytics at all, so there is no way to tell whether
anyone reads it. Cloudflare Web Analytics is the cheapest honest answer
for a Pages-hosted site: cookie-free, no consent banner, first-party
beacon, and it is not blocked as aggressively as GA by the ad blockers
this audience runs.

Enabling it on the Pages project injects the beacon script at the edge,
which the current `script-src 'self'` policy would silently drop. Widen
script-src to static.cloudflareinsights.com and connect-src to
cloudflareinsights.com — the two hosts the beacon needs, nothing else.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@dvcdsys
dvcdsys merged commit 2583d7d into develop Jul 27, 2026
1 check passed
@dvcdsys
dvcdsys deleted the feat/site-web-analytics branch July 27, 2026 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant