tl;dr
This blog now uses GoatCounter instead of Google Analytics. GoatCounter is a lightweight and unobtrusive site-visit counter made by developer Martin Tournoij.
Do blogposts dream of electric goats?
I write posts on this blog for me and for other learners. It’s great if people find the content useful or interesting.
But I don’t and never will make money from this site, so why would I care how many visits it gets?
A highly-viewed post indicates to me that the topic is worth talking about. It’s a signal that it might be worth writing more about that thing in future. Popular posts might also need updating over time to keep the information up to date.
So I think I have a use case. Except I don’t want to ‘track’ people; I just want to count visits and views.
Friendship ended
I’ve been using Google Analytics for this blog since it began in April 2018. Why? My naïve reasons were that it’s free, it’s ubiquitous and it’s easily implemented in {blogdown}.
It’s massively bloated for my use case though. Acquisition reports, revenue per user and cohort analysis are not relevant to me. And I don’t even know what they mean.
More importantly, I’m uncomfortable with various privacy concerns around the company and platform. I don’t need or want you to be the product.
This change has been a long time coming and follows my earlier removal of the Disqus comment platform, thanks to a Maëlle Salmon post.
New best friend
A number of alternatives are available,1 but I chose GoatCounter by independent developer Martin Tournoij. Why?
To summarise, the large type at the top of the GoatCounter home page says:
Easy web analytics. No tracking of personal data.
What does that encompass?
What | Explain |
---|---|
Privacy | GoatCounter doesn’t collect personally-identifiable data and as such it ‘probably doesn’t require a GDPR consent notice’. |
Simple web interface | A clean interface with focus on visits and viewers over time (see a live demo). |
Transparent | GoatCounter is open source and the creator is open about comparisons to other products. |
Thoughtful | The creator has written openly about the rationale and has considered users of assistive tech. |
Free | With paid plans or donations available (Patreon, GitHub Sponsors). |
Lightweight | It’s less than 3 kb. |
Herding GoatCounter
Switching to GoatCounter was straightforward.
This blog was created with the R package {blogdown}, which is built on the Hugo static site generator, and it’s deployed via Netlify. Your mileage may vary, but there were basically three steps:
- Remove the Google Analytics token from the site’s
config.toml
file. - Create a GoatCounter account.
- Add a single script tag to the
<body>
of your site2.
For that last step I used a special Netlify feature that inserts code snippets into the HTML of your site on deployment.3 I didn’t have to worry about where to put it in the code of the site.
![Netlify's HTML injection option confirming the GoatCounter code snippet used to count page visits.](/post/2020-09-15-goatcounter-blogdown_files/inject.png)
Analytics straight into the vein.
Your stats will then be available from a URL in the form https://yoursite.goatcounter.com
, which you set during the sign-up process.
Now you can start counting sheep. Er… goats.
Greatest Of All Time (GOAT)
The switch does mean I’ll lose cumulative view counts for posts that already exist, but I’m not bothered about that. I can always export the Google Analytics data and manually add it to GoatCounter’s counts.
For interest, here’s the most viewed posts as counted by Google Analytics:
- Repaying Tom Nook with {R6} (Apr 2020)
- Packages that Sparked Joy in 2019 (Dec 2019)
- Package a {xaringan} template (May 2019)
- Mail merge with R and Dawson’s Creek (Jun 2018)
- How do you pronounce {dplyr}? (Sep 2019)
In particular, the post about {R6} is a good example of something I wanted to learn and then blog about for posterity. I think the timing helped in people viewing it, since Animal Crossing: New Horizons had just been released to great fanfare. To illustrate the ‘zeitgeistiness’, this post had the highest view spike of any post and has settled down a great deal since then.
The ‘mail merge’ post is a good example of that classic David Robinson tweet:
When you’ve written the same code 3 times, write a function. When you’ve given the same in-person advice 3 times, write a blog post
Given its popularity, I also decided to overhaul it to make it more simple and accessible. It also led to a later post on parameterised R Markdown reports, which I think is actually the better solution in most cases.
I wouldn’t have known any of this without having a record of page views, but the method for collecting that data no longer grinds my goat.
Bonus goat
![A kid goat being cute, jumping and falling over.](https://media.giphy.com/media/U1MNceJIcNEPe/giphy.gif)
I kid you not (Cheezburger via Giphy).
You can read about some further considerations in a blog by David Papandrew.↩︎
This is provided to you by GoatCounter when you set up an account, but it’s just in the form
<script data-goatcounter="https://yoursite.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script>
.↩︎Thanks to a post by Max.↩︎