Introduction
As a website operator, you have a legitimate interest in collecting statistics about your visitors, and even more about recurring ones. When using cookies, a unique identifier is set to track all user actions. This is a really effective method for collecting extensive data, especially combined with solutions like Google Analytics. Google is an expert in tracking down users, their software is so popular that currently more than 27 million websites use and share their data with Google [1].
People deserve privacy, and we have seen many hacks exposing valuable personal data to the world-wide-web [2] [3] [4].
As an administrator, it is my responsibility to keep that data safe. However, the rate of common vulnerabilities and exposures is increasing by such a rate that keeping your software secure and up to date becomes a tedious task. This challenge raises whether it is worth it to even collect any data. Think about it: if you don't have any personal data, there is nothing to protect.
This is where Plausible steps into the game. Plausible is an open-source software for website statistics, but it is so GDPR-compliant that you don’t even need a popup asking your visitors for consent. But how is this possible?
Easy! It just does not collect any personal data to create its statistics [5]. Of course, the tool is not as detailed as Google Analytics and you will still require cookies for other use cases like online shops. But Plausible is perfect for small projects that want usable website analytics while simultaneously not compromising its users’ privacy. I am delighted with the software and if you are interested in installing it yourself, go read ahead.
Installing Plausible
Requirements
To my knowledge, self-hosting Plausible is “only” possible via docker-container. Additionally, if you want to avoid issues, Plausible should only be accessed via HTTPS. Therefore, you will need a working machine with docker-compose and a reverse proxy with SSL/TLS functionality. This tutorial will not cover how to set up docker and neither Traefik, my choice for a docker reverse proxy.
Files
Instructions:
-
Copy the
docker-compose.yml
and theplausible.env
with the above contents in the directory of your choice. -
To avoid many different issues, create as shown a geoip folder, an empty GeoIP.conf and GeoLite.mmdb:
mkdir plausible && mkdir plausible/geoip && touch plausible/GeoIP.conf && touch plausible/geoip/GeoLite2-Country.mmdb
-
Run the following command to create your
SECRET_KEY_BASE
and replace it with the one in the .env file.
openssl rand -base64 64
-
Adjust your
ADMIN_USER_
credentials andBASE_URL
to your liking. -
Change your Postgres database password
POSTGRES_PASSWORD
and replace it with the one already existing in the variableDATABASE_URL
. -
Optional: Insert your own SMTP-server details at the
SMTP_*
variables to enable password-reset emails. -
Optional: In order to get reliant IP-Address to country translation, sign up here. When your account has been successfully created visit page and check "no" to generate a new GeoLite2 license key. Replace the values of the
GEOIPUPDATE_ACCOUNT_ID
andGEOIPUPDATE_ACCOUNT_ID
variables with your own ones. If you do not wish to use this service, remove all the GeoIP variablesTraefik specific settings:
In the
docker-compose.yml
the Traefik labels for the Plausible container need multiple adjustments: -
Replace in the Host rule
data.contoso.com
with the same URL as yoursBASE_URL
. -
Change the certresolver from
contoso
to the one you have set up with your Traefik instance. -
Adjust or remove the middlewares line
secure_headers@file
to the ones you prefer using. -
Don't forget to add the plausible network to the Traefik container (lines 12-13 from the
docker-compose.yml
)
In case you are using a different reverse proxy, remove all labels from the Plausible container, make sure to forward all traffic coming forBASE_URL
(Port 443) toplausible:8000
. For non-docker reverse proxies, you need to add a port mapping to the Plausible containerports: - XXXX:8000
and then point your reverse proxy to the docker-host. -
Finally, create the containers running
docker-compose up -d
. If no errors occur, visit in your browser the value of yourBASE_URL
. You should now be seeing this: -
To validate your account, press "Request activation code" and it will email to
ADMIN_USER_EMAIL
. The verification can, however, be bypassed with this command:
docker exec plausible-db psql -U postgres -d plausible_db -c "UPDATE users SET email_verified = true;"
.
Congratulations, you have now successfully installed Plausible 👏🏼🥳.
Please note that it would be better to create three different .env files (plausible.env
, postgres.env
, geopip.env
), but for readability I passed all containers the same environment file. In case you want to separate them, orientate at the "###" mark. Also, it is recommended to use Docker Secrets, but I have to be honest - as of right now I don't know how to use it.
Bypassing AdBlocks
uBlock Origins EasyPrivacy List will block URL's containing and script files named with the strings “plausible”, “statistics” and “analytics”. This results in users not being tracked if you have chosen a poor name. When following this tutorial, I used “data” as a subdomain and script name, which right now does not trigger any AdBlock. I recommend following my example, or putting some good thought in to the naming scheme.
Adding Plausible to your Website
Add the second or third line into your <header>-section, which for a Ghost-Blog can be found inside the /yourThemeFolder/default.hbs file:
<head>
<script async defer src="{{asset "js/stats.js"}}"></script> <!-- for Ghost -->
<script async defer src="/replacePath/stats.js"}}"></script> <!-- for generic Websites. ADJUST THE PATH! -->
</head>
Next, create the stats.js script in the path you defined above. For Ghost-CMS, that would be /yourThemeFolder/assets/js. Please make sure to adapt in the script the placeholder “YOUR_URL” with the URL of your Website.
Further Resources
I tried my best to make this tutorial helpful, and I certainly had fun writing it! Regardless, if you encounter any issues, make sure to check out the official Plausible documentation.
That is all, see you maybe next time 🥰.