Plausible Analytics is a privacy-friendly website analytics tool that provides website owners with insights about their website traffic without collecting any personal data from their visitors. It is an open-source web analytics platform that emphasizes user privacy and simplicity.

Plausible Analytics offers several features and benefits. some of which include:

  • Lightweight: Plausible Analytics works by loading a script on your website, like Google Analytics.
  • Email or Slack reports: Keep an eye on your traffic with weekly and/or monthly email or Slack reports.
  • Clutter Free: Plausible Analytics provides simple web analytics and it cuts through the noise.
  • Open website stats: You have the option to be transparent and open your web analytics to everyone.
  • SPA support: Plausible is built with modern web frameworks in mind and it works automatically with any pushState-based router on the front end.
  • Search keywords: Integrate your dashboard with Google Search Console to get the most accurate reporting on your search keywords.
  • GDPR/CCPA/PECR compliant: Measure traffic, not individuals.

Plausible Analytics can be deployed in two ways:

  • Managed service in the Cloud: This is the easiest method to run Plausible.
  • Self-hosted: With this method, you do it all yourself.

In this guide, we will learn how to install and run Plausible Analytics in a Docker container – An alternative to Google Analytics.

1 – Install Docker Container Engine

To deploy a self-hosted Plausible, you need to have:

  • CPU with x86_64 architecture
  • Minimum of 4GB of RAM but the requirements will depend on your site traffic.
  • Docker Engine installed. This can be achieved using the guide:

Follow our guide below to install Docker Engine.

Verify the installation:

$ docker version
Client: Docker Engine - Community
 Version:           23.0.6
 API version:       1.42
 Go version:        go1.19.9
 Git commit:        ef23cbc
 Built:             Fri May  5 21:19:37 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.6
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.9
  Git commit:       9dbdbd4
  Built:            Fri May  5 21:18:11 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Add your system user to the Docker group:

sudo usermod -aG docker $USER
newgrp docker

You also need to have Docker-compose installed:

Next install git

### Debian / Ubuntu ###
sudo apt update && sudo apt install git vim

### RHEL based systems ###
sudo yum -y install vim git

2 – Configure Plausible Analytics Container

First, we will clone the hosting repo which has everything required to spin the container. To access the repo, click on plausible/hosting. You can also clone into this repo as shown;

cd ~/
git clone https://github.com/plausible/hosting plausible

Navigate into the created directory:

cd plausible

We need to make adjustments to the plausible-conf.env which contains variables for the container. First, generate a random hash string:

openssl rand 64 | base64 -w 0 ; echo

Copy this base64 string and use it in the next step. Open the file for editing:

vim plausible-conf.env 

In the opened file, modify the below values:

BASE_URL=http://your_domain_here
SECRET_KEY_BASE=paste_your_random_characters_here
ADMIN_USER_EMAIL=your_email_here
ADMIN_USER_NAME=admin_username
ADMIN_USER_PWD=admin_password

Once the desired modifications have been made, save and exit. You can also modify the docker-compose file.

vim docker-compose.yml

By default the service will bind to all network interfaces. You can limit to specific IP address or localhost by editing ports section.

    ports:
      - 127.0.0.1:8000:8000

3 – Run Plausible in Docker Containers

Now you can start the containers using the command:

docker compose up -d

Sample Output:

[+] Running 30/7
 ✔ mail 3 layers [⣿⣿⣿]      0B/0B      Pulled                                                                                                                                                     11.1s
 ✔ plausible_db 8 layers [⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                                                                                                        17.3s
 ✔ plausible_events_db 7 layers [⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                                                                                                  32.6s
 ✔ plausible 8 layers [⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                                                                                                                           13.5s



[+] Running 7/7
 ✔ Network plausible_default                  Created                                                                                                                                              0.1s
 ✔ Volume "plausible_db-data"                 Created                                                                                                                                              0.0s
 ✔ Volume "plausible_event-data"              Created                                                                                                                                              0.0s
 ✔ Container plausible-plausible_db-1         Started                                                                                                                                              1.4s
 ✔ Container plausible-plausible_events_db-1  Started                                                                                                                                              1.2s
 ✔ Container plausible-mail-1                 Started                                                                                                                                              1.3s
 ✔ Container plausible-plausible-1            Started                                                                                                                                              1.9s

You can verify if the containers are running:

$ docker ps
CONTAINER ID   IMAGE                                      COMMAND                  CREATED              STATUS              PORTS                          NAMES
6c873bd012a6   plausible/analytics:latest                 "/entrypoint.sh sh -…"   About a minute ago   Up About a minute   127.0.0.1:8000->8000/tcp       hosting-plausible-1
19d50aca783a   postgres:14-alpine                         "docker-entrypoint.s…"   About a minute ago   Up About a minute   5432/tcp                       hosting-plausible_db-1
2cfe699c4559   clickhouse/clickhouse-server:22.6-alpine   "/entrypoint.sh"         About a minute ago   Up About a minute   8123/tcp, 9000/tcp, 9009/tcp   hosting-plausible_events_db-1
7ba33e34f3a4   bytemark/smtp                              "docker-entrypoint.s…"   About a minute ago   Up About a minute   25/tcp                         hosting-mail-1

You can also verify if the homepage is accessible:

$ curl http://localhost:8000
<html><body>You are being <a href="/register">redirected</a>.</body></html>

Or access with system IP address: http://serverip:8000

4 – Configure Nginx Reverse Proxy

Now we will use Nginx as the reverse proxy server to improve performance by offloading caching, compression, and static file serving to a more efficient process.

First, ensure that Nginx is installed on your system

##On Debian/Ubuntu
sudo apt update && sudo apt install nginx -y

##On RHEL/Rocky Linux/Alma Linux
sudo yum install nginx -y

Once installed, allow HTTP and HTTPS through the firewall:

##For UFW
sudo ufw allow "Nginx Full"

##For Firewalld
sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload

Now create the virtual host file:

sudo vim /etc/nginx/conf.d/plausible.conf

In the file, add the below lines:

server {
    listen       80;
    listen       [::]:80;
    server_name  plausible.computingforgeeks.com;

    access_log  /var/log/nginx/plausible.access.log;
    error_log   /var/log/nginx/plausible.error.log;

    location / {
      proxy_pass http://localhost:8000;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

Remember to replace plausible.computingforgeeks.com with your domain name. Save the file and restart the service.

sudo systemctl enable --now nginx

5 – Configure SSL for Plausible Analytics

It is recommended that you access Plausible via HTTPS. For this reason, we can obtain certificates for our domain name. If you have a fully qualified domain name, you can easily obtain certificates using Let’s Encrypt. For this guide, we will use self-signed certs.

Create a config:

$ vim plausible_ssl.conf
[req]
default_bits       = 2048
default_keyfile    = plausible_ssl.key
distinguished_name = req_distinguished_name
req_extensions     = req_ext
x509_extensions    = v3_ca

[req_distinguished_name]
countryName                 = Country Name (2 letter code)
countryName_default         = KE
stateOrProvinceName         = State or Province Name (full name)
stateOrProvinceName_default = Nairobi
localityName                = Locality Name (eg, city)
localityName_default        = Nairobi
organizationName            = Organization Name (eg, company)
organizationName_default    = plausible
organizationalUnitName      = organizationalunit
organizationalUnitName_default = Development
commonName                  = Common Name (e.g. server FQDN or YOUR name)
commonName_default          = Your_IP-Address
commonName_max              = 64

[req_ext]
subjectAltName = @alt_names

[v3_ca]
subjectAltName = @alt_names

[alt_names]
DNS.1   = localhost
DNS.2   = Your_IP-Address

Replace your IP address, Common Name and proceed to generate the certs.

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout plausible_ssl.key -out plausible_ssl.crt -config plausible_ssl.conf

Copy the generated certs to the /etc/ssl/certs:

sudo cp plausible_ssl.crt /etc/ssl/certs/plausible_ssl.crt
sudo mkdir -p /etc/ssl/private/
sudo cp plausible_ssl.key /etc/ssl/private/plausible_ssl.key

Now adjust your config:

sudo vim /etc/nginx/conf.d/plausible.conf

Add the lines below in the server block and modify the HTTPS port:

server {
    listen       443 ssl http2 default_server;
    listen       [::]:443 ssl http2 default_server;
    server_name  plausible.computingforgeeks.com;
    ssl_certificate /etc/ssl/certs/plausible_ssl.crt;
    ssl_certificate_key /etc/ssl/private/plausible_ssl.key;
    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;

    access_log  /var/log/nginx/plausible.access.log;
    error_log   /var/log/nginx/plausible.error.log;

    location / {
      proxy_pass http://localhost:8000/;
           index  index.html index.htm;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

Restart the Nginx service:

sudo systemctl restart nginx

6 – Access Plausible Analytics Web Interface

Now you are set to access the Plausible web interface using the URL https://domain_name

Install Plausible Analytics on

Once authenticated, you will see a prompt to get your first website set up with Plausible.

Install Plausible Analytics on Linux 1

You will be provided with a JavaScript snippet to integrate into your website. Then you can start collecting the data.

Install Plausible Analytics on Linux 2

This script needs to be added to your site’s HTML code before you view the collected metrics. Now Plausible is waiting for any visits to the set website.

Install Plausible Analytics on Linux 3

7 – Test Plausible Analytics on Linux

The Plausible Events API can be used to record page views and custom events. This is useful when tracking Android or iOS mobile apps, or for server-side tracking.

In most scenarios, it is recommended to install Plausible through the provided script or one of the many integration packages listed on the site here. However, if there’s no easy way for you to integrate with Plausible, you can still do so by sending events directly to the API.

It is important to take note of the two key headers which are used for unique visitor counting. Thes are:

  • The User-Agent header
  • The X-Forwarded-For header

So we will send some test traffic to our site using the command:

curl -ivk -X POST https://plausible.computingforgeeks.com/api/event \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 OPR/71.0.3770.284' \
  -H 'X-Forwarded-For: 127.0.0.1' \
  -H 'Content-Type: application/json' \
  --data '{"name":"pageview","url":"https://test.computingforgeeks.com","domain":"test.computingforgeeks.com"}'

Once the traffic has been sent, you will see the Plausible web update as shown:

Install Plausible Analytics on Linux 4

Conclusion

Today, we have learned how to install Plausible Analytics on Linux – An alternative to Google Analytics. You can now track website traffic, and collect only essential data like page views, unique visitors, bounce rates, and referrers using the self-hosted Plausible Analytics.

See more:

LEAVE A REPLY

Please enter your comment!
Please enter your name here