The Personalization tracking cookie can be shared across subdomains by setting the cookieDomain
parameter to the main host domain. Here is an example for a retail company with multiple websites and subdomains in one dataset:
const getCookieDomain = () => {
let currentDomain = window.location.hostname;
if (currentDomain === "www.brandone.com.au") {
return "brandone.com.au";
} // All subdomains must use the same cookieDomain value
else if (window.location.href.indexOf("brandtwo.com.au") > -1) {
return "brandtwo.com.au";
}
};
const currentCookieDomain = getCookieDomain();
if (currentCookieDomain === "brandtwo.com.au" && (
window.location.hostname === "brandtwo.com.au" ||
window.location.hostname === "sub1.brandtwo.com.au" ||
window.location.hostname === "sub2.brandtwo.com.au" ||
window.location.hostname === "sub3.email.brandtwo.com.au")
) {
SalesforceInteractions.init({
cookieDomain: currentCookieDomain
});
}