Keep the Privacy Consent cookie banner working on production and preview deployments
Netlify and Vercel serve each deployment on a hostname of its own, and the TermsFeed Privacy Consent cookie banner keeps a separate answer on each one. The snippet still goes in the <head> of the site you deploy, and no step needs a paid Netlify or Vercel plan. Place the snippet first with Install TermsFeed Privacy Consent on Next.js, Install TermsFeed Privacy Consent on a Static Site, or Install TermsFeed Privacy Consent on React, Vue, or Angular.
Every deployment on these hosts gets its own hostname
Each host gives the production site a lasting hostname and gives previews new ones. In these usual formats, site or project stands for the name of your project.
| Host | Production hostnames | Preview hostnames |
|---|---|---|
| Netlify | Your custom domain and site.netlify.app |
deploy-preview-42--site.netlify.app for a pull request, branch--site.netlify.app for a branch deploy |
| Vercel | Your custom domain and project.vercel.app |
project-git-branch-team.vercel.app for a branch, plus a unique address per deployment |
The consent banner loads only on the main website domain and the additional domains, so a preview hostname you did not add shows none. A tester who answered on production sees the consent banner again on a listed preview, because each origin stores its own answer in localStorage. The consent log records each hostname in the domain column of the CSV.
Which hostnames to add and why branch previews are skipped
Add your custom domain, the lasting project hostname, and any fixed staging branch you test on, and skip the hostnames each push creates. List each lasting Netlify or Vercel hostname that carries the snippet under "Additional domains" on the Settings page in the TermsFeed app.
Listing a per-deployment hostname fills the list with dead addresses after the merge. Test the consent banner on your fixed staging branch instead. Follow the steps in Multiple Domains.
Keep the script address in an environment variable
Store the full script address in an environment variable, with a value per deploy context in the dashboard of your host. Production then loads the consent banner your visitors see. A preview loads either the same address or the address of a separate test consent banner, which keeps test clicks out of the production consent log.
Netlify sets separate values for Production, Deploy Previews, and Branch deploys. Vercel sets them under Project Settings > Environment Variables, for Production, Preview, and Development. The value is the complete address from the snippet, such as https://cdn.termsfeedtag.com/plugins/pc/v1/YOUR_TOKEN/plugin.js. The build reads it, so change the value and redeploy to switch consent banners.
A Next.js root layout prints the element only when the variable holds a value.
// app/layout.tsx
import type { ReactNode } from 'react';
const privacyConsentSrc = process.env.NEXT_PUBLIC_TERMSFEED_PC_SRC;
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<head>
{privacyConsentSrc && (
<script type="text/javascript" src={privacyConsentSrc} async />
)}
</head>
<body>{children}</body>
</html>
);
}
An Astro layout reads the variable from import.meta.env.
---
// src/layouts/Layout.astro
const privacyConsentSrc = import.meta.env.PUBLIC_TERMSFEED_PC_SRC;
---
<html lang="en">
<head>
<meta charset="utf-8" />
{privacyConsentSrc && (
<script is:inline type="text/javascript" src={privacyConsentSrc} async></script>
)}
</head>
<body>
<slot />
</body>
</html>
A Hugo base template reads variables whose names start with HUGO_, which the default Hugo security policy allows.
{{ with os.Getenv "HUGO_TERMSFEED_PC_SRC" }}
<script type="text/javascript" src="{{ . }}" async></script>
{{ end }}
A Vite index.html replaces %VITE_...% placeholders at build time. Vite leaves a placeholder unchanged when the variable is missing.
<script type="text/javascript" src="%VITE_TERMSFEED_PC_SRC%" async></script>
Why proxying the script through your domain breaks it
Proxying the script breaks it unless the proxy forwards every Privacy Consent path, because a copy served under the same path sends every later request to your domain. Read which requests the proxy has to forward, and how it changes visitor location and script updates, in What Is cdn.termsfeedtag.com?.
Remove any rule of this kind from netlify.toml, _redirects, or vercel.json.
/plugins/* https://cdn.termsfeedtag.com/plugins/:splat 200
Set Content Security Policy headers on each host
A Content Security Policy on these hosts allows https://cdn.termsfeedtag.com in script-src and connect-src, and inline styles in style-src. Netlify reads a _headers file in the publish folder.
/*
Content-Security-Policy: script-src 'self' https://cdn.termsfeedtag.com; connect-src 'self' https://cdn.termsfeedtag.com; style-src 'self' 'unsafe-inline'
Vercel reads the headers key of vercel.json at the project root.
{
"headers": [
{
"source": "/(.*)",
"headers": [
{
"key": "Content-Security-Policy",
"value": "script-src 'self' https://cdn.termsfeedtag.com; connect-src 'self' https://cdn.termsfeedtag.com; style-src 'self' 'unsafe-inline'"
}
]
}
]
}
These policies allow Privacy Consent and block every inline script, including an inline vendor tag and your own Consent Mode block. Add what your vendors need with the Content Security Policy reference.
How to verify Privacy Consent after a deploy
Deploy, then check the production hostname and one preview hostname, each in a new private window so neither has a stored answer.
- Open the Chrome DevTools Network tab, filter for
termsfeedtag, and reload. 7 requests appear with status 200, and each goes tocdn.termsfeedtag.com, not to your own domain. - Select the second
settings.jsonrequest and open Response. The response holds"serviceable": true. - Select the HTML document request and read the
content-security-policyresponse header on Headers. The header listshttps://cdn.termsfeedtag.com, and the Console tab does not show a "Refused to load" message. - Filter for
events.pushand click I Agree. A new request with status 201 appears.
A preview that loads a test consent banner shows that consent banner, which confirms the variable for the preview context. Run the remaining checks with Verify Your Installation.
Common mistakes on Netlify and Vercel
- The variable exists for Production only. Previews then render without the script, or a Vite build prints the placeholder as the address. Set a value for every context.
- The variable name lacks the prefix the framework reads. Vite reads names that start with
VITE_, and client code in Next.js and Astro readsNEXT_PUBLIC_andPUBLIC_names. Rename the variable. - A rewrite rule proxies the script. A settings request fails, or visitors appear at the proxy location. Remove the rule.
- 2 Content Security Policy headers reach the page. The browser enforces both, so a header from the framework and one from the host each have to allow Privacy Consent. Keep one source.
- A preview answer is expected on production. A tester sees the consent banner again on every new hostname. Test each one in a new private window.
A hostname without a consent banner points to a missing snippet, a blocked script, or a saved answer. Diagnose it with The TermsFeed Privacy Consent Banner Does Not Appear.