01 Apr 2021  notes

Self-Hosting GoatCounter's JavaScript

GoatCounter is a great choice for simple, privacy respecting analytics. I had GC on my site for quite some time, but I removed it for two reasons, namely:

  1. Their domains were on all of the major adblock lists and therefore origin views didn’t match traffic that was hitting the edge
  2. There was a 6-month time limit for keeping pageviews, which was understandable due to running a service with a high number of users on the Free tier

Recently though, GoatCounter changed their pricing plans and solved the second problem — the Free plan now offers a maximum of 2.4M pageviews and doesn’t restrict the historical viewing of the data. For a personal site, this really adds value to the trends and spikes regardless of the retention period. The service even allows for deleting historical pageviews, effectively pruning the logs to make room for newer entries.

Regarding the first problem, I discovered that they allow me to self-host the analytics script myself, while still being able to register views to my account’s endpoint. The self-hosted markup simply replaces gc.zgo.at with my own origin:

<script async data-goatcounter="https://paramdeo.goatcounter.com/count" src="/count.js">

Alternatively, the entire contents of count.js can be included in the <script> tags as long as the API endpoint is specified:

    window.goatcounter = {endpoint: 'https://paramdeo.goatcounter.com/count'}
    // [.. contents of https://gc.zgo.at/count.js ..]

And of course the old-school tracking pixel for users with JavaScript disabled should be included. It’s fine if the goatcounter.com origin is blocked since contextual views are out the window at this point:

    <img src="https://paramdeo.goatcounter.com/count?p=/test-noscript">

The one caveat of self-hosting GoatCounter’s JS is that I won’t automatically get new feature updates since the script is being served from my domain.

However, their v1 API endpoint will remain active regardless of future updates; and therefore I can’t envision a scenario where I would be missing out on features that I already have. More importantly, this issue can easily be mitigated by including an NPM script that downloads GoatCounter’s count.js file from their server (at build-time) and overwrites the version stored in my site’s repository.

Copyright © Paramdeo Singh · All Rights Reserved · Built with Jekyll

This node last updated November 7, 2023 and is permanently morphing...

Paramdeo Singh Guyana

Generalist. Edgerunner. Riding the wave of consciousness in this treacherous mortal sea.

Technology Design Strategy Literature Personal Blogs
Search Site

Results are from Blog, Link Dumps, and #99Problems