Skip to content

Commit 3551a56

Browse files
KStockyimfing
andauthored
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 <[email protected]>
1 parent bfeae19 commit 3551a56

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

docs/content/docs/guide/configuration.md

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -383,16 +383,6 @@ excludeSearch: true
383383
---
384384
```
385385

386-
### Google Analytics
387-
388-
To enable [Google Analytics](https://marketingplatform.google.com/about/analytics/), set `services.googleAnalytics.ID` flag in `hugo.yaml`:
389-
390-
```yaml {filename="hugo.yaml"}
391-
services:
392-
googleAnalytics:
393-
ID: G-MEASUREMENT_ID
394-
```
395-
396386
### Google Search Index
397387

398388
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
409399
> To block search crawlers, you can make a [`robots.txt` template](https://gohugo.io/templates/robots/).
410400
> However, `robots.txt` instructions do not necessarily keep a page out of Google search results.
411401

412-
### Umami Analytics
402+
### Analytics
403+
404+
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:
405+
406+
```
407+
hugo server --environment production
408+
```
409+
410+
#### Google Analytics
411+
412+
To enable [Google Analytics](https://marketingplatform.google.com/about/analytics/), set `services.googleAnalytics.ID` flag in `hugo.yaml`:
413+
414+
```yaml {filename="hugo.yaml"}
415+
services:
416+
googleAnalytics:
417+
ID: G-MEASUREMENT_ID
418+
```
419+
420+
#### Umami Analytics
413421

414422
To enable [Umami](https://umami.is/docs/), set `params.analytics.umami.serverURL` and `params.analytics.umami.websiteID` flag in `hugo.yaml`:
415423

@@ -436,7 +444,7 @@ params:
436444
# doNotTrack: "true" # optional
437445
```
438446

439-
### Matomo Analytics
447+
#### Matomo Analytics
440448

441449
To enable [Matomo](https://matomo.org/), set `params.analytics.matomo.URL` and `params.analytics.matomo.ID` flag in `hugo.yaml`:
442450

@@ -448,6 +456,32 @@ params:
448456
websiteID: "94db1cb1-74f4-4a40-ad6c-962362670409"
449457
```
450458

459+
#### GoatCounter Analytics
460+
461+
To enable [GoatCounter](https://www.goatcounter.com/), set `params.analytics.goatCounter.code` in `hugo.yaml`
462+
All settings available here are mirrors of the settings described in GoatCounter [settings](https://www.goatcounter.com/help/js#settings-44186)
463+
464+
```yaml {filename="hugo.yaml"}
465+
params:
466+
analytics:
467+
goatCounter:
468+
code: "ABCDE"
469+
470+
# Optional Settings
471+
#------------------
472+
# disables automatic collection of data
473+
# noOnload: true
474+
475+
# disables event binding. See more here https://www.goatcounter.com/help/events
476+
# noEvents: true
477+
478+
# allows data collection from local addresses. Use this with a production environment to test locally
479+
# allowLocal: true
480+
481+
# Allow data collection when a page is loaded in a frame or iframe
482+
# allowFrame: true
483+
```
484+
451485
### LLMS.txt Support
452486

453487
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`:

layouts/_partials/components/analytics/analytics.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616
{{ partial "components/analytics/matomo.html" . }}
1717
{{- end }}
1818

19+
<!-- GoatCounter -->
20+
{{- if .Site.Params.analytics.goatCounter -}}
21+
{{ partial "components/analytics/goat-counter.html" . }}
22+
{{- end -}}
23+
1924
{{- end }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- with .Site.Params.analytics.goatCounter -}}
2+
{{- if not .code -}}
3+
{{- errorf "Missing GoatCounter 'code' configuration. See https://imfing.github.io/hextra/versions/latest/docs/guide/configuration/#goatcounter-analytics" -}}
4+
{{- end -}}
5+
6+
<script
7+
data-goatcounter="https://{{ .code }}.goatcounter.com/count"
8+
data-goatcounter-settings='
9+
{
10+
"no_onload":{{ .noOnload | default false }},
11+
"no_events":{{ .noEvents | default false }},
12+
"allow_local":{{ .allowLocal | default false }},
13+
"allow_frame":{{ .allowFrame | default false }}
14+
}
15+
'
16+
async src="//gc.zgo.at/count.js"></script>
17+
{{- end -}}

0 commit comments

Comments
 (0)