A Plausible alternative to Google Analytics
Tagged as plausible, analytics, fly.io
This website is a Phoenix app utilizing nimble_publisher to manage blog posts. I’ve been building Elixir applications professionally since 2015, so it was a fairly safe decision. However, my expertise is in building (mostly) internal tools in the healthcare space. That means for certain domains, like SEO and Analytics, I have a learning curve to climb.
I’m using AppSignal to monitor performance and errors, so I can see that my posts are being visited, but that’s about it. I need Web Analytics. The safe bet would have been Google Analytics, with it’s ~55% market share, but the primary mission of Intever Co. is to improve privacy, so I needed an alternative. I found Plausible, and I like their cookie-less approach, so today I deployed it on Fly.io.
First off though, I’m not sure self-hosting it the best approach. Their pricing is reasonable, and it did take some time to set up. I think the cost to self-host the service will actually be more expensive, but I’m trying to use as few cloud services as possible to reduce privacy concerns. In a few months I’ll post a follow up on the long term trade-offs.
Plausible provides helpful docs on self-hosting and a github repo with docker-compose and kubernetes configurations. Unfortunately, fly.io wants a single dockerfile. I created a small repo that documents the 3 apps I used to run it (Postgres, Clickhouse, and Plausible)
I’m running Postgres and Clickhouse on the smallest instances (shared-cpu-1x w/ 256MB ram), but plausible was crashing and required 1GB ram. I think they’re likely under-provisioned, but I have not load tested this setup yet. The other issue I ran into was the DB connection. Fly.io does all internal networking over IPv6, and that required a change to how phoenix apps are built. The phx generators have been updated, but it required a PR for plausible.
I also set a few ENV variables related to the internal dns / IPv6 networking in the fly.toml (
The other issue is that I wanted to
force_ssl, but that’s a compile-time configuration
config :plausible, PlausibleWeb.Endpoint, force_ssl: [rewrite_on: [:x_forwarded_proto]],
As the project is compiled and shipped as a dockerfile, I’m not sure of a solution that wouldn’t effect all users. However, I did come up with a simple enough workaround for now. I moved the fly.toml to my fork of plausible, made the change in the code, and ran
flyctl deploy. It’s not a great long term solution, but it allowed me to ship the app without publishing a new dockerfile or waiting for the PR to be merged.
I also didn’t quite get the
release_command right. I wound up deploying once to create the DB, then again to migrate the DB when the first deploy failed to run.
Feel free to open up a github issue if you have a
force_ssl solution or any suggestions on this setup.