Chapter 04 · Cloudflare Deploy
Subchapter 4.259
references/web-analytics/README.mdMarkdown5 KBView on GitHub
Privacy-first web analytics providing Core Web Vitals, traffic metrics, and user insights without compromising visitor privacy.
Cloudflare Web Analytics provides:
Important: Web Analytics is dashboard-only. No API exists for programmatic data access.
Is your site proxied through Cloudflare?
├─ YES → Use automatic injection (configuration.md)
│ ├─ Enable auto-injection in dashboard
│ └─ No code changes needed (unless Cache-Control: no-transform)
│
└─ NO → Use manual beacon integration (integration.md)
├─ Add JS snippet to HTML
├─ Use spa: true for React/Vue/Next.js
└─ Configure CSP if neededspa: true config| Type | Description | Beacon Injection | Limit |
|---|---|---|---|
| Proxied | DNS through Cloudflare (orange cloud) | Automatic or manual | Unlimited |
| Non-proxied | External hosting, manual beacon | Manual only | 10 sites max |
Critical for modern frameworks:
{"token": "YOUR_TOKEN", "spa": true}Without spa: true, client-side navigation (React Router, Vue Router, Next.js routing) will NOT be tracked. Only initial page loads will register.
If using Content Security Policy, allow both domains:
script-src https://static.cloudflareinsights.com https://cloudflareinsights.com;Dashboard shows top 5 problematic elements with CSS selectors for debugging.
Create custom tracking rules for advanced configurations:
Sample Rate Rules:
Path-Based Rules:
/admin/* or /internal/* from trackingHost-Based Rules:
Availability: Rules feature depends on your Cloudflare plan. Check dashboard under Web Analytics → Rules to see if available. Free plans may have limited or no access.
| Feature | Free | Notes |
|---|---|---|
| Proxied sites | Unlimited | DNS through Cloudflare |
| Non-proxied sites | 10 | External hosting |
| Pageviews | Unlimited | No volume limits |
| Data retention | 6 months | Rolling window |
| Rules | Plan-dependent | Check dashboard |
EU opt-out: Dashboard option to exclude EU visitor data entirely.
#/path) not supported