Personal Plausible Analytics Setup Guide
2025/04/23

Personal Plausible Analytics Setup Guide

A complete guide on setting up your own Plausible Analytics instance, including server deployment, HTTPS configuration, Nginx reverse proxy setup, and website integration


Plausible Analytics is an open-source, lightweight, and privacy-focused website analytics tool that offers several advantages over Google Analytics:

  • Lightweight: Only 2KB in size, 45 times smaller than Google Analytics
  • Cookie-free: No cookies by default, eliminating the need for annoying cookie banners
  • Privacy-focused: No personal data collection, fully compliant with GDPR, CCPA, and other regulations
  • Open source: Completely open-source code that you can audit yourself
  • Simple interface: One-page dashboard with key metrics at a glance
  • Self-hosting option: Complete control over your own data

Plausible Analytics Dashboard

1. Prerequisites

  • A cloud server (I'm using Tencent Cloud with their current promotion until 2025-04-30, overseas servers at 99/year, using Ubuntu Server 22.04 LTS)
  • A domain name (I bought one from Spaceship for around $10-15 per year)
  • Basic command line knowledge

Server Setup

2. Deploying Plausible on Server

Plausible provides a Docker deployment method that's very convenient. Here are the key steps:

Install Docker and Docker Compose

sudo apt update
sudo apt install docker.io docker-compose

Create Plausible Configuration Directory

mkdir -p plausible
cd plausible

Download Docker Configuration Files

wget https://raw.githubusercontent.com/plausible/hosting/master/docker-compose.yml
wget https://raw.githubusercontent.com/plausible/hosting/master/plausible-conf.env

Modify Configuration File

Set basic parameters in plausible-conf.env, including admin email, website domain, etc.

Start Plausible Service

docker-compose up -d

This will run the Plausible service on port 8000 of your server.

3. Setting Up HTTPS Access

To ensure the analytics script loads properly on HTTPS websites, we need to configure secure access for Plausible. I recommend using Cloudflare:

Register Cloudflare Account

If you don't have a Cloudflare account, register one and add your domain

Cloudflare Setup

Configure DNS Records

  • Add an A record pointing your domain to your server IP
  • Ensure proxy status is "Proxied" (orange cloud icon)

DNS Setup

Configure SSL/TLS

  • In Cloudflare control panel, set SSL/TLS to "Flexible" mode
  • This way, user to Cloudflare is HTTPS, Cloudflare to server is HTTP

SSL Setup

Change Domain Name Servers

  • At your domain registrar, point DNS servers to Cloudflare's provided nameservers (the two NS values in the screenshot)
  • Wait for DNS propagation (officially 24 hours, but usually much faster, typically seconds to minutes)

Nameserver Setup

4. Configuring Nginx Reverse Proxy

To properly forward domain requests to the Plausible service, you need to configure Nginx:

Create Nginx Configuration File

sudo nano /etc/nginx/sites-available/your-domain

Add the Following Configuration

server {
    listen 80;
    server_name your-domain;

    location / {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # WebSocket support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;
    }
}

Enable Configuration and Restart Nginx

sudo ln -s /etc/nginx/sites-available/your-domain /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

5. Integrating Plausible into Your Website

The final step is adding the analytics script to your website. Using Next.js as an example:

Create Plausible.tsx Component

// src/components/analytics/Plausible.tsx
'use client'

import Script from 'next/script'

export function Plausible() {
  return (
    <>
      <Script
        defer
        data-domain="your-website-domain"
        src="https://your-plausible-domain.com/js/script.js"
        strategy="afterInteractive"
      />
      <Script id="plausible-setup" strategy="afterInteractive">
        {`
          window.plausible = window.plausible || function() {
            (window.plausible.q = window.plausible.q || []).push(arguments)
          }
        `}
      </Script>
    </>
  )
}

export default Plausible

Import Component in Application

// src/app/layout.tsx
import { Plausible } from '@/components/analytics/Plausible'

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <Plausible />
      </body>
    </html>
  )
}

Verify Integration

  1. Visit your website
  2. Log into Plausible dashboard to check if data is being collected properly

Troubleshooting Common Issues

During deployment, you might encounter some problems:

HTTPS Certificate Issues

  • Ensure Cloudflare SSL/TLS settings are correct
  • Or check if server certificate is properly installed

WebSocket Connection Errors

  • Check if Nginx configuration includes WebSocket support code
  • Ensure Cloudflare settings allow WebSocket connections

DNS Resolution Issues

  • Use nslookup command to verify domain resolves to server IP correctly
  • Be patient and wait for DNS propagation (up to 24 hours)

Final Result

Plausible Final Result

Following these steps, you can successfully set up your own Plausible Analytics service and enjoy privacy-friendly website analytics!