GoatCounter is used for simple site analytics.

To avoid issues with some adblockers, the count.js script is self-hosted

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

Note that with this setup uBlockOrigin will still block the event calls to sagar.goatcounter.com which means that browsers with uBlockOrigin installed will not be visible in GoatCounter. Also, for some reason, the site visits I make with my Apple mobile devices do not show up in GoatCounter?!


This uses the self-hosted version of Plausible . The documentation notes I made while self-hosting Plausible are Plausible

The tracking script needs to be added to layouts/partials/hooks/head-end.html. However, adding the default script recommended by the self-hosted Plausible install (after adding site: sagar.se to it) still results in issues with uBlockOrigin. It seems that the loading of plausible.js is blocked from any domain. Similarly, any ’event’ sent to a domain that contains analytics in its name appear to be blocked by the EasyPrivacy list. There are two ways to counter this

  • Change the subdomain where Plausible is self-hosted to not have the word analytics and use Nginx to reverse proxy /js/script.js to /js/plausible.js OR
  • Use Netlify redirect rules to redirect /js/script.js and /api/event as described on Plausible’s site

We follow the second way of using Netlify redirects . To do that add the following to the netlify.toml file (that should exist in the Hugo site’s root directory. See Netlify hosting )

 2  from = "/js/script.js"
 3  to = "https://analytics.sagar.se/js/plausible.js"
 4  status = 200
 5  force = true
 7  from = "/api/event"
 8  to = "https://analytics.sagar.se/api/event"
 9  status = 200
10  force = true

And then the script to be added to layouts/partials/hooks/head-end.html is

1<script defer data-domain="sagar.se" src="/js/script.js"></script>

NOTE: Doing such redirects with Plausible seems to mess up the Geo-location . It seems that the visitor’s geo-location is restricted to the countries in which the Netlify CDN servers are located, possibly implying that when Netlify does a redirect, it sends the CDN’s IP instead of the visitor’s IP. My ultimate workaround was to actually use the following in layouts/partials/hooks/head-end.html

1<script defer data-domain="sagar.se" src="https://visits.sagar.se/js/script.js"></script>

Where visits.sagar.se is the subdomain hosting Plausible (changed from analytics.sagar.se). Ideally, I’d need to use a reverse proxy rule to redirect /js/script.js to /js/plausible.js but it looks like /js/script.js is already an alias for /js/plausible.js (both locations return the same content). So no special proxy rules are needed.