2023-06-09 project
Banner

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.

Caddy

So on normal days, I used to get some hits amounting to 30-40MB bandwidth usage. But on the HN day, I got 8k hits and 1.25GB bandwidth usage. The problem with this data was that unique users are calculated using IP addresses. But those addresses are refreshed every 24 hours for normal devices. So I decided to check injecting javascript solutions available in public.

My criteria for selecting a solution were straightforward:-

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.

Caddy

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:-

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.

Caddy

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.

Ciao!!!