Environment Variables
diy-analytics is configured entirely through environment variables — there's no separate config file. This page is the full reference.
Required
| Variable | Description |
|---|---|
DATABASE_URL | Your PostgreSQL connection string, e.g. postgres://user:password@host:5432/diy-analytics?sslmode=require. Used for every database read and write. |
NEXT_PUBLIC_SITE_URL | The public URL of your deployment, with no trailing slash (http://localhost:3000 locally, https://your-project.vercel.app on Vercel). Used to generate project tracking snippets. |
Optional
| Variable | Description |
|---|---|
DATABASE_STORAGE_CAP_MB | Soft cap in MB shown as "storage used" in workspace and profile dashboards. Defaults to 512. |
CRON_SECRET | Secret token used to authenticate daily rollup cron requests (GET /api/cron/rollup). Vercel Cron sends this as Authorization: Bearer $CRON_SECRET. |
PAGEVIEW_RETENTION_DAYS | Optional number of days to retain raw pageview records before pruning during daily rollups. |
EVENT_RETENTION_DAYS | Optional number of days to retain raw custom event records before pruning during daily rollups. |
Legacy Environment Variables (v0.1.0 and prior)
| Old Variable | Replacement |
|---|---|
MONGODB_URI | DATABASE_URL |
MONGODB_DATABASE | Included in DATABASE_URL path |
MONGODB_STORAGE_CAP_MB | DATABASE_STORAGE_CAP_MB |
In version 0.1.1, the persistence layer migrated from MongoDB to PostgreSQL via Drizzle ORM. If you are upgrading from an existing MongoDB deployment, see our Migrating from MongoDB guide.
Notes
Authentication is database-backed — there is no global admin password environment variable. The first time you open a fresh deployment, you sign up to create the workspace owner account.
Where to set these
- Local development: create a
.env.localfile at the project root (see Setting Up Locally). - Vercel: Project → Settings → Environment Variables. Redeploy after changing
NEXT_PUBLIC_SITE_URL, since it affects generated tracking snippets. - Other hosts: set them however your platform injects environment variables into a Next.js build/runtime (Docker
-eflags, your PaaS's dashboard, etc).