GoatCounter with Hugo with Ananke
- One minute read - 175 wordsThanks to Joe Mooring for his solution to my question as to how to do this.
I’ve decided to ditch Google Analytics and am evaluating using GoatCounter with Hugo with Ananke theme.
This was the layout of the site:
.
├── archetypes
├── content
│ └── posts
├── go.mod
├── go.sum
├── hugo.toml
├── layouts
├── public
└── static
This is the structure (of layouts
) with the necessary changes:
.
├── archetypes
├── content
│ └── posts
├── go.mod
├── go.sum
├── hugo.toml
├── layouts
│ ├── _default
│ │ └── baseof.html
│ └── partials
│ └── analytics.html
├── public
└── static
I copied /layouts/_default/baseof.html
from the gohugo-ananke-theme
repo into my site’s|repo’s /layouts/_default/baseof.html
.
I created /partials/analytics.html
with the content replacing {site}
with the value from the GoatCounter dashboard:
<script
data-goatcounter="https://{site}.goatcounter.com/count"
async src="//gc.zgo.at/count.js"
></script>
To Joe’s solution, I added the following line to the local (!) copy of baseof.html
:
{{ partialCached "analytics.html" . }}
Rebuilding the site, arbitrary pages now include the GoatCounter script reference.
And, importantly, metrics are being reported in the site’s GoatCounter dashboard.