feat: support GoatCounter analytics (#814)

* feat: support GoatCounter analytics

* docs: add docs for GoatCounter analytics

refactor: move analytics documentation into its own section since there are now 4 supported analytics solutions

* fix: addressing issues raised in PR

* refactor: simplifying goat counter setting logic.
refactor: simplify error handling with goat counter

* fix: fixing goat counter erroring when a code is provided

* fix: Applying suggested fixes

* Update layouts/_partials/components/analytics/goat-counter.html

---------

Co-authored-by: Xin <5097752+imfing@users.noreply.github.com>
This commit is contained in:
Keith Stockdale
2025-10-13 22:50:19 +01:00
committed by GitHub
parent bfeae19076
commit 3551a56b8c
3 changed files with 68 additions and 12 deletions

View File

@@ -383,16 +383,6 @@ excludeSearch: true
---
```
### Google Analytics
To enable [Google Analytics](https://marketingplatform.google.com/about/analytics/), set `services.googleAnalytics.ID` flag in `hugo.yaml`:
```yaml {filename="hugo.yaml"}
services:
googleAnalytics:
ID: G-MEASUREMENT_ID
```
### Google Search Index
To [block Google Search](https://developers.google.com/search/docs/crawling-indexing/block-indexing) from indexing a page, set `noindex` to true in your page frontmatter:
@@ -409,7 +399,25 @@ To exclude an entire directory, use the [`cascade`](https://gohugo.io/configurat
> To block search crawlers, you can make a [`robots.txt` template](https://gohugo.io/templates/robots/).
> However, `robots.txt` instructions do not necessarily keep a page out of Google search results.
### Umami Analytics
### Analytics
Hextra has support for several different analytics solutions. Hextra only supports analytics in production environments. This is to ensure that you do not accidentally send analytic events when working locally. If, however, you do want to test analytics locally, you can run a production server using:
```
hugo server --environment production
```
#### Google Analytics
To enable [Google Analytics](https://marketingplatform.google.com/about/analytics/), set `services.googleAnalytics.ID` flag in `hugo.yaml`:
```yaml {filename="hugo.yaml"}
services:
googleAnalytics:
ID: G-MEASUREMENT_ID
```
#### Umami Analytics
To enable [Umami](https://umami.is/docs/), set `params.analytics.umami.serverURL` and `params.analytics.umami.websiteID` flag in `hugo.yaml`:
@@ -436,7 +444,7 @@ params:
# doNotTrack: "true" # optional
```
### Matomo Analytics
#### Matomo Analytics
To enable [Matomo](https://matomo.org/), set `params.analytics.matomo.URL` and `params.analytics.matomo.ID` flag in `hugo.yaml`:
@@ -448,6 +456,32 @@ params:
websiteID: "94db1cb1-74f4-4a40-ad6c-962362670409"
```
#### GoatCounter Analytics
To enable [GoatCounter](https://www.goatcounter.com/), set `params.analytics.goatCounter.code` in `hugo.yaml`
All settings available here are mirrors of the settings described in GoatCounter [settings](https://www.goatcounter.com/help/js#settings-44186)
```yaml {filename="hugo.yaml"}
params:
analytics:
goatCounter:
code: "ABCDE"
# Optional Settings
#------------------
# disables automatic collection of data
# noOnload: true
# disables event binding. See more here https://www.goatcounter.com/help/events
# noEvents: true
# allows data collection from local addresses. Use this with a production environment to test locally
# allowLocal: true
# Allow data collection when a page is loaded in a frame or iframe
# allowFrame: true
```
### LLMS.txt Support
To enable [llms.txt](https://llmstxt.org/) output format for your site, which provides a structured text outline for [large language models](https://en.wikipedia.org/wiki/Large_language_model) and AI agents, add the `llms` output format to your site's `hugo.yaml`:

View File

@@ -16,4 +16,9 @@
{{ partial "components/analytics/matomo.html" . }}
{{- end }}
<!-- GoatCounter -->
{{- if .Site.Params.analytics.goatCounter -}}
{{ partial "components/analytics/goat-counter.html" . }}
{{- end -}}
{{- end }}

View File

@@ -0,0 +1,17 @@
{{- with .Site.Params.analytics.goatCounter -}}
{{- if not .code -}}
{{- errorf "Missing GoatCounter 'code' configuration. See https://imfing.github.io/hextra/versions/latest/docs/guide/configuration/#goatcounter-analytics" -}}
{{- end -}}
<script
data-goatcounter="https://{{ .code }}.goatcounter.com/count"
data-goatcounter-settings='
{
"no_onload":{{ .noOnload | default false }},
"no_events":{{ .noEvents | default false }},
"allow_local":{{ .allowLocal | default false }},
"allow_frame":{{ .allowFrame | default false }}
}
'
async src="//gc.zgo.at/count.js"></script>
{{- end -}}