Environment Variables
diy-analytics is configured entirely through environment variables. This page is the complete reference — required, optional, and AI provider keys.
Required
| Variable | Description | Example |
|---|---|---|
DATABASE_URL | PostgreSQL connection string. Must be a pooled URI in serverless production environments. | postgres://user:pass@ep-pooler.neon.tech/dbname?sslmode=require |
NEXT_PUBLIC_SITE_URL | Canonical public URL of your deployment, no trailing slash. Used for embed snippets and CORS checks. | https://analytics.yourdomain.com |
Optional & performance
| Variable | Type | Default | Description |
|---|---|---|---|
CRON_SECRET | string | — | Authenticates the daily rollup cron job (GET /api/cron/rollup). Passed automatically by Vercel Cron. |
DATABASE_STORAGE_CAP_MB | number | 512 | Soft storage quota, in megabytes, shown in workspace and profile usage gauges. |
PAGEVIEW_RETENTION_DAYS | number | 90 | Days to retain raw pageview rows before automatic pruning during daily rollups. |
EVENT_RETENTION_DAYS | number | 90 | Days to retain raw custom event rows before automatic pruning during daily rollups. |
AI assistant providers (optional)
Set any one of these to enable the in-app AI Copilot:
| Variable | Provider | Description |
|---|---|---|
GEMINI_API_KEY | Google Gemini | Enables Gemini 2.0 models for natural language database queries |
OPENAI_API_KEY | OpenAI | Enables GPT-4o / GPT-4o-mini |
ANTHROPIC_API_KEY | Anthropic | Enables Claude 3.5 Sonnet |
GROQ_API_KEY | Groq | Enables ultra-low-latency Llama 3 models |
OPENROUTER_API_KEY | OpenRouter | Multi-model routing through OpenRouter |
NVIDIA_API_KEY | NVIDIA NIM | Hosted NVIDIA NIM inference |
Complete .env.local example
bash
Legacy variables (v0.1.0 and earlier)
In 0.1.1, the persistence layer moved from MongoDB to PostgreSQL via Drizzle ORM:
| Legacy variable (MongoDB) | Modern variable (PostgreSQL) |
|---|---|
MONGODB_URI | DATABASE_URL |
MONGODB_DATABASE | Included in the DATABASE_URL connection path |
MONGODB_STORAGE_CAP_MB | DATABASE_STORAGE_CAP_MB |
Upgrading a legacy MongoDB deployment? Follow the Migrating from MongoDB guide.