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/patterns.md
1# Web Analytics Patterns23## Core Web Vitals Debugging45Dashboard → Core Web Vitals → Click metric → Debug View shows top 5 problematic elements.67### LCP Fixes89```html10<!-- Priority hints -->11<img src="hero.jpg" loading="eager" fetchpriority="high" />12<link rel="preload" as="image" href="/hero.jpg" fetchpriority="high" />13```1415### CLS Fixes1617```css18/* Reserve space */19.ad-container { min-height: 250px; }20img { width: 400px; height: 300px; } /* Explicit dimensions */21```2223### INP Fixes2425```typescript26// Debounce expensive operations27const handleInput = debounce(search, 300);2829// Yield to main thread30await task(); await new Promise(r => setTimeout(r, 0)); await task2();3132// Move to Web Worker for heavy computation33```3435| Metric | Good | Poor |36|--------|------|------|37| LCP | ≤2.5s | >4s |38| INP | ≤200ms | >500ms |39| CLS | ≤0.1 | >0.25 |4041## GDPR Consent4243```typescript44// Load beacon only after consent45const consent = localStorage.getItem('analytics-consent');46if (consent === 'accepted') {47const script = document.createElement('script');48script.src = 'https://static.cloudflareinsights.com/beacon.min.js';49script.setAttribute('data-cf-beacon', '{"token": "TOKEN", "spa": true}');50document.body.appendChild(script);51}52```5354Alternative: Dashboard → "Enable, excluding visitor data in the EU"5556## SPA Navigation5758```html59<!-- REQUIRED for React/Vue/etc routing -->60<script data-cf-beacon='{"token": "TOKEN", "spa": true}' ...></script>61```6263Without `spa: true`: only initial pageload tracked.6465## Staging/Production Separation6667```typescript68// Use env-specific tokens69const token = process.env.NEXT_PUBLIC_CF_ANALYTICS_TOKEN;70// .env.production: production token71// .env.staging: staging token (or empty to disable)72```7374## Bot Filtering7576Dashboard → Filters → "Exclude Bot Traffic"7778Filters: Search crawlers, monitoring services, known bots.79Not filtered: Headless browsers (Playwright/Puppeteer).8081## Ad-Blocker Impact8283~25-40% of users may block `cloudflareinsights.com`. No official workaround.84Dashboard shows minimum baseline; use server logs for complete picture.8586## Limitations8788- No UTM parameter tracking89- No webhooks/alerts/API90- No custom beacon domains91- Max 10 non-proxied sites92