Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/web-analytics/integration.md
1# Framework Integration23**Web Analytics is dashboard-only** - no programmatic API. This covers beacon integration.45## Basic HTML67```html8<script defer src='https://static.cloudflareinsights.com/beacon.min.js'9data-cf-beacon='{"token": "YOUR_TOKEN", "spa": true}'></script>10```1112Place before closing `</body>` tag.1314## Framework Examples1516| Framework | Location | Notes |17|-----------|----------|-------|18| React/Vite | `public/index.html` | Add `spa: true` |19| Next.js App Router | `app/layout.tsx` | Use `<Script strategy="afterInteractive">` |20| Next.js Pages | `pages/_document.tsx` | Use `<Script>` |21| Nuxt 3 | `app.vue` with `useHead()` | Or use plugin |22| Vue 3/Vite | `index.html` | Add `spa: true` |23| Gatsby | `gatsby-browser.js` | `onClientEntry` hook |24| SvelteKit | `src/app.html` | Before `</body>` |25| Astro | Layout component | Before `</body>` |26| Angular | `src/index.html` | Add `spa: true` |27| Docusaurus | `docusaurus.config.js` | In `scripts` array |2829## Configuration3031```json32{33"token": "YOUR_TOKEN",34"spa": true35}36```3738**Use `spa: true` for:** React Router, Vue Router, Next.js, Nuxt, Gatsby, SvelteKit, Angular3940**Use `spa: false` for:** Traditional server-rendered (PHP, Django, Rails, WordPress)4142## CSP Headers4344```45script-src 'self' https://static.cloudflareinsights.com;46connect-src 'self' https://cloudflareinsights.com;47```4849## GDPR Consent5051```typescript52// Load conditionally based on consent53if (localStorage.getItem('analytics-consent') === 'true') {54const script = document.createElement('script');55script.src = 'https://static.cloudflareinsights.com/beacon.min.js';56script.defer = true;57script.setAttribute('data-cf-beacon', '{"token": "YOUR_TOKEN", "spa": true}');58document.body.appendChild(script);59}60```61