# Plausible Analytics

> Lightweight, privacy-friendly Google Analytics alternative

- Category: Monitoring & Observability
- Difficulty: intermediate
- Components: plausible, postgres, clickhouse
- Tags: analytics, privacy, metrics, tracking, gdpr
- Source: https://docker.recipes/monitoring/plausible

## Overview

Plausible Analytics is a lightweight, open-source web analytics platform that serves as a privacy-focused alternative to Google Analytics. Developed with GDPR, CCPA, and PECR compliance in mind, Plausible delivers essential website metrics without using cookies or collecting personal data. The platform provides a clean, intuitive dashboard that displays visitor counts, page views, traffic sources, and device information while maintaining user privacy through data anonymization and aggregation.

This stack combines Plausible with PostgreSQL and ClickHouse to create a powerful dual-database architecture optimized for both operational and analytical workloads. PostgreSQL handles user accounts, site configurations, and application metadata with its robust ACID compliance and relational integrity. ClickHouse manages the high-volume event data from website visitors, leveraging its columnar storage and real-time query capabilities to process millions of pageviews efficiently. This separation allows Plausible to maintain fast dashboard performance even with large traffic volumes.

This configuration is ideal for privacy-conscious organizations, European businesses requiring GDPR compliance, and anyone seeking full control over their analytics data. The self-hosted approach eliminates third-party data sharing while providing enterprise-grade analytics capabilities. Startups can avoid Google Analytics' data sampling limitations, while larger organizations benefit from unlimited data retention and custom reporting without per-seat licensing costs.

## Features

- Cookie-free tracking with <1KB JavaScript snippet that doesn't impact site performance
- Real-time visitor analytics with ClickHouse-powered sub-second query responses
- PostgreSQL-backed user management supporting multiple team members and site ownership
- GDPR-compliant data collection with automatic IP anonymization and EU data residency
- Custom event tracking and goal conversion measurement without personal data collection
- ClickHouse columnar compression reducing storage requirements by 80% compared to traditional databases
- Built-in referrer spam filtering and bot detection using PostgreSQL pattern matching
- Open-source transparency allowing full audit of data collection and processing methods

## Use cases

- European businesses needing GDPR-compliant analytics without consent banners or cookie notices
- Privacy-focused websites wanting visitor insights without compromising user anonymity
- High-traffic sites requiring real-time analytics with ClickHouse's billion-row processing capabilities
- Organizations avoiding Google's data collection while maintaining comprehensive traffic analysis
- SaaS companies tracking product usage and conversion funnels with custom event goals
- News and content sites monitoring article performance and reader engagement patterns
- E-commerce platforms analyzing visitor behavior without storing personal shopping data

## Prerequisites

- Minimum 4GB RAM to support ClickHouse's in-memory operations and PostgreSQL concurrency
- Docker Engine 20.10+ with docker-compose for multi-container orchestration
- Available ports 8000 (Plausible), 5432 (PostgreSQL), and 8123 (ClickHouse) or custom port mapping
- Generate secure SECRET_KEY_BASE using openssl rand -base64 64 for session encryption
- Domain name or reverse proxy setup for production BASE_URL configuration
- Understanding of basic SQL for custom ClickHouse queries and PostgreSQL user management

## docker-compose.yml

```yaml
services:
  plausible:
    image: plausible/analytics:latest
    container_name: plausible
    restart: unless-stopped
    command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
    ports:
      - "${PLAUSIBLE_PORT:-8000}:8000"
    environment:
      - BASE_URL=${BASE_URL:-http://localhost:8000}
      - SECRET_KEY_BASE=${SECRET_KEY_BASE}
      - DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@plausible_db:5432/plausible_db
      - CLICKHOUSE_DATABASE_URL=http://plausible_events_db:8123/plausible_events_db
    depends_on:
      - plausible_db
      - plausible_events_db

  plausible_db:
    image: postgres:16-alpine
    container_name: plausible_db
    restart: unless-stopped
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=plausible_db
    volumes:
      - plausible_db_data:/var/lib/postgresql/data

  plausible_events_db:
    image: clickhouse/clickhouse-server:latest
    container_name: plausible_events_db
    restart: unless-stopped
    volumes:
      - plausible_events_data:/var/lib/clickhouse
    ulimits:
      nofile:
        soft: 262144
        hard: 262144

volumes:
  plausible_db_data:
  plausible_events_data:
```

## .env

```bash
# Plausible Configuration
PLAUSIBLE_PORT=8000

# Your site URL
BASE_URL=http://localhost:8000

# Secret key (generate with: openssl rand -base64 64)
SECRET_KEY_BASE=your-64-char-secret-key

# Database password
POSTGRES_PASSWORD=postgres

# Optional: Email (for registration)
# MAILER_EMAIL=hello@plausible.local
# SMTP_HOST_ADDR=mail.example.com
```

## Usage notes

- Dashboard at http://localhost:8000
- First visit creates admin account
- Add tracking script to your sites
- GDPR compliant - no cookies by default
- Lightweight ~1KB tracking script
- Self-hosted = you own your data

## Troubleshooting

- ClickHouse 'Cannot allocate memory' errors: Increase Docker memory limits to 4GB+ and set ClickHouse max_memory_usage
- Plausible 'Database migration failed' on startup: Ensure PostgreSQL is fully ready before Plausible starts, increase sleep time in command
- Missing SECRET_KEY_BASE causes 'KeyError' on first access: Generate 64-character base64 key and restart all services
- ClickHouse connection refused: Verify port 8123 accessibility and check ClickHouse container logs for initialization errors
- PostgreSQL 'password authentication failed': Confirm POSTGRES_PASSWORD matches in both DATABASE_URL and PostgreSQL environment
- High memory usage from ClickHouse: Configure max_memory_usage and max_bytes_before_external_group_by in ClickHouse settings

