Web analytics system using Nodejs and MySQL
There are many tools on the market that allow you to perform web analytics. I have always used Google Analytics, but there are several points that I don't like:
- Privacy, what am I going to say. If the product is free, you are the product. We often sacrifice this (and it's okay as long as we're aware), but I increasingly like to respect the privacy of users.
- You don't have your data. They are on their servers and although you can export them, it's not ideal for working with them.
- In my case, although I'm familiar with the tool, I think it's too complex for my use cases, and I don't know why, they don't show all the traffic data on my websites. In addition to the limitations of real-time data.
Exploring alternatives to Google Analytics
I have been testing the Cloudflare web analytics system these days, which advertise that it respects privacy, but they have a big problem: the tracking file is loaded from a third-party domain and is blocked by many browsers. Anyway, I have left this one active since it collects information about Web Core Vitals, which never hurts.
My next option on the list is Plausible. I love the idea behind it, but today I'm in the process of wanting to monetize my projects, so I'm interested in optimizing my costs, and as long as it doesn't bring me real value, I don't want to hire a product for everything. Since it's open source, you can build it yourself, but between maintenance costs and server costs, I totally rule out this option.
My own service: “pirobits analytics”
Conclusion, my “stack” today is a VPS where I deploy my side-projects, which together with a MySQL database (although I have always used postgresql, I know much better how MySQL works) and a cache layer to reduce traffic, move all my side-projects.
Since this year I have set out to create 12 projects in 12 months, I'll talk about this in a post soon so subscribe to the newsletter, in some of these side-projects I need and should have certain metrics. But I don't really need much, nowadays only traffic per page and a few click events.
That's why I created a MySQL table, analytics, which contains the minimum necessary information: *host, path, session, date... * and some other data that is not relevant.
With a small script on the front, I can send analytics events to my backend, which is made with NodeJS. So my system complies with:
- Respect the user's privacy, there is no personal data so I don't use a cookie banner.
- It's language-agnostic, I can use it with React, Vue, NextJS, Static HTML... or whatever I decide to use tomorrow.
- It's light and fast, remember that the more traffic you serve at scale, everything costs more.
- I can consult it in real time and make all kinds of aggregations.
Now when I want to collect information, I simply have to run a couple of queries to MySQL or use some visualization system, and if it falls short I'll see if I can use BigQuery, ClickHouse... or if I can use some other system by then. When some time passes, I will tell you about my reflections and learnings on this journey.
Since you've come this far, would you be interested in using my web analytics API, which also has support for forms? Subscribe to the newsletter or send me a message in Twitter.
Did you find this article useful? Subscribe to my newsletter and take the first step to launch IT products faster. You will receive exclusive tips that will bring you closer to your goals.