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/analytics-engine/configuration.md
1# Analytics Engine Configuration23## Setup451. Add binding to `wrangler.jsonc`62. Deploy Worker73. Dataset created automatically on first write84. Query via SQL API910## wrangler.jsonc1112```jsonc13{14"name": "my-worker",15"analytics_engine_datasets": [16{ "binding": "ANALYTICS", "dataset": "my_events" }17]18}19```2021Multiple datasets for separate concerns:22```jsonc23{24"analytics_engine_datasets": [25{ "binding": "API_ANALYTICS", "dataset": "api_requests" },26{ "binding": "USER_EVENTS", "dataset": "user_activity" }27]28}29```3031## TypeScript3233```typescript34interface Env {35ANALYTICS: AnalyticsEngineDataset;36}3738export default {39async fetch(request: Request, env: Env) {40// No await - returns void, fire-and-forget41env.ANALYTICS.writeDataPoint({42blobs: [pathname, method, status], // String dimensions (max 20)43doubles: [latency, 1], // Numeric metrics (max 20)44indexes: [apiKey] // High-cardinality filter (max 1)45});46return response;47}48};49```5051## Data Point Limits5253| Field | Limit | SQL Access |54|-------|-------|------------|55| blobs | 20 strings, 16KB each | `blob1`...`blob20` |56| doubles | 20 numbers | `double1`...`double20` |57| indexes | 1 string, 16KB | `index1` |5859## Write Behavior6061| Scenario | Behavior |62|----------|----------|63| <1M writes/min | All accepted |64| >1M writes/min | Automatic sampling |65| Invalid data | Silent failure (check tail logs) |6667**Mitigate sampling:** Pre-aggregate, use multiple datasets, write only critical metrics.6869## Query Limits7071| Resource | Limit |72|----------|-------|73| Query timeout | 30 seconds |74| Data retention | 90 days (default) |75| Result size | ~10MB |7677## Cost7879**Free tier:** 10M writes/month, 1M reads/month8081**Paid:** $0.05 per 1M writes, $1.00 per 1M reads8283## Environment-Specific8485```jsonc86{87"analytics_engine_datasets": [88{ "binding": "ANALYTICS", "dataset": "prod_events" }89],90"env": {91"staging": {92"analytics_engine_datasets": [93{ "binding": "ANALYTICS", "dataset": "staging_events" }94]95}96}97}98```99100## Monitoring101102```bash103npx wrangler tail # Check for sampling/write errors104```105106```sql107-- Check write activity108SELECT DATE_TRUNC('hour', timestamp) AS hour, COUNT(*) AS writes109FROM my_dataset110WHERE timestamp >= NOW() - INTERVAL '24' HOUR111GROUP BY hour112```113