Environment Variables

diy-analytics is configured entirely through environment variables — there's no separate config file. This page is the full reference.

Required

VariableDescription
DATABASE_URLYour PostgreSQL connection string, e.g. postgres://user:password@host:5432/diy-analytics?sslmode=require. Used for every database read and write.
NEXT_PUBLIC_SITE_URLThe 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

VariableDescription
DATABASE_STORAGE_CAP_MBSoft cap in MB shown as "storage used" in workspace and profile dashboards. Defaults to 512.
CRON_SECRETSecret token used to authenticate daily rollup cron requests (GET /api/cron/rollup). Vercel Cron sends this as Authorization: Bearer $CRON_SECRET.
PAGEVIEW_RETENTION_DAYSOptional number of days to retain raw pageview records before pruning during daily rollups.
EVENT_RETENTION_DAYSOptional number of days to retain raw custom event records before pruning during daily rollups.

Legacy Environment Variables (v0.1.0 and prior)

Old VariableReplacement
MONGODB_URIDATABASE_URL
MONGODB_DATABASEIncluded in DATABASE_URL path
MONGODB_STORAGE_CAP_MBDATABASE_STORAGE_CAP_MB

Notes

Where to set these

  • Local development: create a .env.local file 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 -e flags, your PaaS's dashboard, etc).