diff --git a/README.md b/README.md
index 10bdba6..dbcbca1 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# hugo-cookie-consent
+# hugo_cookie_consent
**Hugo module that implements a cookie-consent message and functionality to change
the cookie-consent decision.**
@@ -33,7 +33,7 @@ structure with `_partials` and `_shortcode` directories with leading underscores
# config/_default/hugo.yaml
module:
imports:
- - path: git.bovender.de/daniel/hugo-cookie-consent
+ - path: git.bovender.de/daniel/hugo_cookie_consent
```
3. Add configuration keys (see [below](#configuration)).
@@ -41,42 +41,49 @@ structure with `_partials` and `_shortcode` directories with leading underscores
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:
+5. Make your pages load the JavaScript code, e. g. by adding this partial to your
+ `baseof.html` template:
```html
- {{- $js := resources.Get "js/cookie-consent.js" | minify -}}
-
- {{- $js := resources.Get "js/tracker-code.js" | minify -}}
-
+ {{ partial "hugo_cookie_consent/scripts.html" }}
```
-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.
+6. Ensure that the SCSS style sheet is being loaded, e.g. by adding this line to
+ your main *.css file:
+
+ ```scss
+ @import "hugo_cookie_consent/style";
+ ```
+
+7. Optionally, insert a `hugo_cookie_consent/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 >}}
+ {{< hugo_cookie_consent/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.
+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.
```yaml
# config/_default/params.yaml
hugo_cookie_consent:
privacy_policy_url:
- enable_matomo: false
+ enable_tracking: false
matomo_host:
matomo_site_id:
```
-| Parameter | Description |
-|-----------|-------------|
-| `privacy_policy_url` | URL of the privacy policy page
+| 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. |
[anthropic claude]: https://claude.ai
[gdpr]: https://en.wikipedia.org/wiki/GDPR
diff --git a/assets/js/cookie-consent.js b/assets/js/hugo_cookie_consent/cookie_consent.js
similarity index 100%
rename from assets/js/cookie-consent.js
rename to assets/js/hugo_cookie_consent/cookie_consent.js
diff --git a/assets/js/tracker-code.js b/assets/js/hugo_cookie_consent/tracker_code.js
similarity index 93%
rename from assets/js/tracker-code.js
rename to assets/js/hugo_cookie_consent/tracker_code.js
index a9086c8..d6c5158 100644
--- a/assets/js/tracker-code.js
+++ b/assets/js/hugo_cookie_consent/tracker_code.js
@@ -6,6 +6,8 @@
var siteId = banner.dataset.matomoSiteId;
if (!matomoUrl || !siteId) return;
+ if (matomoUrl.slice(-1) !== '/') matomoUrl += '/';
+
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
diff --git a/assets/scss/cookie-consent.scss b/assets/scss/hugo_cookie_consent/style.scss
similarity index 100%
rename from assets/scss/cookie-consent.scss
rename to assets/scss/hugo_cookie_consent/style.scss
diff --git a/config/_default/params.yaml b/config/_default/params.yaml
index 5977a03..9a562dd 100644
--- a/config/_default/params.yaml
+++ b/config/_default/params.yaml
@@ -1,5 +1,5 @@
hugo_cookie_consent:
privacy_policy_url:
- enable_matomo: false
+ enable_tracking: false
matomo_host:
matomo_site_id:
diff --git a/layouts/_partials/cookie-consent.html b/layouts/_partials/hugo_cookie_consent/banner.html
similarity index 100%
rename from layouts/_partials/cookie-consent.html
rename to layouts/_partials/hugo_cookie_consent/banner.html
diff --git a/layouts/_partials/hugo_cookie_consent/scripts.html b/layouts/_partials/hugo_cookie_consent/scripts.html
new file mode 100644
index 0000000..de0162b
--- /dev/null
+++ b/layouts/_partials/hugo_cookie_consent/scripts.html
@@ -0,0 +1,6 @@
+{{- $js := resources.Get "js/hugo_cookie_consent/cookie_consent.js" | minify -}}
+
+{{- if eq .Site.Params.hugo_cookie_consent.enable_tracking true -}}
+ {{- $js := resources.Get "js/hugo_cookie_consent/tracker_code.js" | minify -}}
+
+{{- end -}}
\ No newline at end of file
diff --git a/layouts/_shortcodes/cookie-settings.html b/layouts/_shortcodes/hugo_cookie_consent/settings.html
similarity index 100%
rename from layouts/_shortcodes/cookie-settings.html
rename to layouts/_shortcodes/hugo_cookie_consent/settings.html