plausible analytics

How to Self Host Plausible Analytics Community Edition and Ditch Google Analytics

You have a reasonable desire to see your website traffic, we all do. But Google Analytics has become such a mess, with its insane UI, overly complicated user admin, Google Tag Manager, GA5 migration, cookie consent banners, and all the other nonsense that comes with it.

Even if you manage to get it all set up, you now have to worry about Google's data collection policies and privacy concerns. And then to simply see your traffic, you have to wade through a sea of data and settings that are seemingly built for giant organizations.

Google Analytics

Even just trying to get the tracking code - with Google Tag Manager, you have to create an account, a property, a tag, a trigger, and then you go into Google Analytics to the Data Stream section, and you now have to figure out how to reconcile the Tag Manager Tag with the Analytics Tag and how they fit within your Account, Property, View, and Data Stream heirarchy. Fun!

So after using Google Analytics for many years, I was done. Fortunately there are alternatives, and I settled on Plausible Analytics. It's a simple, lightweight, privacy-friendly, and open-source analytics solution that you can self-host. It provides all the essential features you need to track your website traffic without the bloat and complexity of Google Analytics.

Plausible Analytics alternative to Google Analytics

What a breath of fresh air! But of course, simple and easy are often not free. And while you can certainly pay for Plausible's cloud services, they offer a Community Edition that you can self-host for free.

So in this article, I'll show you how to self-host Plausible Analytics Community Edition for free using a home server. Let's get started!

Plausible Analytics vs Umami

Before I dive into the setup, a common question people ask is why choose Plausible over Umami?

If the goal is a super simple web traffic tracker, Umami is awesome. It is very lightweight and open-source as well, and in some ways even more minimal than Plausible. You can self-host it or use their paid cloud service, which is free for up to 3 websites and 100k page views per month, with 6 month data retention.

Umami Analytics Dashboard

To me there is one little difference that made me choose Plausible over Umami - Plausible has the ability to share a site's traffic dashboard with an embed link. Or you can create a public link for anyone to see the traffic stats without needing to log in to Plausible.

With either the private embed link or public link, I think it's a great way to place the traffic stats somewhere within a website's CMS or admin dashboard, or in a team site like SharePoint or Notion. That's way easier than creating a user account for everyone who wants to see a site's traffic stats.

But that's really the one feature that made me choose Plausible - Umami is great too and lighter weight if your home server doesn't have a lot of resources. Both Plausible and Umami are privacy-focused and open source, with very simple and clean UIs, so you can't go wrong with either.

Why Self-Host Plausible Analytics?

To use Plausible's cloud service, it costs $9/month for one site, up to 3 years data retention, and 10k page views per month. You also get some benefits like a Google Analytics import tool, email reports, and custom event tracking.

It goes up to $14/month for 3 sites. And the more page views you have, the more each plan costs. Up to 100k page views per month is $19/month for one site, and $29/month for 3 sites.

Plausible Analytics Pricing

Honestly, to me traffic analytics is not worth paying that much for. I have a few low-traffic sites, with occasional potential for a popular post. I like to experiment with small apps and projects and want to track them even if they don't get a lot of traffic. Google Analytics is a pain, but at least it's free.

As a developer or marketing manager, you might also have a number of different projects, websites, or clients that you want to track, and it's hard to convince people to pay for analytics if Google is free (yet terrible).

Plausable Analytics Self Hosted Dashboard

So self-hosted is the way to go if you have a hodge podge of sites that don't really deserve dedicated paid traffic analytics. And even if you self-host Plausible via a cloud provider like Digital Ocean, it will cost you only a few bucks a month for as many sites as you want, with unlimited page views and data retention. And it will continue to work no matter what happens to Plausible's cloud service or pricing.

Plausible Analytics on Digital Ocean

Probably the easiest way to self-host Plausible is by getting a Digital Ocean droplet and using their one-click marketplace app to install Plausible.

If you want to use another VM, there's a $20 service that will set up Plausible anywhere - check out The Plausible Bootstrapper. I'm all about supporting developers who make your life easier.

Plausible Bootstrapper

This will give you a fully working Plausible 24/7 without much effort, no matter what VM you use. But it does cost a few bucks a month for something like Digital Ocean.

For me personally, I like to self-host things on my own home server, even though I know there's hidden costs like electricity, hardware, and time. But not seeing a monthly bill makes it "feel" free, and I also get to learn something new, as well as have the option to tinker with other self hosted apps.

Self-Hosting Plausible Analytics on a Home Server

To get started with self hosting Plausible, you either need to decide if you're ok with leaving your computer on all the time, and if not then you'll need another computer. Any cheap Mini PC will do, although I personally am a Mac guy so I use an old Mac Mini.

For your website to reach your home served Plausible, you'll need a static URL. Traditionally you would get a static IP address through your ISP, and then you'd open up a port on your router and then learn about security along the way.

Cloudflare Tunnel Plausible Analytics

But now you can get a free Cloudflare Tunnel, which you pair with a domain you already own (or get for this purpose), and then setup a subdomain like plausible.yourdomain.com to point to your Plausible instance.

So now when someone goes to your site, Cloudflare will receive the request, and then forward it to your home server Plausible instance. You can also setup extra security measures such as rate limiting, IP whitelisting, and more, through Cloudflare's dashboard.

It's easy to get overwhelmed at first with home server security, so take it slow rather than trying to learn everything all at once.

Plausible Analytics Docker Setup

Once you have the Cloudflare Tunnel setup on a subdomain, you can install Plausible to your Docker Desktop. You can leave everything in the compose.yml file, but in your .env file, make sure to replace your BASE_URL and your SECRET_KEY_BASE with your own values. You can see how to generate a secret key in the Plausible self hosted configuration document.

Now you need to go into your .cloudflared folder, open the config.yml file, and add your new Plausible subdomain. If you have other subdomains and self-hosted services, here's what your config file might look like:

tunnel: your-tunnel-id
credentials-file: /path/to/your/tunnel.json
ingress:
  - hostname: plausible.yourdomain.com
    service: http://localhost:8000
  - hostname: other-service.yourdomain.com
    service: http://localhost:4567
  - service: http_status:404

Now run docker compose up -d to start Plausible and login with your credentials at https://plausible.yourdomain.com.

Once you're logged in, it's a good idea to prevent others from finding your Plausible instance and creating their own account. You can do this by switching DISABLE_REGISTRATION to true in your compose.yml file.

Adding Your Website to Plausible

Once you're in Plausible, it's fairly easy to add your website. But know that you'll need to add a script tag to your website's HTML head section, and deploy it live, before Plausible can confirm the tracking and add your site to its dashboard.

Plausible Add Website

Public Dashboard Link and Private Embed iFrame

As I mentioned earlier, the main reason I chose Plausible over Umami is the ability to share a site's traffic dashboard with either a public link or a private embed link. You can create a public link for anyone to see the traffic stats without needing to log in to Plausible, or you can create a private embed link that you can use in an iFrame on your website or CMS.

Plausible Public Dashboard and Private Embed Link

To do that, go to Site Settings -> Visibility, and here you can toggle the public dashboard as well as add a private embed link.

The public dashboard will give you a URL that you can share with anyone, while the private embed link will give you an iFrame code that you can use to embed the dashboard on your website.

And there you have it, now you can share the dashboard with your team or clients so they'll see something like this without having to log in to Plausible.

Plausible Analytics Public Dashboard

Hide Your Tracking URL

Finally, here's an extra tip to hide your Plausible tracking URL - your plausible.yourdomain.com URL, or whatever you choose as your subdomain.

If your site is hosted on Netlify, you can create a Netlify function that will proxy the Plausible tracking URL.

For example, in your <head> section, you could add the following script tag:

    <script
      defer
      data-domain="yoursite.com"
      data-api="/.netlify/functions/event"
      src="/.netlify/functions/analytics"
    ></script>

And then in your Netlify functions folder, create a file called analytics.js with the following code:

exports.handler = async function (event) {
  try {
    // Get the actual script from your Plausible instance
    const response = await fetch('https://plausible.yourdomain.com/js/script.js');
    const data = await response.text();

    return {
      statusCode: 200,
      headers: {
        'Content-Type': 'application/javascript',
        'Cache-Control': 'public, max-age=3600',
      },
      body: data,
    };
  } catch (error) {
    return {
      statusCode: 500,
      body: 'Error fetching analytics script',
    };
  }
};

And then create another file in the Netlify functions folder called event.js with the following code:

exports.handler = async function (event) {
  try {
    // Forward the event data to Plausible
    const response = await fetch('https://plausible.yourdomain.com/api/event', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'User-Agent': event.headers['user-agent'],
        'X-Forwarded-For': event.headers['x-forwarded-for'] || event.headers['client-ip'],
      },
      body: event.body,
    });

    const data = await response.text();

    return {
      statusCode: 200,
      headers: {
        'Access-Control-Allow-Origin': '*',
        'Content-Type': 'application/json',
      },
      body: data,
    };
  } catch (error) {
    return {
      statusCode: 500,
      body: 'Error forwarding event',
    };
  }
};

It might seem a little overkill, but if you don't want bots to scrape your Plausible tracking URL or if you want to obfuscate it, this is a good way to do it.

You can also use this method to add additional security measures, such as rate limiting or IP whitelisting, to your Plausible tracking URL.

Conclusion

Self-hosting Plausible Analytics Community Edition is a great way to get simple, privacy-friendly web traffic analytics without the bloat and complexity of Google Analytics. Whether you choose to use a cloud provider like Digital Ocean or self-host it on your own home server, Plausible provides all the essential features you need to track your website traffic.

With the ability to share a site's traffic dashboard via a public link or private embed link, I like Plausible over other options like Umami because it makes it easy to share traffic stats with your team or clients without needing to log in to Plausible.

So if you're looking for a simple, lightweight, and privacy-friendly analytics solution, give Plausible Analytics a try.