How to self-host Umami with Next.js

How-to · Updated 3 December 2026

TL;DR

Docker Compose starts Umami and Postgres on a VPS. On Vercel, the Umami app uses DATABASE_URL from Supabase or Neon. Set APP_SECRET with openssl rand -hex 32, add script.js through next/script, and proxy /stats.js when an ad blocker drops the hostname.

Commands and env names below match Umami's docs and the master compose file as of 3 December 2026. Product comparisons stay on the Umami alternatives list.

License
$59 once
Refund
7-day no-questions refund
Stack
Next.js 16, shadcn/ui, Recharts, Postgres, Drizzle, Clerk, optional Stripe

On this page

Which host should you pick?

Use Docker Compose when Umami and Postgres should share one VPS. Use Vercel when the app deploys from a Git fork and Postgres already lives on Supabase or Neon. Use Railway when you want the one-click template in Umami's Railway guide.

HostWhat runsDatabaseUpdatesYou still own
Docker Compose on a VPSUmami and Postgres 15 in the official compose fileNamed volume umami-db-data on the VPSdocker compose pull, then up --force-recreateYou patch the host, terminate TLS, and keep the volume
Vercel plus managed PostgresA fork of umami-software/umami on VercelSupabase pooler on port 6543, or a Neon pooler URLMerge upstream and redeploy so the build migratesThe app and the database are separate bills and backups
Railway template or forkUmami service plus Railway PostgresDATABASE_URL referenced from the Railway databaseUse a fork when you want to pull upstream commitsThe template button creates a one-commit repository

Docker Compose on a VPS

Umami's install page ships a compose file with the app and a PostgreSQL database. The master file checked on 3 December 2026 pins ghcr.io/umami-software/umami:latest and postgres:15-alpine. It publishes port 3000. The database service publishes no host port.

The install page also documents a pull of docker.umami.is/umami-software/umami:latest. That image needs a database you already run, plus DATABASE_URL and APP_SECRET. The bundled compose file sets DATABASE_URL itself, pointed at the db service.

Vercel with Supabase or Neon

Umami's Vercel guide says to fork umami-software/umami, import the fork, and set DATABASE_URL and APP_SECRET. The same guide points at the Supabase and Neon pages when you still need a database. It also says Vercel provides a free hosting service for Next.js applications. Current Vercel prices are on Vercel's pricing page.

A pooled URL belongs in DATABASE_URL. Migrations use DIRECT_DATABASE_URL, supported from v3.2.0. Supabase's guide uses the pooler on port 6543 and the session connection on port 5432. Neon's guide uses the -pooler host for the app and the host without that label for migrations.

Railway and the other app hosts

Umami's Railway guide documents a template button and a fork path. The button deploys Umami and a Postgres database. The guide says that button creates a new repository with a single commit. A fork is the path when you want upstream commits. The fork steps set PORT, DATABASE_TYPE, and HOSTNAME, then reference DATABASE_URL from Railway Postgres and add APP_SECRET.

The hosting guide, read on 3 December 2026, lists Vercel, Netlify, Render, and Northflank as app hosts and says a free tier is available. It lists Neon and Supabase as managed databases. Current prices for those hosts are on each vendor's pricing page. The Railway guide calls Railway a free hosting service. Plan limits change, so read the vendor page before you budget.

A source install is the other official path. It needs Node.js 20.19 or newer, with 22 LTS recommended, and PostgreSQL 12.14 or newer. The install page also links a third-party Helm chart. The Docker image carries its own Node.js, so the Node floor applies to a source build. Steps for that build stay on the install page. The two walks below are Compose and Vercel.

Which environment variables does Umami require?

Every install needs DATABASE_URL and APP_SECRET. DATABASE_URL is the Postgres connection string. APP_SECRET signs login tokens and takes part in anonymous session ids.

Generate the secret with openssl rand -hex 32. Umami rejects an empty value and the placeholder replace-me-with-a-random-string. From v3.5.0 there is no fallback to DATABASE_URL. If an older install never set a secret, the environment page says to copy the exact DATABASE_URL into APP_SECRET so existing logins and the current salt period stay intact.

A new secret signs everyone out. Visitors already seen in the current salt period then count as new sessions. Keep the value stable across deploys.

.env beside the compose file, or in the Vercel project
# openssl rand -hex 32
APP_SECRET=your-64-hex-characters

Pooled Supabase and Neon URLs need a second variable. Set DIRECT_DATABASE_URL to the direct connection. Umami uses it for Prisma migrations during check-db. The environment page says this split is for a pooled DATABASE_URL that should stay off the migration path. Support starts at v3.2.0.

The install page recommends UTC on Postgres so timestamps stay put when the server timezone changes. The compose file checked on 3 December 2026 does not set a timezone variable. Set UTC on the database before you trust a daily chart.

TWO_FACTOR_ENCRYPTION_KEY is a separate 64-character hex string. It is required before anyone can turn on two-factor sign-in. The compose file ships a placeholder. Replace that placeholder before you enable two-factor. Generate it with the same openssl rand -hex 32 command.

TRACKER_SCRIPT_NAME and COLLECT_API_ENDPOINT rename the public script and the collector. They show up again in the proxy section. DISABLE_TELEMETRY=1 turns off the anonymous telemetry the environment page describes.

How do you start Umami with Docker Compose?

Clone the repository, create the .env file, then start the stack. The compose file refuses to start when APP_SECRET is missing.

Compose shape from docker-compose.yml on master, 3 December 2026. Healthcheck, restart, and init lines are omitted. Password and two-factor values are variables in this excerpt.
services:
  umami:
    image: ghcr.io/umami-software/umami:latest
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgresql://umami:${POSTGRES_PASSWORD}@db:5432/umami
      APP_SECRET: ${APP_SECRET:?Set APP_SECRET in your .env file}
      TWO_FACTOR_ENCRYPTION_KEY: ${TWO_FACTOR_ENCRYPTION_KEY}
    depends_on:
      db:
        condition: service_healthy
  db:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: umami
      POSTGRES_USER: umami
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - umami-db-data:/var/lib/postgresql/data
volumes:
  umami-db-data:
Start the stack
docker compose up -d

The app listens on http://localhost:3000. The compose healthcheck requests http://localhost:3000/api/heartbeat. The first login is username admin and password umami. From v3.5.0, Umami asks you to replace that password before you can continue.

The database user, password, and database name in that file are all umami. The db service does not publish port 5432 to the host. If you publish it, change POSTGRES_PASSWORD and the password inside DATABASE_URL together.

Postgres data sits in the named volume umami-db-data, mounted at /var/lib/postgresql/data. Put TLS in front of port 3000 before the instance is public. The install page points at a reverse proxy, or at changing the listen port.

Minimum Postgres on the install page is 12.14. The compose pin checked on 3 December 2026 is postgres:15-alpine.

How do you run Umami on Vercel with Postgres?

Fork https://github.com/umami-software/umami. Create a Vercel account. Import the fork. Add DATABASE_URL and APP_SECRET. Deploy. Open the .vercel.app URL, sign in as admin / umami, and change the password.

Umami's Vercel page has a deploy button that fills the same two variables. The first build checks the database and creates the tables. A pooled string still needs DIRECT_DATABASE_URL.

Supabase connection strings

Create the Supabase project in a region close to the Vercel region. In Settings, then Database, copy the pooled connection string. Umami's Supabase guide uses port 6543 for DATABASE_URL and port 5432 for DIRECT_DATABASE_URL. The shapes below are the ones that guide prints. Replace the bracketed parts with the dashboard values.

Supabase URLs from Umami's Supabase guide
DATABASE_URL=postgresql://[db-user].[project-ref]:[db-password]@aws-0-[aws-region].pooler.supabase.com:6543/[db-name]?pgbouncer=true&connection_limit=1
DIRECT_DATABASE_URL=postgresql://[db-user].[project-ref]:[db-password]@aws-0-[aws-region].pooler.supabase.com:5432/[db-name]

Neon connection strings

Create the Neon project near the Vercel region. Copy the pooled connection string. Append ?pgbouncer=true&connect_timeout=10. Put the direct string, without the pooler host, in DIRECT_DATABASE_URL.

Neon URL shape from Umami's Neon guide. User and password stay placeholders.
DATABASE_URL=postgresql://[user]:[password]@endpoint-pooler.region.aws.neon.tech/neondb?pgbouncer=true&connect_timeout=10
DIRECT_DATABASE_URL=postgresql://[user]:[password]@endpoint.region.aws.neon.tech/neondb

The Neon guide also shows pnpm dlx neonctl projects create and pnpm dlx neonctl connection-string, with --pooled for the app URL. Then run pnpm build if you are building from source against that database. On Vercel, the import build is the step that creates the tables.

Railway fork variables

The fork path in the Railway guide sets these three variables, then adds Postgres and references its DATABASE_URL. The first deploy fails until that reference exists. Add APP_SECRET in the same variables tab.

Railway fork variables from Umami's Railway guide
PORT=3000
DATABASE_TYPE=postgresql
HOSTNAME=0.0.0.0

HOSTNAME=0.0.0.0 matches the bind address a container platform expects. DATABASE_TYPE=postgresql is the build-time variable the environment page says the Docker build reads. The Vercel guide lists DATABASE_URL and APP_SECRET.

How do you add the tracker to a Next.js app?

The website screen in Umami shows a tracking code after you add a website. Copy the website id. For a self-hosted instance, script.js lives on that instance, for example https://stats.example.com/script.js. Cloud's host cloud.umami.is is a different deployment.

Umami's collect-data page says to insert the snippet with next/script in the App Router. Put it in app/layout.tsx so every route loads it. data-domains is matched against window.location.hostname. List the production hosts, including www when you use it. localhost then fails the match.

app/layout.tsx
import Script from "next/script"

const umamiSrc = process.env.NEXT_PUBLIC_UMAMI_SCRIPT_URL
const umamiWebsiteId = process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {umamiSrc && umamiWebsiteId ? (
          <Script
            defer
            src={umamiSrc}
            strategy="afterInteractive"
            data-website-id={umamiWebsiteId}
            data-domains="example.com,www.example.com"
          />
        ) : null}
        {children}
      </body>
    </html>
  )
}

NEXT_PUBLIC_UMAMI_SCRIPT_URL and NEXT_PUBLIC_UMAMI_WEBSITE_ID ship in the browser bundle. They are public. Keep APP_SECRET and DATABASE_URL on the Umami server only.

The collect-data page says single-page navigations are tracked with no extra code. Leave data-auto-pageview unset. If a client click sends no second pageview, the Next.js install guide for Plausible and Umami shows the manual umami.track() path and the double-count trap.

Open the site, then the browser network panel. You want a successful load of script.js and a POST to /api/send. The collect-data page names ad blockers as a reason the script never loads. The next sections cover events and the rewrite.

How do you send a custom Umami event?

Custom events have been available since v2.0.0. Two methods are on the track-events page. A data attribute records the click. umami.track() records it from your own handler.

Event names are limited to 50 characters. Umami rejects event data that has no event name. Data attributes store every extra property as a string. The JavaScript call can send numbers. The track-events page also says other listeners inside an element with data-umami-event do not run. Use one method on a given control.

Data attribute. Properties stay strings.
<button type="button" data-umami-event="signup-button" data-umami-event-plan="pro">
  Start trial
</button>
umami.track from a client component
"use client"

declare global {
  interface Window {
    umami?: {
      track: (event: string, data?: Record<string, string | number>) => void
    }
  }
}

export function SignupButton() {
  return (
    <button
      type="button"
      onClick={() => {
        window.umami?.track("signup-button", { plan: "pro" })
      }}
    >
      Start trial
    </button>
  )
}

Leave email addresses, account ids, and tokens out of the payload. The tracker configuration page says a distinct id is visible in the HTML and should be an internal id, with a 50-character limit. That id is a different choice than an anonymous pageview. Read the privacy-friendly Next.js install before you add one.

Recorded events show on the website Events page. Properties show on the Properties tab. A Stripe charge is still a billing record. The guide to tracking Stripe revenue after Checkout shows where a revenue event stops and MRR starts.

How do you proxy Umami with Next.js rewrites?

Ad blockers can block a hostname or the path script.js. Umami's bypass page lists three responses: proxy the script and the collector, host a saved copy of the script, or rename both on a self-hosted server.

A self-hosted collector is /api/send on your Umami origin. Point both rewrites at that origin. Set data-host-url to the Next.js site so the browser posts to your domain. Default behavior sends data to the host that served the script.data-host-url overrides that host.

next.config rewrites for a self-hosted origin
/** @type {import('next').NextConfig} */
const nextConfig = {
  async rewrites() {
    return [
      {
        source: "/stats.js",
        destination: "https://stats.example.com/script.js",
      },
      {
        source: "/api/send",
        destination: "https://stats.example.com/api/send",
      },
    ]
  },
}

export default nextConfig
Script tag that posts to the Next.js origin
<Script
  defer
  src="/stats.js"
  strategy="afterInteractive"
  data-website-id={process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID}
  data-host-url="https://example.com"
  data-domains="example.com,www.example.com"
/>

Rewrites in the default rewrites() list run after a matching route. A file at app/api/send/route.ts handles /api/send, and the rewrite does not. Pick a free path, or rename the collector.

On the Umami server, TRACKER_SCRIPT_NAME renames script.js. COLLECT_API_ENDPOINT renames /api/send. The script Umami serves then calls the new path. Your rewrite source has to match that path.

Rename the script and collector on the Umami server
TRACKER_SCRIPT_NAME=x.js
COLLECT_API_ENDPOINT=/api/x

Umami's Vercel guide shows a different rewrite for Umami Cloud. It proxies /stats/:match* to https://cloud.umami.is/:match*. The sample script uses /stats/script.js. The bypass page says the Cloud script posts to gateway.umami.is unless data-host-url points at your domain. Use the Cloud destination only when the account is Cloud.

vercel.json example from Umami's Vercel guide, for Cloud
{
  "rewrites": [
    {
      "source": "/stats/:match*",
      "destination": "https://cloud.umami.is/:match*"
    }
  ]
}

Saving script.js onto your own host is the third method on the bypass page. The page says you download it again after the tracker changes. A rewrite stays current because it fetches the live file.

How do you upgrade Umami and back up Postgres?

Umami's update page splits source installs from Docker. Take a database dump first. The update page does not include a backup command. The compose volume is the data you would lose.

Logical dump of the database named in the compose file
docker compose exec -T db pg_dump -U umami -d umami > umami.sql

pg_dump ships in the official Postgres image. The command uses the user and database name from the compose file checked on 3 December 2026. Store the SQL file off the VPS. Supabase and Neon document their own backup controls. Retention periods are on each provider's backup page.

Docker's compose down reference removes containers and networks. Named volumes stay until you pass the flag that removes them. Deleting umami-db-data deletes the analytics database. Dump first.

Apply the update

Compose pulls whatever image the file names, then recreates the containers:

Update a Docker Compose install
docker compose pull
docker compose up --force-recreate -d

A prebuilt container that you started without compose follows the update page's pull of docker.umami.is/umami-software/umami:latest, then a restart. That registry and the ghcr.io image in the compose file are both on the docs and the file. Pull the image your service already runs.

A source checkout updates in the Umami directory:

Update a source install
git pull
pnpm install
pnpm build
pnpm start

If PM2 owns the process, the update page says pm2 restart umami instead of a second pnpm start. On Vercel, merge upstream into the fork and redeploy. The build runs migrations. A Railway fork is the same idea: pull upstream, then redeploy. The one-commit template repository has no upstream remote until you add one.

Before v3.5.0, set APP_SECRET. Node.js 20.19 or newer is required for a source install. Node.js 22 LTS is the recommendation. The Docker image includes its own Node.js. Password changes moved to Settings, then Security. The release runs the 27_add_error_tracking migration on pnpm build and when the container starts.

After a major upgrade, the update page says the query planner can keep stale statistics. Run this in the Umami database. The page says it is safe on a live database.

Refresh Postgres statistics
ANALYZE;

Keep APP_SECRET the same value across the upgrade unless you intend to sign everyone out.

What does it cost to keep Umami running?

The LICENSE file on master, read on 3 December 2026, is the MIT License. That file charges no fee. You pay for the VPS, or for Vercel plus the database, or for Railway.

Umami's hosting guide says a free tier is available for Vercel, Netlify, Render, and Northflank. The Railway guide says Railway provides a free hosting service. Those sentences are the vendor claims inside Umami's guides on 3 December 2026. Current dollar amounts and quotas are on each vendor's pricing page.

Cloud plan limits and prices stay on umami.is/pricing. The Umami alternatives page records a 25 November 2026 reading of those plans. Use that page when you want the dated figures. Use umami.is/pricing when you want the current table.

Maintenance is the other cost. You pull images or merge upstream. You run ANALYZE after a major upgrade. You dump umami-db-data or confirm the managed database has backups. You change the default admin password. You keep APP_SECRETstable. You terminate TLS on a VPS. Umami's Cloud comparison assigns hosting, updates, backups, and scaling to you on the self-hosted row, and to Umami on the Cloud row.

Email reports are the capability that comparison marks Cloud only, on Pro, Business, and Enterprise. Web analytics, custom events, funnels, goals, journeys, retention, UTM, revenue, and attribution are in both columns. Teams, links, and API access are included on self-hosted. Session replays are included on self-hosted from v3.1. Heatmaps are included from v3.2. On Cloud, those two reports are on Business and Enterprise.

When should you skip self-hosting?

Skip the server when nobody will apply updates or keep a backup. Umami Cloud is the hosted app from the same project. Signup is at cloud.umami.is. The Cloud overview says the open-source platform and Cloud share the same analytics reports, and that some Cloud plan items depend on the plan.

Skip Umami itself when the question is which product to buy. That comparison is the Umami alternatives list and the Plausible alternatives list. Head-to-head price and hosting notes stay on the Umami vs Plausible page.

Skip both when the report you want is Stripe subscription math inside a Next.js dashboard you own. Umami's revenue report is included on self-hosted. Monthly recurring revenue still needs your own rule for active subscriptions. The Stripe revenue event guideshows the event you can send after Checkout. MRR, ARR, and revenue per visitor are the template's cards.

Data Lighthouse is that template. You host it. The license is $59 once. The pricing page also shows $99 as a compare-at price. Optional Stripe cards show revenue for 7, 14, or 30 days from succeeded charges. Refunds are not subtracted. MRR counts subscriptions with status active, normalized to one month. ARR is that MRR times 12. Revenue per visitor uses distinct visitors in Postgres for the same window.

The overview does not compute churn. The tracker stores a visitor id in localStorage. It is a different privacy choice than Umami's script. The live demo renders sample data. Pricing is the license page.

7-day no-questions refund. If the template is not a fit, request it within 7 days through the purchase contact on the contact page.

Self-hosted Umami FAQ

Short answers for Compose, Vercel with Postgres, the script, the rewrite, backups, and the point where a server is the wrong tool.

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