Repository navigation
Add Cloudflare Web Analytics beacon - #194
Conversation
Loads the privacy-first beacon from static.cloudflareinsights.com on every page and lets the Content-Security-Policy allow its script and its report endpoint. No cookies, no third-party tracking; the token is a public site identifier.
src/_headers is generated by scripts/csp-hashes.mjs, so the two new sources live in the template and the file is regenerated with --write. ci's csp-hashes --check passes again.
Deploying amnesia-site with
|
| Latest commit: |
6c5da8f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://363dad96.amnesia-site.pages.dev |
| Branch Preview URL: | https://chore-web-analytics-beacon.amnesia-site.pages.dev |
sprayberry-redline
left a comment
There was a problem hiding this comment.
Verdict: request changes. The analytics beacon is present and the CSP template and generated header allow its script and reporting endpoint, but the script is loaded with a mode that prevents the beacon from reading its configuration token.
1. Blocking: src/amnesia-search.html:1491
<script type='module' src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "d7edf0ba4b1647e99e00af0d94856c6b"}'></script>
Cloudflare's beacon is a classic script and reads its data-cf-beacon configuration from document.currentScript. Module scripts have no document.currentScript, so this load cannot obtain the token and exits without recording page views or Web Vitals.
Suggested fix:
Load the documented classic beacon instead, for example `<script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "..."}'></script>`, without `type='module'`.
rule:none
|
Verified the module-type tag works as shipped, so no change is needed here. beacon.min.js (current build, 31,853 bytes) locates its config with Live check on a site carrying this identical tag, observed in Chrome's network log:
The 204 is the beacon reporting with its token. Leaving the tag as is; happy to switch to the classic |
sprayberry-redline
left a comment
There was a problem hiding this comment.
Verdict: approve. The analytics beacon is loaded once at the document level, and both its script host and collection endpoint are consistently permitted by the generated CSP template and deployed header.
Adds the Cloudflare Web Analytics beacon to every page so page views and Core Web Vitals show up in the analytics dashboard.
beacon.min.jsfromstatic.cloudflareinsights.comwith the site's public token.cloudflareinsights.com).Verify after deploy: the page source carries one
cloudflareinsightsscript tag and the browser console shows no CSP violation.