13 comments

[ 121 ms ] story [ 976 ms ] thread
I have a Hugo blog running on Netlify. All I need is to know if someone has visited it or not. I'm using Google analytics currently but would gladly use something much simpler. Any alternatives?
Plausible.io, or just write something yourself
Writing it myself is what I did for my blog. The only thing I capture is the page that was visited, when it was visited, and the domain of the referrer (to see what the source is). The tracker is meant to be used for blogs where I don't control the server, such as Github Pages, so there's a single AJAX call to my self-hosted server.

I usually open source my code, I just haven't gotten around to it for this one in particular. Might be worth doing if people are interested.

Yeah sure! Please do open source it if you choose to, I've been thinking about something similar but it's just not pressing vs. all the other stuff I'm working on. I literally haven't given it much thought beyond "ok intercept the request from a visitor, do some analytics on the IP address, and then log visits of logged in users/new visitors"

> The only thing I capture is the page that was visited, when it was visited, and the domain of the referrer (to see what the source is). The tracker is meant to be used for blogs where I don't control the server, such as Github Pages, so there's a single AJAX call to my self-hosted server.

To be honest, I'm not entirely sure how I'd solve this without the 'single AJAX call' but I guess it makes sense to start there!

Curious how you implemented it - again, I'm not a rocket surgeon and this is just like a 3 second analysis of the problem space, but it's always neat to check out other people's implementations for common, shared problems

For sure! Because this was for my own use, I need to put in some documentation for it to be useful for others. That, and pick a name :) It's all on my TODO list.

You're right: if you don't control the server, you basically can't intercept any requests without this extra AJAX call, or some similar mechanism like a tracking image served from your own server. Essentially, you need to make a request to your own server at some point!

The architecture is pretty simple:

1. Insert the AJAX request into each page, sending the page URL and the referrer in the payload. Because I found some weirdness with tools like Pocket serving my pages from some cached location, I use my static site generator (Jekyll) to embed the page URL into each page, instead of pulling it from the client side.

2. I support multi-tenancy on a single tracking server by using multiple domain names. Based on the incoming domain name, I have nginx attach an additional header to the request that says which site is being tracked. This way, I can have my personal blog and my newsletter website both tracked by the same tracking server instance.

3. Then, it's just a matter of storing the data (page URL, time of visit, referrer domain, which site) into a SQLite database.

4. And of course, I have a small web UI to view the data.

Note that I don't do anything with the IP address of the visitor. That's personal data that I don't track.

Having added Plausible to my site recently, one killer feature in my opinion is the ability to rewrite the analytics script to be served from your own domain. What this means in effect is that it won't get picked up in traditional ad blockers so the accuracy is much closer to that of server log parsing. Additionally, you can surface your analytics publically which is cool.
Cool yeah I don't have something with sufficient page visits to merit analytics but if I did I'd probably reactivate plausible from its dormant status

Public analytics seems interesting - have you been able to do anything particularly interesting by leveraging this capability?

I haven't myself but there is an API for running queries so it'd be kinda cool to surface X people are on this site currently or generate a little timeseries graph showing popularity of posts
I use and really like GoatCounter: https://www.goatcounter.com/ -- it's free for non-commercial use, and low-cost for commercial use. It's a little less sleekly designed (and more nerdy-looking) than Plausible Analytics and some others, but for Hacker News users, that's probably a plus. :-)
Maybe something from this:? „Fathom Analytics”, „Matomo”, „Simple Analytics”, „Plausible Analytics” Not used any of them, but they seem interesting.
We now only track sales, stopped Google Analytics or any type of third party analytics. Site analytics can be a waste of energy and time. Also, user privacy is critical for success. With this, we cut our competitors targetting our clients with ads.
Personally I use Google Analytics because it's low effort for visitation and referrer stats but for work, geez the time that gets sunk into making Google Analytics accurate...