Add the TermsFeed Privacy Consent cookie banner to a static site by pasting its snippet into the <head> of the base layout every page inherits. One edit reaches every generated page on the next build. The code covers Hugo 0.146 or later, Jekyll 4, Eleventy 3, and Astro 5, and setup takes about 15 minutes.

Copy the snippet from the Install page of your consent banner, with its own token in place of YOUR_TOKEN. Create the consent banner first with Create Your First TermsFeed Privacy Consent Banner.

<!-- Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
<script type="text/javascript" src="https://cdn.termsfeedtag.com/plugins/pc/v1/YOUR_TOKEN/plugin.js" async></script>
<!-- End Privacy Consent by TermsFeed (https://www.termsfeed.com) -->

Where the base layout lives in each static site generator

Each generator builds the <head> from one layout file or one head include. A theme installed as a module or gem keeps that file outside your project, so copy it into your own layouts folder under the same path and edit the copy.

Generator Usual file that holds the head How to override a theme file
Hugo layouts/baseof.html, or a head partial Copy the theme file to the same path under layouts/
Jekyll _includes/head.html with the Minima theme, or _layouts/default.html Copy the file to the same path in your site folder
Eleventy The base layout in _includes/, such as _includes/layouts/base.njk Edit the layout in your project
Astro The layout component in src/layouts/, such as Layout.astro Edit the component in your project

Hugo: add the snippet to the base template

Add the snippet at the end of the <head> in baseof.html, or in the head partial your theme uses. A site on Hugo before 0.146 keeps the file at layouts/_default/baseof.html.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>{{ .Title }}</title>
  {{ partial "head.html" . }}
  <!-- Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
  <script type="text/javascript" src="https://cdn.termsfeedtag.com/plugins/pc/v1/YOUR_TOKEN/plugin.js" async></script>
  <!-- End Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
</head>
<body>
  {{ block "main" . }}{{ end }}
</body>
</html>

Hugo themes print Google Analytics from the site configuration. Remove the ID from services.googleAnalytics.id in hugo.toml, so the theme does not print a tag, and add the tool as a vendor.

Jekyll: add the snippet to the head include

Add the snippet before the closing </head> in _includes/head.html, the include the Minima theme loads on every page. The example keeps the tags Minima ships.

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  {%- seo -%}
  <link rel="stylesheet" href="{{ "/assets/main.css" | relative_url }}">
  <!-- Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
  <script type="text/javascript" src="https://cdn.termsfeedtag.com/plugins/pc/v1/YOUR_TOKEN/plugin.js" async></script>
  <!-- End Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
</head>

Minima prints Google Analytics in production builds from the google_analytics key. Remove the key from _config.yml and add the tool as a vendor.

Eleventy: add the snippet to the base layout

Add the snippet to the <head> of the layout every page names in its layout front matter. This example is a Nunjucks layout.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title }}</title>
    <!-- Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
    <script type="text/javascript" src="https://cdn.termsfeedtag.com/plugins/pc/v1/YOUR_TOKEN/plugin.js" async></script>
    <!-- End Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
  </head>
  <body>
    {{ content | safe }}
  </body>
</html>

Astro: add the snippet to the layout component

Add the script to the <head> of the layout component with the is:inline directive, so Astro prints it as written. Astro processes and bundles a script it treats as its own, and the directive opts this one out.

---
// src/layouts/Layout.astro
const { title } = Astro.props;
---
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>{title}</title>
    <!-- Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
    <script is:inline type="text/javascript" src="https://cdn.termsfeedtag.com/plugins/pc/v1/YOUR_TOKEN/plugin.js" async></script>
    <!-- End Privacy Consent by TermsFeed (https://www.termsfeed.com) -->
  </head>
  <body>
    <slot />
  </body>
</html>

Leave Astro view transitions off, which means no <ClientRouter /> in the layout. The client router replaces the page body on each navigation, which removes what Privacy Consent added there, and Privacy Consent does not start again after the swap.

Google tags added from their templates in the TermsFeed app need no Consent Mode code in the layout. With your own Google Consent Mode v2 code, the order is the block, then any Google tag or container, then the snippet, in all 4 generators. Copy the block from Set Up Google Consent Mode v2.

A tag your theme or layouts print runs on every page before any answer. Search the build output to find what is left. This command lists each generated page that still loads a Google tag, with public replaced by _site for Jekyll and Eleventy or dist for Astro.

grep -rl --include="*.html" "googletagmanager.com" public/

Delete each tag from the layout only after its vendor exists. Set each tool up with Add a Vendor From a Template.

Add this element to the footer partial or footer section of the base layout. A click on it opens the Preferences Center, and Privacy Consent keeps its href="#" from jumping to the top of the page once the script has started. Compare the link with the floating button in Let Visitors Reopen Preferences.

<a href="#" id="open_privacy_preferences_element">Privacy Preferences</a>

List each lasting hostname you deploy the site to under "Additional domains" on the Settings page in the TermsFeed app, such as a staging address or a GitHub Pages address. The consent banner loads only on the domains you add, the main website domain and the additional domains, so a preview address missing from the list shows none. Follow the steps in Multiple Domains.

The local server of each generator (hugo server, jekyll serve, npx @11ty/eleventy --serve, astro dev) answers on localhost, where Privacy Consent runs normally and the app takes no entry. A hosting platform that builds a preview per branch creates a new hostname each time. Decide which of those to skip with Install TermsFeed Privacy Consent on Netlify and Vercel or Install TermsFeed Privacy Consent on Cloudflare Pages.

Deploy the build, then check the output folder and the live site.

  1. Run grep -rL --include="*.html" "cdn.termsfeedtag.com" public/ with the output folder of your generator. The command prints each generated page that misses the snippet, and nothing when every page carries it.
  2. Open the deployed site in a private window, open Chrome DevTools, select the Network tab, type termsfeedtag in the filter box, and reload. 7 requests appear with status 200, ending with settings.json twice.
  3. Select the Console tab. No line after [termsfeed] holds [ee] or [ww].
  4. Filter the Network tab for events.push and click I Agree. A new request with status 201 appears.
  5. Open a post, a tag list, and the 404 page. The consent banner stays gone on each, because the same answer applies across the origin, and a termsfeedtag request shows each layout carries the snippet.

A saved answer hides the consent banner on reload, so close every private window and open a new one to test I Decline. Read what each result means, and run the other checks, with Check That Your TermsFeed Privacy Consent Installation Works.

Common mistakes on static sites

Most static site problems come from a layout the edit did not reach.

  • The edit sits in the theme folder. A theme update overwrites it. Copy the file into your own layouts folder and edit the copy.
  • A second layout skips the base template. A standalone layout for the 404 page or a landing page builds its own <head>. Add the snippet to each one.
  • Astro processes the script. Without is:inline, Astro treats the element as its own script. Add the directive.
  • The site configuration still holds an analytics ID. The theme prints the tag on every page before any answer. Remove the ID once the vendor exists.
  • The test runs on a file from the output folder. A file:/// page has no hostname, so Privacy Consent stops and prints [ee][36de8955]. Use the local server of the generator.

Each [ee] or [ww] code names its cause. Find the fix in the Console Error Reference, and read about local files in the environments where Privacy Consent does not run.