Skip to content
New: Customize your theme with an AI assistant. Read the guide

Cookies, Analytics & Custom Scripts

Files: src/config/config.toml, src/content/sections/<language>/cookie-consent.md · Skill level: Beginner (you paste your analytics snippet)

Covena itself adds no analytics or tracking. The only thing it keeps in the visitor’s browser is their cookie choice, under cookie-consent in local storage. The banner matters once you add analytics or ad tags, and it holds those tags back until the visitor agrees.

The banner is a card at the bottom of the page with Accept all, Reject all, and Customise. Customise opens a list of categories with a Save choices button.

src/config/config.toml
[settings.cookieConsent]
enable = true # false turns the banner off
revision = 1 # raise it when your cookie use changes, to ask every visitor again

The text and categories are in src/content/sections/<language>/cookie-consent.md, one file per language:

title: "We use cookies"
description: "Necessary cookies keep this site working. If you agree, we also use analytics cookies ..."
link:
enable: true
label: "Privacy policy"
url: "/privacy-policy/"
acceptLabel: "Accept all"
rejectLabel: "Reject all"
customizeLabel: "Customise"
saveLabel: "Save choices"
categories:
- id: "necessary"
title: "Necessary"
description: "Security, form protection, and your language choice."
- id: "analytics"
title: "Analytics"
description: "Aggregated visit counts and page performance, used to improve the site."
- id: "marketing"
title: "Marketing"
description: "Measure enquiries that come from ads and campaigns."

A category id is one of necessary, analytics, or marketing. The necessary category is always on and shows requiredLabel (“Always on”). Rewrite the description so it names the tools you really use.

Add Analytics Or Any Script

Paste tags into [head] in config.toml. They go into the <head> of every page:

[head]
content = """
<script defer src="https://analytics.example.com/script.js" data-site="yourfirm.com"></script>
"""

Use this for analytics, a verification meta tag, or a chat widget.

With the banner on, mark each tracking tag with the category it belongs to:

  1. Change <script> to <script type="text/plain" data-consent="analytics"> (or "marketing").
  2. Keep src, async, defer, and the other attributes as they are. Inline code works the same way.
  3. To need two categories, list both: data-consent="analytics marketing".
  4. For a module script, add data-type="module".
[head]
content = """
<script type="text/plain" data-consent="analytics" defer src="https://analytics.example.com/script.js" data-site="yourfirm.com"></script>
"""

The browser ignores a text/plain script, so it doesn’t run until the visitor accepts its category. Then the banner turns it into a real script.

Reopen The Preferences

Any link with data-cookie-settings or href="#cookie-settings" reopens the preferences. The footer’s “Cookie settings” link (in footerLegal) does this already. Mention it in your privacy policy so visitors know how to change their mind.

For Developers

  • A consentchange event fires on document on every page load and after each choice. event.detail has necessary, analytics, and marketing:

    document.addEventListener("consentchange", (e) => {
    if (e.detail.analytics) {
    // load analytics
    }
    });
  • window.cookieConsent.get() returns the saved choice, or null before the visitor chooses.

  • window.cookieConsent.open() opens the preferences.

  • The banner is src/layouts/components/widgets/CookieConsent.astro.

Do It With AI

Add Google Analytics 4 to this Covena site with the ID [G-XXXXXXX]. Put the tags in
[head] content in src/config/config.toml, and gate both script tags on the analytics
category: type="text/plain" data-consent="analytics". Then update the analytics
description in every src/content/sections/<language>/cookie-consent.md to say we use
Google Analytics. Don't change anything else.
Type something to search...