Cloudflare Web Analytics on Astro Starlight
To integrate Cloudflare Web Analytics into your Astro Starlight documentation site, you must insert the beacon script into the <head> of all pages via the astro.config.mjs file.
- Retrieve Token: Get your unique analytics token (e.g., 9692482312d8a417…) from the Cloudflare Web Analytics dashboard.
- Update Configuration: Open
astro.config.mjsand add the following configuration block within the starlight integration. Replace “YOUR_TOKEN_HERE” with your actual token.
export default defineConfig({
...
integrations: [
starlight({
head: [
{
tag: "script",
attrs: {
defer: true,
src: "https://static.cloudflareinsights.com/beacon.min.js",
"data-cf-beacon": '{"token": "YOUR_TOKEN_HERE"}',
},
},
],
}),
],
});
- Deploy: Build and deploy your updated site. Data will start appearing in your Cloudflare dashboard after users begin visiting your site.