I started blogging in December 2020. I wanted to collect my old stories, software and notes all in one place. I thought others may like the content and I was curious how popular it may be, so I setup Google Analytics to keep track of things.
After a few months, I decided I did not need Google Analytics. It was really over-kill and had privacy implications for people who visit my blog. It also impacted the blog’s performance a bit.
Alternatives
I looked at a few alternatives that promised better privacy, but they too were over-kill for my needs and required either infrastructure to setup (which I do not want to maintain) or monthly fees. And JavaScript. Lots and lots of JavaScript.
They all seemed so unpleasant.
What metrics do I want?
I started by thinking about what metrics I want. It’s pretty simple really.
- The number of log entries.
- The list of most popular URLs.
- The list of HTTP status codes.
- The list of referring websites.
I wanted the lists to be ordered by descending count. Like so:
# Count HTTP-Status-Code
558 200
60 304
35 404
15 301
What granularity do I want?
Daily. I don’t really care about weekly, monthly or trends over time. I just want to check my email each day, read my metric reports and compare them to the last few days.
This way, I’ll know when a blog post has made it to the front page of Hacker News or when too many visitors are getting 404s due to some mistake I made.
The shell scripts
I host the blog on Nearly Free Speech. They run FreeBSD with Apache and have a nice web interface that allows customers to edit ‘Scheduled Tasks’. So, once I had the scripts working, as I wanted, from the command line (via SSH), I just copied and pasted them into the web interface.
Here they are in order as listed above:
$ /usr/bin/wc -l /home/logs/access_log.old
$ /usr/bin/awk '{print $7}' /home/logs/access_log.old | /usr/bin/sort | /usr/bin/uniq -c | /usr/bin/sort -r
$ /usr/bin/awk '{print $9}' /home/logs/access_log.old | /usr/bin/sort | /usr/bin/uniq -c | /usr/bin/sort -r
$ /usr/bin/awk '{print $11}' /home/logs/access_log.old | /usr/bin/sort | /usr/bin/uniq -c | /usr/bin/sort -r
The daily emails
To get the metrics into my inbox, I added one final pipe to the end of each shell script to send an email:
$ /usr/bin/wc -l /home/logs/access_log.old | /usr/bin/mail -s "Total Visitors" me@example.com
Here’s what a report looks like:

Conclusion
I know this approach isn’t for everyone. Many people actually need all the features offered by tools such as Google Analytics, but if you are concerned about privacy and just want basic daily metrics, you may give it a try.
Now, my blog is simpler than it was before, performs better and is more private too.
WRT increased privacy, please stayed tuned. I plan to run the blog as a tor hidden service and write some about how I set that up and why I decided to do some things the way I did. It’s easy to make mistakes and disclose your server’s location.
With security and privacy… the devil, as always, is in the detail.
Until next time.
from Hacker News https://ift.tt/3drVx62
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.