diff --git a/README.md b/README.md index 67bbae2..da9c5d4 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,9 @@ GitHub Actions are pinned to full commit SHAs. When updating an Action, verify t replacement commit in its official repository and update its version comment. Production builds include a Content Security Policy generated by Astro. Scripts -are limited to the same origin and build-generated hashes; the initial theme +are limited to the same origin, build-generated hashes, and the Cloudflare Web +Analytics beacon at `https://static.cloudflareinsights.com/beacon.min.js`. Connections +are limited to the same origin and `https://cloudflareinsights.com`. The initial theme script is served from `/theme-init.js` and runs before visible page content. Inline style attributes remain allowed for Shiki syntax highlighting, while script attributes and arbitrary inline scripts are blocked. YouTube embeds use @@ -183,3 +185,18 @@ attribute allowance; syntax highlighting has been verified in a production brows The policy is delivered through a meta tag on GitHub Pages. Directives that require HTTP headers, such as `frame-ancestors`, must be configured at a compatible hosting layer if needed. Local validation does not verify a deployment on GitHub Pages. + +## Web analytics + +Production pages using `src/layouts/Base.astro` include the Cloudflare Web Analytics +snippet for `codegeeksai.github.io`, covering both Italian and English routes. The +root redirect is not tracked separately. The snippet is omitted by `npm run dev`; +`npm run preview` serves the production output, which includes it. + +The `data-cf-beacon` token is a public site identifier supplied by Cloudflare, not +an account API credential. View the statistics in the Cloudflare account's +Web Analytics dashboard. Data collection begins after this change is deployed; +confirm incoming visits in the dashboard after publication. + +The CSP allows the external beacon script and its reporting endpoint, as described +in [Cloudflare's CSP guidance](https://developers.cloudflare.com/web-analytics/faq/#what-do-i-need-to-add-to-my-content-security-policy-csp). diff --git a/astro.config.mjs b/astro.config.mjs index 1c49b21..b94d2c4 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -8,6 +8,7 @@ export default defineConfig({ csp: { directives: [ "default-src 'self'", + "connect-src 'self' https://cloudflareinsights.com", "base-uri 'none'", "object-src 'none'", "form-action 'self'", @@ -17,6 +18,7 @@ export default defineConfig({ scriptDirective: { resources: [ { resource: "'self'", kind: 'element' }, + { resource: 'https://static.cloudflareinsights.com/beacon.min.js', kind: 'element' }, { resource: "'none'", kind: 'attribute' }, ], }, diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index aa02731..cab0e6c 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -89,5 +89,13 @@ const navigation = [ }); } + {import.meta.env.PROD && ( + + )}