GoatCounter

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?!

Plausible

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

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 Hosting on Netlify )

 1# remove this line and the '-' characters from the -[[redirects]]- line below
 2-[[redirects]]-
 3  from = "/js/script.js"
 4  to = "https://analytics.sagar.se/js/plausible.js"
 5  status = 200
 6  force = true
 7# remove this line and the '-' characters from the -[[redirects]]- line below
 8-[[redirects]]-
 9  from = "/api/event"
10  to = "https://analytics.sagar.se/api/event"
11  status = 200
12  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.

References