Environment Variables

diy-analytics is configured entirely through environment variables. This page is the complete reference — required, optional, and AI provider keys.


Required

VariableDescriptionExample
DATABASE_URLPostgreSQL connection string. Must be a pooled URI in serverless production environments.postgres://user:pass@ep-pooler.neon.tech/dbname?sslmode=require
NEXT_PUBLIC_SITE_URLCanonical public URL of your deployment, no trailing slash. Used for embed snippets and CORS checks.https://analytics.yourdomain.com

Optional & performance

VariableTypeDefaultDescription
CRON_SECRETstring—Authenticates the daily rollup cron job (GET /api/cron/rollup). Passed automatically by Vercel Cron.
DATABASE_STORAGE_CAP_MBnumber512Soft storage quota, in megabytes, shown in workspace and profile usage gauges.
PAGEVIEW_RETENTION_DAYSnumber90Days to retain raw pageview rows before automatic pruning during daily rollups.
EVENT_RETENTION_DAYSnumber90Days 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:

VariableProviderDescription
GEMINI_API_KEYGoogle GeminiEnables Gemini 2.0 models for natural language database queries
OPENAI_API_KEYOpenAIEnables GPT-4o / GPT-4o-mini
ANTHROPIC_API_KEYAnthropicEnables Claude 3.5 Sonnet
GROQ_API_KEYGroqEnables ultra-low-latency Llama 3 models
OPENROUTER_API_KEYOpenRouterMulti-model routing through OpenRouter
NVIDIA_API_KEYNVIDIA NIMHosted NVIDIA NIM inference

Complete .env.local example

bash
1# ============================================================================== 2# Database Configuration (PostgreSQL 14+ with Connection Pooling) 3# ============================================================================== 4DATABASE_URL=postgres://user:password@ep-xxxx-pooler.us-east-2.aws.neon.tech/neondb?sslmode=require 5 6# ============================================================================== 7# Application URL (No Trailing Slash) 8# ============================================================================== 9NEXT_PUBLIC_SITE_URL=https://analytics.yourdomain.com 10 11# ============================================================================== 12# Scheduled Rollup Cron Authentication 13# ============================================================================== 14CRON_SECRET=super_secret_cron_token_32_characters_long 15 16# ============================================================================== 17# Storage Quota & Retention Policies (in Days) 18# ============================================================================== 19DATABASE_STORAGE_CAP_MB=512 20PAGEVIEW_RETENTION_DAYS=90 21EVENT_RETENTION_DAYS=90 22 23# ============================================================================== 24# AI Copilot Provider (Optional) 25# ============================================================================== 26GEMINI_API_KEY=AIzaSyYourSecretGeminiKeyHere

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_URIDATABASE_URL
MONGODB_DATABASEIncluded in the DATABASE_URL connection path
MONGODB_STORAGE_CAP_MBDATABASE_STORAGE_CAP_MB

Next steps