For me, it is important to see analytics about my portfolio website. This way, I can see which posts got the most views, which country my users are from, and which browser & operating system they are using. The simplest solution to add analytics to your site is Google Analytics as it is free and easy to set up. But as we all know, this service is only free as we pay it indirectly by providing data to it. What you need to know about Google Analytics and privacy.
In this blog post, I will show you how I replaced Google Analytics with Umami which is a simple, easy to use, self-hosted web analytics solution.
Umami
I chose Umami because it
- is open-source
- is privacy-focused
- simple
- easy to use
- has a beautiful UI
- has good documentation
Umami does not provide a hosting solution. Therefore, we need to host the service on our own. All you need to get Umami up and running is a database (either MySQL or PostgreSQL) and a server that can run Node.js (10.13 or newer). Check the list of available hosting solutions.
I will show you two different approaches I tried to host Umami.
Running on Heroku
Heroku is a container-based cloud Platform as a Service (PaaS). Developers use Heroku to deploy, manage, and scale modern apps. The platform is elegant, flexible, and easy to use, offering developers the simplest path to getting their apps to market.
You can read more about Heroku on their "What is Heroku?" page.
We can host Umami and a corresponding database for free on Heroku. The setup is well described in the Umami documentation.
To get it running, I just had to modify the npm start
script command to include the Heroku port:
Using Heroku is for sure the easiest & fastest way to set up a running Umami instance but there is one drawback: It is expensive.
I collected analytics data from my website for about 2 days and I quickly realized that the free "Hobby Dev" Heroku Postgres plan will not be enough.
This free plan includes 10,000 database rows and I filled ~1000 per day. So the free plan would be reached in about 10 days. The next "Hobby Basic" plan for 9$/month would include 10,000,000 rows which would last for approximately 27 years (assuming 1000 new rows per day, so no increasing traffic on my website). The "Standard 0" plan for 50$/month provides unlimited rows but this is way too much money I would spend for a self-hosted analytics solution.
Running on DigitalOcean & Vercel
An alternative to Heroku is to host the database on Digital Ocean and Umami on Vercel.
DigitalOcean
Digital Ocean is an affordable cloud hosting provider. Starting with 5$/month you get a cloud server for personal use and can scale it up as needed. Using this link you get a $100 credit for the first 60 days.
I host a MySQL database on DigitalOcean which required these steps to set up:
- Initial setup the server with Ubuntu 18.04
- Install MySQL on Ubuntu
- Setup the MySQL database schema with the Umami MySQL schema
- Allow remote access to the database
DigitalOcean also provides a Node.js droplet template that comes with Node.js, Ubuntu, and Nginx to host the Umami frontend. We will instead use Vercel as it is completely free.
Vercel
Vercel is the company behind the framework Next.js which is used by Umami and they provide a free frontend hosting service. As you can imagine, it is really easy to deploy a Next.js application on Vercel as both applications are developed by the same company.
The setup is described in the official documentation.
If you now open the deployed Vercel app at <app-name>.vercel.app
you need to perform these steps
- Login
- Add your website to Umami
- Add tracking code to your website
- Optional: Umami is also able to track events that occur on your website
This should result in a working private, open-source, self-hosted analytics solution:
Conclusion
I can sleep better as I now know that no more data is sent from my website to Google. I still have the possibility to track my website analytics but in a simpler and privacy-focused way. Setting up Umami is quite easy if you are familiar with software like Ubuntu and MySQL/Postgres.
Of course, I know need to pay some money to store this analytics data on my server but for me, it is worth the money.
Monitoring Spring Boot Application With Micrometer, Prometheus And Grafana Using Custom Metrics
It is important to monitor an application's metrics and health which helps us to improve performance, manage the app in a better way, and notice unoptimized behavior. Monitoring each service is important to be able to maintain a system that consists of many microservices.
My Top Angular Interview Questions
This article summarizes a list of Angular interview questions that I would ask candidates and that I get often asked in interviews.