Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
2 changes: 2 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand All @@ -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' },
],
},
Expand Down
8 changes: 8 additions & 0 deletions src/layouts/Base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,13 @@ const navigation = [
});
}
</script>
{import.meta.env.PROD && (
<script
is:inline
type="module"
src="https://static.cloudflareinsights.com/beacon.min.js"
data-cf-beacon='{"token": "8d24179560e24250994db7de79af9cd1"}'
></script>
)}
</body>
</html>
Loading