GoatCounter with gohugo-theme-ananke

I’ve been using Google Analytics but looking to switch some sites to GoatCounter

I’m using gohugo-theme-ananke as a Hugo Module

Cursory searches suggest1 that I could create layouts/partials/analytics.htm containing:

<script
    data-goatcounter="https://{site}.goatcounter.com/count"
    async src="//gc.zgo.at/count.js"
></script>

But this approach appears to not work:

  1. There’s no obvious place to reference analytics.html after creation
  2. The <script> isn’t included in the built site.

Apologies for finding this challenging…

1 How to add GoatCounter to your Hugo website

Override the theme’s baseof.html template, and place this within the <head> element:

{{ partialCached "analytics.html" . }}

Always use .html instead of .htm when naming templates.

1 Like

Thank you for the helpful reply.

How do I override the theme’s baseof.html template? Do I simply create a local copy of baseof.html and add the {{ partialCached ... }}? Will try that.

The htm (sic.) was a typo in my question; it is actually html.

Yes, place it in the layouts directory in the root of your project.

1 Like

I placed it under ./layouts/_default and directly under ./layouts with the same error.

ERROR render of “page” failed: “/path/to/layouts/_default/baseof.html:34:7”: execute of template failed: template: _default/single.html:34:7: executing “_default/single.html” at <partialCached “layouts/partials/analytics.html” .>: error calling partialCached: partial “layouts/partials/analytics.html” not found
Total in 162 ms
Error: error building site: render: failed to render pages: render of “page” failed: “/path/to/layouts/_default/baseof.html:34:7”: execute of template failed: template: _default/single.html:34:7: executing “_default/single.html” at <partialCached “layouts/partials/analytics.html” .>: error calling partialCached: partial “layouts/partials/analytics.html” not found

Line #34: {{ partialCached "layouts/partials/analytics.html" . }}

If I remove line #34, it builds successfully.

Ah… it appears it wants the local reference:

Line #34: {{ partialCached "analytics.html" . }}

Thank you!

Sorry, cut and paste. Glad it’s working for you.

1 Like

Thank you for your help!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.