I decided to self-host my website analytics. In this blog, I will walk you through the process of self-hosting Plausible analytics and explain why I made this decision.

Why Self-Host?

The cost and control are the two main factors that motivated me to self-host Plausible analytics. Hosted solutions can be quite expensive when you have a significant number of pageviews. By self-hosting, I am able to save on costs and have full control over my analytics data.

Getting Started

To get started, you will need a DigitalOcean account. If you don’t have one yet, you can use my referral link to get $200 in free credits for the next 60 days. Once you have created an account, you can proceed with the following steps:

  1. Create a new project on DigitalOcean.
  2. Click on “New Project” in the sidebar and give it a name.
  3. Choose a region for your Droplet (VPS) that is closest to your users.
  4. Select an image (I recommend using Docker for easy self-hosting).
  5. Choose a size for your Droplet (I recommend the $4/m plan, if available).
  6. Set up authentication method (password auth is fine for this tutorial).
  7. Create your Droplet.
  8. Set up DNS to point a subdomain of your domain to the Droplet’s IP address.

Configuring Plausible Analytics

Now that your Droplet is up and running, you can proceed with configuring Plausible analytics:

  1. Access the Droplet’s console.
  2. Clone the Plausible Docker Compose setup to the /opt folder.
  3. Update the plausible-conf.env file with your desired configuration (e.g., BASE_URL, SECRET_KEY_BASE).
  4. Update the docker-compose.yml file to specify the localhost port for Plausible (e.g., ports: - 127.0.0.1:8000:8000).
  5. Start the Plausible analytics Docker containers using docker-compose up -d.

Setting Up Nginx

To enable secure connections and set up a reverse proxy for Plausible analytics, follow these steps:

  1. Install and configure Nginx on your Droplet.
  2. Create a plausible.conf file in /etc/nginx/sites-available/ and configure it to proxy requests to Plausible.
  3. Enable the Nginx site by creating a symbolic link in /etc/nginx/sites-enabled/.
  4. Test the Nginx configuration and reload Nginx.
  5. Obtain and configure SSL certificates using Certbot.
  6. Verify that Plausible analytics is working by accessing your Plausible URL.

Disabling Registration

By default, anyone can create an account on your self-hosted Plausible instance. To disable registration, follow these steps:

  1. Open the plausible-conf.env file and add the line DISABLE_REGISTRATION=true.
  2. Reload Plausible using the commands docker-compose down --remove-orphans and docker-compose up -d.

That’s it! You have successfully self-hosted Plausible analytics and disabled registration to maintain control over who can access your analytics data.

I hope this tutorial has been helpful in guiding you through the process of self-hosting Plausible analytics. Plausible is a great tool for website analytics, and by self-hosting, you can enjoy its benefits while saving on costs. Don’t forget to support the Plausible project by becoming a sponsor.

Tags: self-hosting, Plausible analytics, website analytics, Docker, Nginx, SSL certificates