Decide how visitors answer the cookie banner on each of your subdomains
A visitor who answers the TermsFeed Privacy Consent cookie banner on one subdomain gets asked again on every other subdomain. Privacy Consent stores the answer in localStorage, which belongs to one origin only. An origin is the scheme, hostname, and port of a page, so www.example.com and shop.example.com are 2 origins. The browser enforces that separation, and no Privacy Consent setting changes it.
Choose between asking on each origin and mirroring the answer into a cookie your own code shares across subdomains. The second option needs edit access to the <head> of every subdomain and takes about 30 minutes.
What adding a domain to the consent banner does
Adding a hostname as an additional domain makes the consent banner load there, beside the main website domain. A hostname you did not add does not show the consent banner.
Adding a domain does not carry an answer across hostnames. A visitor who clicks I Agree on www.example.com still gets the consent banner on shop.example.com, and vendors there run only after the answer given there. Add each hostname with run one consent banner across several domains.
Option 1: Ask for consent on each origin
Asking on each origin is what Privacy Consent does by default, and it needs no code. Each origin collects its own answer, and the consent log records each answer against the hostname where the visitor gave it. Your record then shows which site the visitor was on.
This option asks some visitors twice. A visitor who moves from your marketing site to your shop answers the consent banner again on the shop. Keep it where few visitors cross between subdomains, or where the subdomains run different vendors that need separate answers anyway.
Option 2: Mirror the answer into a shared cookie
Write the answer into a first-party cookie on the parent domain, so your own code on every subdomain reads it. Browsers send a cookie set for example.com with requests to every subdomain of example.com, and scripts on each of them read it. Privacy Consent does not write a cookie of its own, so the callbacks are the source.
Put the block inline in the <head> of every subdomain, above the Privacy Consent snippet, as the only set of callbacks on the page. Replace example.com with your parent domain. The cookie holds the fully accepted vendor category IDs joined with dots, such as functionality.analytics, or none.
<script>
function tfWriteSharedConsent(categories) {
var granted = categories.filter(function (id) { return id !== 'essential'; });
document.cookie = 'tf_consent=' + (granted.length ? granted.join('.') : 'none') +
'; domain=example.com; path=/; max-age=' + 365 * 24 * 60 * 60 + '; SameSite=Lax; Secure';
}
var callbacks = {
acceptedAll: function (categories) { tfWriteSharedConsent(categories); },
acceptedSome: function (categories) { tfWriteSharedConsent(categories); },
rejectedAll: function () { tfWriteSharedConsent([]); }
};
if (window.termsfeed_privacy_consent !== undefined)
window.termsfeed_privacy_consent.v1.callbacks(callbacks);
else
window.termsfeed_privacy_consent_callbacks = callbacks;
</script>
The block writes only from the answer callbacks, so the cookie always holds the latest answer on any subdomain. Keep it that way: a page-load write from localStorage puts the older answer of that subdomain back over a newer decline given elsewhere. A hostname outside the parent domain, such as a preview host, rejects the cookie with no error.
Your own code on the other subdomain reads the cookie with the next function. It returns the list of granted vendor category IDs, or null while no subdomain has recorded an answer.
function tfSharedConsent() {
var match = /(?:^|;\s*)tf_consent=([^;]*)/.exec(document.cookie);
if (!match || match[1] === '') return null;
return match[1] === 'none' ? [] : match[1].split('.');
}
What Privacy Consent ignores in the shared cookie
Privacy Consent never reads the tf_consent cookie, so the consent banner still appears on the second subdomain. Privacy Consent there decides from its own localStorage, runs vendors only after the answer given there, and records that answer in the consent log. The shared cookie changes only what your own code outside Privacy Consent does.
No method sets an answer from outside, so the cookie has no way to answer the consent banner for the visitor. Ask your legal adviser whether an answer given on one subdomain covers your code on another. The consent log does not hold a record of that answer on the second hostname. Keep the cookie to vendor category IDs, because a consent cookie that carries an identifier becomes a tracking cookie itself.
Separate domains never share Privacy Consent answers
Privacy Consent does not share consent between separate domains, so a visitor answers the consent banner once on each domain. example.com and example-shop.com share neither localStorage nor cookies. The shared cookie of option 2 works only between subdomains of 1 parent domain.
Treat each domain as its own consent choice, with its own answer and its own entries in the consent log. The browser sets this limit, and the Privacy Consent settings do not change it.
How privacy browsers limit a shared consent cookie
Safari caps the lifetime of every cookie JavaScript writes at 7 days, so the shared cookie of option 2 lapses a week after the last answer. A lapsed cookie makes your code more cautious, because tfSharedConsent() returns null and your code treats the visitor as undecided. Safari applies this cap through Intelligent Tracking Prevention.
The same Safari feature reaches the answer itself. Safari deletes localStorage for a site after 7 days of Safari use without an interaction on that site, and the consent banner then asks again. Test in Safari as well as Chrome before you rely on the cookie.
What to tell visitors about answering twice
Tell visitors why a second consent banner appears on another part of your site. Add a sentence to your Privacy Policy or Cookies Policy saying that each subdomain stores privacy preferences separately, and name the subdomains. Visitors who expect the question are less likely to report the consent banner as broken.
How to verify consent across your subdomains
Confirm that the shared cookie reaches the second subdomain and that your own code reads it. The consent banner still appears on the second subdomain, which is the expected result. These steps assume a visit that shows the consent banner.
- Open
www.example.comin a private window with Chrome DevTools open and click I Agree. - Select the Application tab, open Cookies, and confirm that
tf_consentexists for the domain.example.comwith the valuefunctionality.analytics.marketing.advertising. - Open
shop.example.comin the same window and confirm that the consent banner appears. - Select the Console tab on
shop.example.com, typetfSharedConsent(), and confirm that it returns the 4 vendor category IDs. - Select the Network tab, type
events.pushin the filter box, click I Decline, and confirm that 1 request with status 201 records the answer forshop.example.com. - Select the Console tab, type
tfSharedConsent(), and confirm that it now returns an empty array.