# Plausible Analytics

> Plausible privacy-friendly web analytics alternative to Google Analytics.

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

## Overview

Plausible Analytics is an open-source, privacy-focused web analytics platform that serves as a lightweight alternative to Google Analytics. Founded in 2019, Plausible emphasizes user privacy by design, requiring no cookies, collecting no personal data, and maintaining full GDPR compliance while providing essential website insights. The platform generates a tracking script that's 45x smaller than Google Analytics, ensuring minimal impact on site performance. This stack combines Plausible with PostgreSQL for metadata storage and ClickHouse for high-performance event analytics. PostgreSQL handles user accounts, site configurations, and dashboard data with its robust ACID compliance, while ClickHouse excels at processing millions of pageview events with columnar storage optimized for real-time analytics queries. The dual-database architecture allows Plausible to maintain fast dashboard responses even when processing billions of events. This configuration is ideal for organizations prioritizing user privacy, regulatory compliance, and performance while maintaining comprehensive analytics capabilities. The stack eliminates dependency on third-party analytics services, provides complete data ownership, and offers transparent insights without compromising visitor privacy or requiring cookie consent banners.

## Features

- Privacy-first analytics with no cookies or personal data collection
- Lightweight 1.7KB tracking script that loads 45x faster than Google Analytics
- Real-time event processing using ClickHouse columnar database for billion-row analytics
- PostgreSQL-backed user management with ACID-compliant configuration storage
- GDPR, CCPA, and PECR compliant by design without requiring cookie banners
- Open-source transparency with self-hosted data ownership
- Simple dashboard showing essential metrics without complex goal funnels
- API access for custom integrations and automated reporting

## Use cases

- Privacy-conscious businesses replacing Google Analytics for GDPR compliance
- SaaS companies tracking product usage without compromising user privacy
- Publishers and bloggers monitoring content performance with lightweight tracking
- E-commerce sites analyzing traffic patterns while maintaining customer trust
- Government and healthcare organizations requiring strict data sovereignty
- Marketing agencies offering privacy-compliant analytics to clients
- Educational institutions tracking website engagement without student data concerns

## Prerequisites

- Docker Engine 20.10+ and Docker Compose v2 for container orchestration
- Minimum 4GB RAM (2GB for ClickHouse, 1GB for PostgreSQL, 1GB for Plausible)
- Domain name or public IP address for BASE_URL configuration
- Generated SECRET_KEY_BASE using openssl rand -base64 64 command
- Port 8000 available for Plausible web interface access
- Understanding of environment variables for initial admin account setup

## docker-compose.yml

```yaml
services:
  plausible:
    image: plausible/analytics:v2.0
    container_name: plausible
    command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
    environment:
      - BASE_URL=${BASE_URL}
      - SECRET_KEY_BASE=${SECRET_KEY_BASE}
      - DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/plausible
      - CLICKHOUSE_DATABASE_URL=http://clickhouse:8123/plausible
      - DISABLE_REGISTRATION=${DISABLE_REGISTRATION}
    ports:
      - "8000:8000"
    depends_on:
      postgres:
        condition: service_healthy
      clickhouse:
        condition: service_started
    networks:
      - plausible-network

  postgres:
    image: postgres:16-alpine
    container_name: plausible-db
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=plausible
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - plausible-network

  clickhouse:
    image: clickhouse/clickhouse-server:23.11-alpine
    container_name: plausible-events
    volumes:
      - clickhouse_data:/var/lib/clickhouse
    ulimits:
      nofile:
        soft: 262144
        hard: 262144
    networks:
      - plausible-network

volumes:
  postgres_data:
  clickhouse_data:

networks:
  plausible-network:
    driver: bridge
```

## .env

```bash
# Plausible Analytics
BASE_URL=http://localhost:8000
SECRET_KEY_BASE=your-secret-key-base-at-least-64-chars
POSTGRES_USER=plausible
POSTGRES_PASSWORD=plausible_password
DISABLE_REGISTRATION=false
```

## Usage notes

- Dashboard at http://localhost:8000
- Add script to your website
- GDPR compliant, no cookies
- Lightweight tracking script
- Set DISABLE_REGISTRATION=true after setup

## Troubleshooting

- Database connection errors during startup: Increase the sleep timer in the Plausible command from 10 to 30 seconds to allow PostgreSQL full initialization
- ClickHouse memory allocation failures: Increase Docker Desktop memory limit to 6GB+ or add memory limits to clickhouse service
- Site not showing in dashboard after adding script: Verify BASE_URL matches exactly including protocol (https://) and check browser console for CORS errors
- Registration disabled but can't access dashboard: Create admin user with docker-compose exec plausible /entrypoint.sh db create-admin command
- High memory usage over time: Configure ClickHouse data retention policies using TTL settings to automatically clean old analytics data
- Script blocked by ad blockers: Host Plausible on subdomain of tracked site or configure proxy to serve analytics script from same domain

