---
title: "How to self-host Umami with Next.js"
description: "Self-host Umami with Docker Compose, or on Vercel with Supabase or Neon Postgres. Set DATABASE_URL, APP_SECRET, and next/script."
canonical: https://datalighthouse.dev/guides/self-host-umami-analytics-nextjs
last-updated: 2026-12-03
---

# How to self-host Umami with Next.js
Self-host Umami with Docker Compose, or on Vercel with Supabase or Neon Postgres. Set DATABASE_URL, APP_SECRET, and next/script.
### 1. Set DATABASE_URL and APP_SECRET

Set DATABASE_URL to a PostgreSQL URL and APP_SECRET to the output of openssl rand -hex 32. Umami rejects an empty secret and the placeholder replace-me-with-a-random-string. On a pooled Supabase or Neon URL, also set DIRECT_DATABASE_URL to the direct connection so migrations skip the pooler. That split is supported from v3.2.0.

### 2. Start Umami with Docker Compose

Put APP_SECRET in a .env file beside the compose file, then run docker compose up -d. The master compose file checked on 3 December 2026 runs ghcr.io/umami-software/umami:latest and postgres:15-alpine, publishes port 3000, and stores Postgres in the named volume umami-db-data. Sign in as admin / umami and replace that password. v3.5.0 blocks the app until you do.

### 3. Deploy Umami on Vercel with Postgres

Fork umami-software/umami, import the fork in Vercel, and set DATABASE_URL and APP_SECRET. Use the Supabase pooler URL on port 6543 or the Neon pooler URL with pgbouncer=true as DATABASE_URL. Set DIRECT_DATABASE_URL to the non-pooled string. Deploy, open the Vercel URL, and change the admin password.

### 4. Add the tracker with next/script

In app/layout.tsx, load the self-hosted script.js with next/script and set data-website-id to the UUID from the website tracking code. Umami's collect-data page says to use next/script. Set data-domains to the production hostnames so localhost does not match. Single-page navigations are tracked with no extra code.

### 5. Send a custom event

Add data-umami-event on an element, or call umami.track('signup-button', { plan: 'pro' }). Event names are limited to 50 characters. Data attributes store every property as a string. Leave email addresses and tokens out of the payload.

### 6. Proxy the script with Next.js rewrites

Rewrite /stats.js to https://stats.example.com/script.js and /api/send to https://stats.example.com/api/send. Set data-host-url to the Next.js origin so the browser posts to your domain. A route handler on the same path wins over the rewrite. Cloud's collector host is gateway.umami.is. A self-hosted collector stays on your Umami origin.

### 7. Upgrade Umami and back up Postgres

For Compose, run docker compose pull and docker compose up --force-recreate -d. For a source install, run git pull, pnpm install, pnpm build, and restart. After a major upgrade, run ANALYZE in Postgres. Dump the compose database with pg_dump before you remove the umami-db-data volume. Changing APP_SECRET signs everyone out.

## FAQ
### How do I self-host Umami with Docker Compose?

Clone the Umami repository, write APP_SECRET in a .env file next to docker-compose.yml, and run docker compose up -d. Generate the secret with openssl rand -hex 32. The master compose file checked on 3 December 2026 uses ghcr.io/umami-software/umami:latest and postgres:15-alpine, listens on port 3000, and keeps Postgres in the volume umami-db-data. The first login is admin / umami. From v3.5.0 you replace that password before the app continues.

### Can I run Umami on Vercel with Supabase or Neon?

Yes. Umami's Vercel guide says to fork umami-software/umami, import it, and set DATABASE_URL and APP_SECRET. Point DATABASE_URL at the pooled string. Supabase's guide uses the pooler on port 6543 with pgbouncer=true and connection_limit=1. Neon's guide adds pgbouncer=true and connect_timeout=10 to the pooler URL. Set DIRECT_DATABASE_URL to the direct string so Prisma migrations skip the pooler. That variable exists from v3.2.0.

### What do DATABASE_URL and APP_SECRET do?

DATABASE_URL is the Postgres connection string. APP_SECRET signs login tokens and takes part in anonymous session ids. Each install needs its own secret. openssl rand -hex 32 is the command the environment page shows. An empty value, or the placeholder replace-me-with-a-random-string, is rejected. Replacing a live secret signs every user out, and visitors already seen in the current salt period count as new sessions.

### How do I add a self-hosted Umami script to Next.js?

Add next/script in app/layout.tsx. Set src to https://your-umami-host/script.js and data-website-id to the UUID on the tracking code screen. Umami's collect-data page says to use next/script. data-domains limits the tracker to hostnames you list, which keeps localhost out. The same page says single-page navigations are tracked with no extra code.

### How do I proxy Umami through Next.js rewrites?

In next.config, rewrite /stats.js to your Umami origin's /script.js and /api/send to that origin's /api/send. Load /stats.js and set data-host-url to your Next.js origin. The browser then posts to your domain. A route handler at the same path handles the request first. For a self-hosted instance, TRACKER_SCRIPT_NAME and COLLECT_API_ENDPOINT rename the script and the collector on the Umami server. The Cloud bypass example forwards /api/send to gateway.umami.is.

### How do I back up and upgrade self-hosted Umami?

Umami's update page tells Compose users to run docker compose pull and docker compose up --force-recreate -d. Source installs use git pull, pnpm install, pnpm build, and a restart. Run ANALYZE after a major upgrade so the Postgres planner refreshes statistics. The compose file stores data in the volume umami-db-data. Dump it with pg_dump before you delete that volume. The update page does not include a backup command. On Cloud, Umami's comparison table says Umami manages hosting, updates, backups, and scaling.

### When should I skip self-hosting Umami?

Skip it when you will not run backups, upgrades, or the admin password change. Umami Cloud is the hosted app. Email reports are listed as Cloud only. The open-source app and Cloud share the analytics reports, including the revenue report. A Stripe MRR dashboard is a separate job. Data Lighthouse is a Next.js template you host. The license is $59 once. Optional cards show succeeded-charge revenue, MRR from active subscriptions, ARR as that MRR times 12, and revenue per visitor. The overview does not compute churn. The tracker stores a visitor id in localStorage. The sample dashboard is at https://datalighthouse.dev/demo and pricing is at https://datalighthouse.dev/pricing.


## Sources
- [Umami: installation](https://docs.umami.is/docs/install)
- [Umami: environment variables](https://docs.umami.is/docs/environment-variables)
- [Umami: getting updates](https://docs.umami.is/docs/updates)
- [Umami: running on Vercel](https://docs.umami.is/docs/guides/running-on-vercel)
- [Umami: running on Supabase](https://docs.umami.is/docs/guides/running-on-supabase)
- [Umami: running on Neon](https://docs.umami.is/docs/guides/running-on-neon)
- [Umami: running on Railway](https://docs.umami.is/docs/guides/running-on-railway)
- [Umami: hosting](https://docs.umami.is/docs/guides/hosting)
- [Umami: collect data](https://docs.umami.is/docs/collect-data)
- [Umami: track events](https://docs.umami.is/docs/track-events)
- [Umami: tracker functions](https://docs.umami.is/docs/tracker-functions)
- [Umami: tracker configuration](https://docs.umami.is/docs/tracker-configuration)
- [Umami: bypass ad blockers](https://docs.umami.is/docs/bypass-ad-blockers)
- [Umami Cloud and self-hosted](https://docs.umami.is/docs/cloud)
- [Umami docker-compose.yml on master](https://github.com/umami-software/umami/blob/master/docker-compose.yml)
- [Umami LICENSE (MIT)](https://github.com/umami-software/umami/blob/master/LICENSE)
- [PostgreSQL: pg_dump](https://www.postgresql.org/docs/current/app-pgdump.html)
- [Docker Compose: down](https://docs.docker.com/reference/cli/docker/compose/down/)
- [Next.js: rewrites](https://nextjs.org/docs/app/api-reference/config/next-config-js/rewrites)
