Files
hugo_cookie_consent/README.md
T
2026-06-14 11:14:34 +02:00

85 lines
2.7 KiB
Markdown

# hugo-cookie-consent
**Hugo module that implements a cookie-consent message and functionality to change
the cookie-consent decision.**
The purpose of this module is to help make a site [GDPR][] compliant. It can
optionally insert tracking code that calls a [Matomo][] instance. This will only
happen after visitors have accepted the use of a cookie -- no logging will take
place before visitors have interacted with the cookie information message. Their
decision is stored in the browser's Local Storage, and it is _not_ personal data
as defined by the GDPR.
This Hugo Module requires Hugo [v0.146.0][]+ which uses the new layout directory
structure with `_partials` and `_shortcode` directories with leading underscores.
[Anthropic Claude][] helped in creating this module (paid subscription).
## Installation in your Hugo site
1. Turn the Hugo site into a Hugo module:
```bash
hugo mod init <identifier>
```
Where `<identifier>` may be the path to the site's Git repository or anything
else; see [Hugo's docs][mod-doc].
2. Add the hugo-cookie-consent module by adding this `module.imports.path` to your
site configuration file:
```yaml
# config/_default/hugo.yaml
module:
imports:
- path: git.bovender.de/daniel/hugo-cookie-consent
```
3. Add configuration keys (see [below](#configuration)).
4. If your site's language is neither English nor German, add a few terms in the
desired language to the language tables.
5. Make your pages load the JavaScript code, e. g. by adding this to a `script.html`
partial:
```html
{{- $js := resources.Get "js/cookie-consent.js" | minify -}}
<script src="{{ $js.RelPermalink }}" defer></script>
{{- $js := resources.Get "js/tracker-code.js" | minify -}}
<script src="{{ $js.RelPermalink }}" defer></script>
```
6. Optionally, insert a `cookie-settings` partial somewhere on your site to enable
visitors to review and revise their choice. The privacy statement page might
be a good place for this.
```md
{{< cookie-settings >}}
```
## Configuration
You can configure the module by defining site parameters in your
`hugo.yaml` or `hugo.toml` configuration file. The following
snippet shows the default values.
```yaml
# config/_default/params.yaml
hugo_cookie_consent:
privacy_policy_url:
enable_matomo: false
matomo_host:
matomo_site_id:
```
| Parameter | Description |
|-----------|-------------|
| `privacy_policy_url` | URL of the privacy policy page
[anthropic claude]: https://claude.ai
[gdpr]: https://en.wikipedia.org/wiki/GDPR
[matomo]: https://matomo.org
[mod-doc]: https://gohugo.io/hugo-modules/use-modules/#import
[v0.146.0]: https://github.com/gohugoio/hugo/releases/tag/v0.146.0