3.0 KiB
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
-
Turn the Hugo site into a Hugo module:
hugo mod init <identifier>Where
<identifier>may be the path to the site's Git repository or anything else; see Hugo's docs. -
Add the hugo-cookie-consent module by adding this
module.imports.pathto your site configuration file:# config/_default/hugo.yaml module: imports: - path: git.bovender.de/daniel/hugo_cookie_consent -
Add configuration keys (see below).
-
If your site's language is neither English nor German, add a few terms in the desired language to the language tables.
-
Make your pages load the JavaScript code, e. g. by adding this partial to your
baseof.htmltemplate:{{ partial "hugo_cookie_consent/scripts.html" }} -
Ensure that the SCSS style sheet is being loaded, e.g. by adding this line to your main *.css file:
@import "hugo_cookie_consent/style"; -
Optionally, insert a
hugo_cookie_consent/settingspartial somewhere on your site to enable visitors to review and revise their choice. The privacy statement page might be a good place for this.{{< hugo_cookie_consent/settings >}}
Configuration
You can configure the module by defining site parameters in your site
configuration. The following snippet shows the content of the default
params.yaml which you may override as needed.
# config/_default/params.yaml
hugo_cookie_consent:
privacy_policy_url:
enable_tracking: false
matomo_host:
matomo_site_id:
| Parameter | Description |
|---|---|
privacy_policy_url |
URL of the privacy policy page |
enable_tracking |
Whether to include the tracking script |
matomo_host |
URL of the Matomo host. |
matomo_site_id |
Matomo site ID to use for tracking. |