With Universal Google Analytics being shut down” on the 1st of July, 2023, I decided to bypass a GA4 migration and explore moving to a self-hosted analytics solution instead. Within a few hours I had my own low-cost VPS running open-source, privacy-focused, cookie-less web analytics handling multiple sites. 

Self hosting

Motivation #

I’ve been weaning myself off Google products for some years now, and the upcoming forced (whether you like it or not) switch to GA4 seemed like a good opportunity to explore more privacy-focused web analytics. 

Google analytics countdown

I’d heard a lot of good things about Fathom Analytics and Plausible Analytics and would have been prepared to migrate to them – except for the fact that they both have variable pricing.

Both of these services are very reasonably priced for what they offer, but I tend to be averse to variable costs. Budgeting $14/​month for Fathom, which allows up to 100k monthly page views for up to 50 sites, might be fine on launch day. But in a year or two from now, your organisation may find itself having to upgrade and paying upwards of $500 per year, as the site grows in popularity. That’s fine if it there’s the budget for it, but SaaS products (and their unpredictable costs) have a habit of sneaking up on you if left unchecked.

Fathom analytics plans

The other thing I realised was that I rarely actually look at my Google Analytics dashboard, let alone drill into the details – I wanted simple analytics with fixed pricing.

I decided to self-host Plausible Analytics on a fixed-cost virtual private server (VPS). Plausible is open source, privacy focused (requiring no cookie consent for GDPR) and provides simple web analytics, so it fit the bill perfectly (although there are other worthy contenders).

Plausible dashboard

After a few hours I had it all set up with multiple sites and my Google Analytics data imported, and it’s been working flawlessly ever since. There were a few gotchas along the way, which I’ve noted below, in case you choose to go down the same path.

The Setup #

I used a low-spec CX11 server on Hetzner Cloud – a 2GB Intel-based VPS – costing under €5 per month (fixed pricing). Hetzner has data centres in Germany, Finland and the U.S. Since my business is based in Europe, keeping my data there makes it easier to comply with GDPR.

Note that self-hosted Plausible requires Docker and a server with an x86-based CPU, which is why I opted for CX11” over the Arm64-based CAX11”.

Web Server #

I used Ploi to provision a web server and generally make the setup process and maintenance easier. Rather than create a new server and then install Docker on it, I selected the convenient Docker Server” option that Ploi offers.

Creating a Docker Server

Installation #

The self-hosting Plausible docs are good, however, since I already had a Docker server, I found this installation guide easier to follow. 

Below are some important steps that are easy to miss during the setup process.

Disable Public Registration #

By default, Plausible allows public registration of user accounts, which should absolutely be disabled unless you are password-protecting site access. After I created my first account, I set DISABLE_REGISTRATION=true in the plausible-conf.env configuration file to disable public registration.

Enable CORS #

For security reasons, browsers enforce a same-origin policy. Since I wanted the tracking script to be available from multiple origins, and not have to manually allow another each time a new site was added, I ensured that the Access-Control-Allow-Origin response header was set to a wildcard (*).

add_header Access-Control-Allow-Origin *;

The alternative would be to set it to a single origin or to vary the origin based on the source of the request.

Adding a CDN #

Fronting the tracking script with a CDN is a no-brainer. It reduces load on the origin server and ensures that the script is delivered to users as quickly as possible by serving from (and caching on) edge nodes. It can also help improve security by mitigating DDoS attcaks. Enabling Cloudflare for the analytics domain gives it a near-instant boost.

Google Analytics Data Import #

I was impressed how easy Plausible makes it to import Google Analytics data. Within a few minutes I was able to import 15 years’ worth of data!

Google Analytics import success

Google Analytics data suffers from a lag of a day or two, meaning that importing it into Plausible too soon can result in some data loss. I found that the best strategy was to switch the Google Analytics tracking script with the Plausible one and then wait a few days before importing the Google Analytics data.

Craft CMS Dashboard Widgets #

Since I use Craft CMS exclusively, and have a habit of forgetting to look at my site’s analytics regularly, I installed the Plausible plugin and set up the dashboard widgets so they’re front-and-centre each time I log in.

Craft CMS Plausible dashboard widgets

Note that data imported from Google Analytics does not appear in the dashboard widgets, as Plausible’s API is unable to export it (for some strange reason).

Final Thoughts #

The entire setup process took 2 – 3 hours, but much of that was figuring out how I wanted to go about setting things up. I plan on using this one Plausible instance for approximately 10 sites, so the question of disk space naturally crossed my mind. 

Disk Space #

Plausible uses PostgreSQL for storing user data and ClickHouse for storing analytics data. ClickHouse is a column-oriented database that is well-suited for real-time analytics. I was expecting the ClickHouse database storage to be efficient, but I wasn’t expecting it to be as low as 2MB!

ClickHouse database disk usage

This is tiny in comparison to the Docker images required just to run everything, so I don’t see myself having to upgrade the 20GB disk space for a very long time (and it’s easy to scale up if it ever becomes necessary).

Docker image sizes

Updating Plausible #

The self-hosted version of Plausible is considered LTS (long-term support), which should mean that updates are battle tested and released infrequently. Still though, it’s important to keep software updated, so it’s reassuring to see that this can be done, thanks to Docker, with just a single command.

docker-compose pull plausible

Longevity #

And that brings me to my closing thought. Plausible is an open-source project backed by an independent, self-funded company that publishes good quality content. This is a great way to develop and nurture open-source software and I hope to see it have a bright and long future.