There are lies, damned lies and statistics.
So I got a lot of traffic on my site after my previous post
got featured on Hacker news home page for 20mins.The good thing was that I enabled caddy logging. So I had some data to work with.
So on normal days, I used to get some hits amounting to 30-40MB bandwidth usage.
My criteria for selecting a solution were straightforward:-
- Lightweight implementation
- Minimal invasion of privacy
I came across two promising options:-
So I decided to go with GoatCounter. It was simple to setup and had a free tier. I just had to add a script tag to my site and it started collecting data on google chrome.
Then I switched to Brave browser to my surprise,Brave was blocking the script.
That was a bummer. I had to find a solution. And I gave piratepx a try. It was also simple to setup. But the same problem persisted.
Brave was blocking the gif download.
This experience taught me that any analytics service with moderate popularity would likely be blocked by Brave or uBlockOrigin. So I decided to create my analytics service.
After learning that if you generate UUID without any user’s data as input(hashing) and store it in local storage, it is considered anonymous data. And I am also not storing any personal data on my server. So it is privacy friendly.
So I started coding, I had a simple post route that would get UUID from local storage and the current URL after the user has been on any link for 2 secs.
Triggering a POST call after two seconds helps in 2 ways:-
- It checks if the user is spending some time on the page and not just bouncing off.
- It helped reduce the number of calls to the server if a user repeatedly opened and closed the page.
I also added a simple server-rendered HTML which shows analytics of each page for both domains I have registered with it. I am using charts.css for styling the charts.
The first bar of each pair shows unique users and the second bar shows total hits.
So the first bar can be smaller than the second bar if the user has visited the page multiple times.
I named this small project “Lialytics” (Light Analytics), and it utilizes Golang and SQLite. Overall, I am pleased with the results.