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, as your framework or static site guide shows. These hosts add preview hostnames, environment variables, proxy rules, and security headers to think about, and none of that needs a paid plan on the host. 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. This table shows the usual formats, with site or project standing 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 |
Privacy Consent loads the consent banner on the domains you add: the main website domain and the additional domains. A preview hostname you did not add does not show the consent banner. 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. Enter them on the Settings page, under "What is your website domain?" and "Additional domains". The app stores www.example.com as example.com, and that entry covers www and every subdomain.
A per-deployment hostname does not show the consent banner unless you add it, and listing one fills the list with dead addresses after the merge. Test the consent banner on your fixed staging branch instead. The number of domains on one consent banner has a limit. Add the lasting hostnames with Run One TermsFeed Privacy Consent Banner Across Several 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, so set the variable in every context.
<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. The settings, the code files, and the consent log events all follow the script address. The proxy has to pass each one through with its Origin header unchanged. A proxy that misses a path or the header makes a settings request fail, and the consent banner never appears.
A proxy has 2 more effects. The server locates a visitor from the request it receives, so a proxy makes every visitor appear to come from the proxy location. TermsFeed does not update a copy you serve yourself.
Remove any rule of this kind from netlify.toml, _redirects, or vercel.json. Read why the script has its own host in What Is cdn.termsfeedtag.com?.
/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. Strict, the starting consent logic, asks every visitor wherever they are. Standard in Settings passes over a visitor in a US state, so pick a test location from Cookie Banner by Visitor Location.
- Open Chrome DevTools, select the Network tab, type
termsfeedtagin the filter box, 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. Go through the remaining checks in Check That Your TermsFeed Privacy Consent Installation Works.
Common mistakes on Netlify and Vercel
Most hosting problems come from a variable missing in one context or a header that contradicts another.
- 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. Each hostname stores its own answer, so 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.