Back to articles
DevOps & Systems

Building a Privacy-First Static Site Analytics System from a VPS Host with Umami and ClickHouse

Discover how to set up a privacy-first, self-hosted static site analytics system on a VPS using Umami and ClickHouse. This guide walks through step-by-step configuration, security...

DPTCloud Engineering4 min read
Building a Privacy-First Static Site Analytics System from a VPS Host with Umami and ClickHouse

Discover how to set up a privacy-first, self-hosted static site analytics system on a VPS using Umami and ClickHouse. This guide walks through step-by-step configuration, security hardening, performance optimization, and data integration, enabling you to track user behavior without third-party tracking tools. The system ensures compliance with GDPR and other data protection regulations, offering full control over user data. It is ideal for businesses, individuals, or organizations seeking to avoid dependency on platforms like Google Analytics.

Introduction to Privacy-First Static Site Analytics

In an era of growing user privacy concerns, replacing popular tracking tools like Google Analytics with self-hosted solutions is a logical choice. Umami is an open-source, lightweight, privacy-focused web analytics platform that does not track users or use cookies for data collection. When paired with ClickHouse—a high-performance real-time database system—you can store, query, and analyze user data quickly and securely. This setup allows you to maintain complete control over your data, from storage to analysis, without sharing information with third parties.

Requirements and VPS Environment Preparation

To deploy this system, you need a high-performance VPS. We recommend using NVMe Cloud VPS for Docker, Nginx & Databases to ensure high I/O speed and strong concurrent processing capabilities. The basic requirements include:

  • OS: Ubuntu 22.04 LTS or Debian 11
  • RAM: at least 4GB (8GB or more for high traffic)
  • Storage: 20GB SSD or larger
  • Docker and Docker Compose installed

Before starting, ensure you have a VPS account, SSH key setup, and system updates applied. You may also use High-Performance Dedicated Servers for Production Clusters if you need higher performance for larger scale operations.

Installing and Configuring Umami

Umami is a simple, lightweight, privacy-focused web analytics tool. You can deploy Umami using Docker Compose. Create a `docker-compose.yml` file with the following content:

version: '3.8'
services:
  umami:
    image: umami/umami:latest
    container_name: umami
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=clickhouse://clickhouse:8123/umami
      - DATABASE_TYPE=clickhouse
      - PORT=3000
      - ADMIN_USER=admin
      - ADMIN_PASSWORD=your_secure_password
    volumes:
      - ./data:/app/data
    depends_on:
      - clickhouse
  clickhouse:
    image: clickhouse/clickhouse-server:latest
    container_name: clickhouse
    restart: unless-stopped
    ports:
      - "8123:8123"
      - "9000:9000"
    volumes:
      - ./clickhouse/data:/var/lib/clickhouse
    ulimits:
      nofile:
        soft: 262144
        hard: 262144

Run the following command to start the services:

docker-compose up -d

After startup, access `http://your-vps-ip:3000` to log in and set up your first website. Umami will automatically connect to ClickHouse using the URL `clickhouse://clickhouse:8123/umami`.

Integration and Performance Optimization

Once Umami and ClickHouse are running stably, integrate the tracking script into your static website. Insert the following script into the `` section of each page:

<script async src="https://your-umami-domain.com/script.js" data-website-id="YOUR_WEBSITE_ID"></script>

To optimize performance, you should:

  • Use Nginx as a reverse proxy in front of Umami to manage HTTPS and load balancing.
  • Set up ClickHouse data storage with daily partitioning policies to speed up queries.
  • Apply security measures such as IP restrictions, firewall rules, and regular updates.

To verify data, you can access Umami’s admin interface or use the ClickHouse CLI:

docker exec -it clickhouse clickhouse-client --query="SELECT count(*) FROM umami.visits"

Troubleshooting and Maintenance

Common issues include:

  • Umami cannot connect to ClickHouse: Check the service name in `docker-compose.yml` and ensure ClickHouse is running.
  • Data not displaying: Verify that the tracking script is correctly inserted into the website and the website ID matches.
  • Slow performance: Optimize ClickHouse configuration with appropriate partitioning and indexing.

For system maintenance, you should:

  • Regularly back up ClickHouse and Umami data.
  • Update Docker, Umami, and ClickHouse periodically.
  • Monitor logs to detect issues early.

References

For deeper exploration of the technologies used, you may refer to:

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478