Self-Hosted Analytics with Umami: A Privacy-Friendly Google Analytics Alternative
A complete guide to setting up self-hosted Umami analytics as a Google Analytics alternative that is privacy-friendly, fast, and keeps your data entirely yours.
- Why Umami?
- The Advantages of Umami vs Google Analytics
- When Should You Use Umami?
- Setting Up Umami with Docker
- Step 1: Preparation
- Step 2: Clone Umami
- Step 3: Configure the Environment
- Step 4: Create the Docker Compose File
- Step 5: Run Umami
- Step 6: Log In
- Website Configuration
- Step 1: Add a Website
- Step 2: Get the Tracking Code
- Step 3: Install on Your Website
- Setup in Astro (ByteNesia)
- Umami Features
- 1. Real-time Analytics
- 2. Custom Events
- 3. Goal Tracking
- 4. Custom Dashboard
- Backup and Maintenance
- Back Up the Database
- Update Umami
- Monitoring
- Deploying Umami on a Server
- Using Cloudflare Tunnel
- Security Hardening
- Comparison with Other Analytics Tools
- Case Study: Umami for ByteNesia
- Requirements:
- Solution:
- Results:
- Conclusion
Google Analytics is powerful, but there is a price to pay: your visitors’ data is sent to Google. For those who care about privacy, Umami is an excellent alternative. Analytics that is entirely yours, hosted on your own server.
Why Umami?
The Advantages of Umami vs Google Analytics
| Feature | Umami | Google Analytics |
|---|---|---|
| Self-hosted | Yes | No |
| Privacy-friendly | Yes (GDPR compliant) | No |
| Open source | Yes | No |
| No cookies | Yes | No |
| Fast | Very lightweight | Heavy |
| Data ownership | 100% yours | Google’s |
| Cost | Free | Free (but data = payment) |
When Should You Use Umami?
- You care about visitor privacy
- You want your analytics data to remain yours
- You don’t need GA’s complex features (funnels, attribution, etc.)
- You want analytics that is lightweight and fast
- You host your own website in a homelab
Setting Up Umami with Docker
Step 1: Preparation
Make sure Docker and Docker Compose are installed:
# Check Docker
docker --version
# Check Docker Compose
docker-compose --version
Step 2: Clone Umami
# Create directory
mkdir -p ~/umami && cd ~/umami
# Clone repository
git clone https://github.com/umami-software/umami.git .
# Enter directory
cd umami
Step 3: Configure the Environment
# Copy environment template
cp .env.example .env
Edit the .env file:
# Database
DATABASE_URL=postgresql://umami:your_password@db:5432/umami
DATABASE_TYPE=postgresql
# App
APP_SECRET=your_random_secret_key_here
Generate a random secret:
# Generate random string
openssl rand -base64 32
Step 4: Create the Docker Compose File
# docker-compose.yml
version: '3'
services:
umami:
image: ghcr.io/umami-software/umami:postgresql-latest
ports:
- "3000:3000"
environment:
DATABASE_URL: postgresql://umami:your_password@db:5432/umami
DATABASE_TYPE: postgresql
APP_SECRET: your_random_secret_key
depends_on:
db:
condition: service_healthy
restart: always
db:
image: postgres:15-alpine
environment:
POSTGRES_DB: umami
POSTGRES_USER: umami
POSTGRES_PASSWORD: your_password
volumes:
- umami-db-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U umami"]
interval: 5s
timeout: 5s
retries: 5
restart: always
volumes:
umami-db-data:
Step 5: Run Umami
# Build and run
docker-compose up -d
# Check status
docker-compose ps
# View logs
docker-compose logs -f
Step 6: Log In
Open your browser and go to:
http://localhost:3000
Default credentials:
- Username:
admin - Password:
umami
Change the password immediately after your first login!
Website Configuration
Step 1: Add a Website
- Log in to the Umami dashboard
- Click + Add Website
- Enter the website name and URL
- Click Save
Step 2: Get the Tracking Code
After adding a website, Umami will provide a tracking code:
<script
defer
src="https://your-umami-domain.com/script.js"
data-website-id="your-website-id"
></script>
Step 3: Install on Your Website
Add the tracking code before the </head> tag on your website:
<!DOCTYPE html>
<html>
<head>
<!-- ... other meta tags ... -->
<script
defer
src="https://your-umami-domain.com/script.js"
data-website-id="your-website-id"
></script>
</head>
<body>
<!-- ... website content ... -->
</body>
</html>
Setup in Astro (ByteNesia)
If you use Astro like ByteNesia does:
---
// src/layouts/BaseLayout.astro
---
<!DOCTYPE html>
<html lang="id">
<head>
<!-- ... other meta tags ... -->
<!-- Umami Analytics -->
<script
defer
src="https://analytics.bytenesia.afrizalab.my.id/script.js"
data-website-id="your-website-id"
></script>
</head>
<body>
<slot />
</body>
</html>
Umami Features
1. Real-time Analytics
Umami displays real-time data without delay. You can see:
- Current active visitors
- Pages currently being viewed
- Referrer sources
- Browser and device info
2. Custom Events
You can track custom events:
// Track button click
umami.track('button-click', { button: 'subscribe' });
// Track form submission
umami.track('form-submit', { form: 'contact' });
// Track file download
umami.track('file-download', { file: 'ebook.pdf' });
3. Goal Tracking
Set up goals to track conversions:
- Newsletter signups
- Product purchases
- Form submissions
- Time on page
4. Custom Dashboard
Create a dashboard that fits your needs:
- Most popular pages
- Top referrers
- Browser distribution
- Country/city analytics
Backup and Maintenance
Back Up the Database
# Backup Umami database
docker exec umami-db-1 pg_dump -U umami umami > umami-backup.sql
# Restore database
cat umami-backup.sql | docker exec -i umami-db-1 psql -U umami umami
Update Umami
# Pull the latest update
docker-compose pull
# Restart with the update
docker-compose up -d
# Clean up old images
docker image prune
Monitoring
# Check resource usage
docker stats umami
# Check logs
docker-compose logs --tail=100 umami
Deploying Umami on a Server
Using Cloudflare Tunnel
If you want to access Umami from anywhere:
# Add a route in the Cloudflare Tunnel config
# /etc/cloudflared/config.yml
ingress:
- hostname: analytics.yourdomain.com
service: http://localhost:3000
- service: http_status:404
Security Hardening
# Restrict access to specific IPs only
# In the nginx config:
location / {
allow 192.168.1.0/24;
deny all;
proxy_pass http://localhost:3000;
}
Comparison with Other Analytics Tools
| Feature | Umami | Plausible | Matomo | GA4 |
|---|---|---|---|---|
| Self-hosted | Yes | Yes (paid) | Yes | No |
| Price | Free | $9/month | Free | Free |
| GDPR | Yes | Yes | Yes | No |
| Cookies | No | No | Yes | Yes |
| Open source | Yes | Yes | Yes | No |
| Performance | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ |
Case Study: Umami for ByteNesia
Requirements:
- Track visitors without Google Analytics
- Privacy-friendly for Indonesian visitors
- Keep analytics data owned by us
- No need for complex GA4 features
Solution:
- Platform: Umami on Docker
- Database: PostgreSQL
- Domain: analytics.bytenesia.afrizalab.my.id
- Server: Homelab yukikatherina
Results:
- Real-time analytics without cookies
- Page views, referrers, and devices tracked
- Data 100% owned by us
- Faster website loading times (without the GA script)
Conclusion
Umami is an excellent Google Analytics alternative for those who care about privacy and want to own their analytics data. It’s easy to set up with Docker, its features are sufficient for basic analytics needs, and most importantly, your visitors’ data remains yours.
Related Articles
Getting Started with a Homelab: A Complete Guide for Beginners
Learn how to build your own homelab from scratch, covering hardware selection, software setup, and practical tips to get your first server running.
HomelabProxmox VE: Virtualization for the Homelab
Install and use Proxmox VE in a homelab: create VMs and LXC containers, configure storage, snapshots, integrated backups, and why one server should be virtualized.
HomelabServer Monitoring with Grafana & Prometheus
A homelab monitoring guide with Grafana and Prometheus. Install node_exporter, scrape metrics, build dashboards, and set alerts so problems surface early.
Your ideas deserve to be read by thousands of people.
ByteNesia is built for everyone. If you have experience, tutorials, or opinions about technology, write and share them here. Your name will be credited as a contributor.
Write anything: tool reviews, homelab tutorials, security tips, or your tech stories.