Skip to main content
All CollectionsTracking Implementation
Cookie decor between domain redirects
Cookie decor between domain redirects
Hanna Mattsson avatar
Written by Hanna Mattsson
Updated over a week ago

If your store website has different domain-structures for different markets/countries we must ensure the cookie does not get lost between redirects on the site. This might already be the behaviour on your site, or it might be necessary to add the Klarna Creator cookie "caprl" as link-decor between the domains.
​
​Example case: if a shopper based in the UK clicks a tracking link generated by an SE creator which goes to yourstorename.se. Then when the shopper land on the .se domain, they would select to browse the UK website which takes them to yourstorename.uk - in these cases (no matter if the redirect is automatic, via a pop-up when they land on the website or that the shopper manually select a different country on the interface) we must ensure that the cookie set when the shopper came to the .se domain is following along and is saved in the browser when they reach the .uk domain. Otherwise, we will not track the order if placed on the .uk domain.

Find below our example script for link-decor, please note this would need to be tweaked according to your code for it to work as expected:

// domainToAppend is the outside domains needing to be decorated.
// So if I put this script on somepage.se and have outgoing links to somepage.com
// I need to set domainToAppend = "https://somepage.com".
// If I have links to somepage.se on somepage.com then when I add this script to somepage.se
// I need to set the domainToAppend = "https://somepage.com"

const apprlCookieName = "caprl", domainToAppend = "https://somepage.se";

function getApprlCookie() {
const e = '; ${document.cookie}'.split('; ${apprlCookieName}=');
if (e.length > 1) {
const t = e[e.length - 1].split("|");
if (2 === t.length) {
return t[0]
}
}
}

function updateQueryStringParameter(e, t, o) {
var r = new RegExp("([?&])" + t + "=.*?(&|$)", "i"), n = -1 !== e.indexOf("?") ? "&" : "?";
return e.match(r) ? e.replace(r, "$1" + t + "=" + o + "$2") : e + n + t + "=" + o
}

window.addEventListener("load", function () {
const e = getApprlCookie();
if (e) {
const r = document.querySelectorAll("a[href^='" + domainToAppend + "']");
for (var t = 0, o = r.length; t < o; t++) {
const o = r[t], n = updateQueryStringParameter(o.href, apprlCookieName, e);
o.setAttribute("href", n)
}
}
});


​
​

Did this answer your question?