Skip to main content

Share consent across different domains

Avoid re-requesting consent from a visitor moving from one of your sites to another by passing their token in your links and loading the same configuration everywhere.

Written by Manon Manso

When a visitor makes their choice in your banner, their consent is recorded with an anonymous identifier: the token. By passing this token in links between your sites via the axeptio_token parameter, the destination site retrieves the visitor's choice and does not display the banner a second time. You can share consent between two sites or more.

What this sharing allows
Consent follows the visitor as they move from one of your sites to another by clicking a link. This is not a single consent for all your sites: a visitor who arrives directly on one of them (from a search engine, an advertisement, or by typing the address) sees the banner, even if they have already made their choice on another of your sites.

👉 In this article, we will use two sites as an example: maboutique.com and monblog.com. The process is the same with three or more sites.
For a main domain and its subdomains (maboutique.com, aide.maboutique.com…), see Share consent between main domain and subdomains.

Prerequisite: the same configuration on all your sites

Consent is linked to a configuration. For it to be shared, all your sites must load the same project and the same configuration, that is, the same cookies version: the same technical name indicated in the cookiesVersion parameter of your integration.

Using the same project is not enough. Two different configurations of the same project do not share consent, even if one was created by duplicating or translating the other.

On your sites

Result when the visitor arrives on another of your sites

Same project, same configuration

Consent is retrieved: the banner is not displayed.

Same project, different configurations

The token is passed, but consent is not found: the banner is displayed again.

Different projects

The banner is displayed again.

Consequence: your visitors see the same banner, with the same design and the same texts, on all sites that share consent.

Set up consent sharing

  1. Choose the configuration common to all your sites.

  2. In this configuration, add all the services used on all the relevant sites, not just one of them.

  3. Integrate Axeptio on each of your sites, with the same project identifier and the same cookies version.

  4. On each of your sites, add the code below, specifying in sharedConsentDomains the domains of all your sites, including the one on which you are adding the code, without https:// or www. The list is the same on each site.

Code to add:

<script>
// Sharing Axeptio consent between your sites.
// Add this code on each of the sites listed below.
window._axcb = window._axcb || [];
window._axcb.push(function (axeptio) {
// Waits for the visitor to make their choice in the banner
axeptio.on("cookies:complete", function () {
// TO MODIFY: the domains of all your sites, including this one,
// without https:// or www. The list is the same on each site.
// Their subdomains (www, fr, blog…) are included automatically.
var sharedConsentDomains = [
"maboutique.com",
"monblog.com"
];

// Returns the domain from the list to which an address belongs, or null
function findSharedDomain(hostname) {
return sharedConsentDomains.find(function (domain) {
return hostname === domain || hostname.endsWith("." + domain);
}) || null;
}

// Page outside the list: no links are modified
var currentDomain = findSharedDomain(window.location.hostname);
if (!currentDomain) {
return;
}

document.querySelectorAll("a[href]").forEach(function (link) {
var url;
try {
url = new URL(link.href);
} catch (e) {
return; // Unreadable address: this link is ignored
}
// Only links to web pages are processed (not mailto:, tel:…)
if (url.protocol !== "http:" && url.protocol !== "https:") {
return;
}
// Adds the visitor's token to links to another site in the list
var targetDomain = findSharedDomain(url.hostname);
if (targetDomain && targetDomain !== currentDomain) {
url.searchParams.set("axeptio_token", axeptio.getToken());
link.href = url.href;
}
});
});
});
</script>

Once the visitor has made their choice, this code adds their token to links that lead to another domain in the list, or to one of its subdomains. Other links are not modified. A link to monblog.com becomes for example:

<a href="https://www.monblog.com/?axeptio_token=VISITOR_TOKEN">

VISITOR_TOKEN is replaced by the visitor's token, added automatically by the code.

If you have more than two sites, add the domain of each of them to sharedConsentDomains, then add this code, with the same list, on each of them. For example, with a third site monforum.com:

var sharedConsentDomains = [
"maboutique.com",
"monblog.com",
"monforum.com"
];

What this code does, step by step

  1. It waits for the visitor to make their choice in the banner: accept, refuse, or customize. Before that moment, it does not modify anything.

  2. It reads the list of your sites, sharedConsentDomains. Each domain in the list includes its subdomains: www.monblog.com and fr.monblog.com count as monblog.com.

  3. It looks in the list for the site it is on. If it does not find it, it stops without modifying any links: this is why the list must contain all your sites, including the one on which the code is installed.

  4. It goes through all the links on the page. A link that leads to another site in the list receives the axeptio_token parameter, with the visitor's token. Other links remain as they are: links to the same site, to a site not in the list (Google, Facebook…), mailto: or tel: links, unreadable addresses.

The code only modifies links present on the page when the visitor makes their choice. A link that appears later, for example in a menu loaded afterwards, does not receive the token.

Expected result

When a visitor makes their choice on maboutique.com, then clicks on a link to monblog.com, the Axeptio SDK reads the token in the URL and retrieves their choice: the banner is not displayed on monblog.com. Sharing works between all sites in the list, in all directions, since the code is present on each of them.

If your sites are multilingual

Create one configuration per language, and load the same configuration for a given language on all your sites: for example, the French configuration on the French versions of maboutique.com and monblog.com. Each of these configurations declares all the services used on all your sites.

Links from one site to another must lead to the same language. If a link from the French version of maboutique.com leads to the Spanish version of monblog.com, both pages load different configurations: the banner is displayed again.

On the same site, changing language (for example going from /fr to /es) does not cause the banner to reappear when the configurations of these languages declare the same services: the visitor's choice is read from their browser cookie.

To load the correct configuration according to the page language, see Adapt your banner for different versions of your site: introduction.

Did this answer your question?