Functionality
-
Retrieving the
tpccparameter from the URL-
The function
getQueryParamByName('tpcc')searches for thetpccparameter in the URL. -
If the parameter is found, its value is stored in the
tpccvariable.
-
-
Creating cookie data
-
A
campaignCodeDateobject is created, containing the timestamp of when the cookie was set. -
The top-level domain is determined using
getTopLevelDomain()so that the cookie is accessible across all subdomains.
-
-
Setting the cookie
-
The
setCookieConsent()function is called, which sets thetpcc_<value>cookie with specific parameters (expiration period: 90 days, path:/, defined domain).
-
-
Cookie synchronization (only for Safari)
-
If the browser is Safari or UIWebView,
itp.synchronizeCookie()is executed, which:-
Restores previously saved cookies from
localStorage. -
Adds the current cookies to the list for sending.
-
Saves them in
localStorage. -
Triggers a delayed cookie submission via an AJAX request to
pn.cloudflareWorkerUrl.
-
-
Limitations
-
Does not work in private browsing modes that block
localStorage. -
Requires proper consent configuration (
consent["vx"]must be initialized). -
For proper functionality in Safari,
pn.cloudflareWorkerUrlmust be configured and accessible. -
The cookie is only set if
tpccis present in the URL.
Synchronizing cookies and consents with postMessage and tp.util.setTpccCookies
If a user visits the site for the first time and has not given consent for cookie processing, the cookies will not be set and will have to be synchronized afterwards. In Safari, synchronization is performed via itp.synchronizeCookie(), using localStorage for temporary cookie storage before sending them to the server.
In general case, after consent is granted, cookies can be synchronized via the postMessage mechanism allowing communication between domains. In the example below such synchronization is configured for https://example.com and its consent page https://consent-example.com (please use your URLs instead).
-
Add the code below to to your consent page.
window.addEventListener('message', function (message) {
if (message.origin !== 'https://consent-example.com') {
return;
}
let event;
try {
event = JSON.parse(message.data);
} catch (e) {
return;
}
if (event && event.eventName && event.eventName === 'setTpccCookie') {
console.log('Tpcc cookies successfully set');
tp.util.setTpccCookies();
}
}, false);
2. Add the postMessage to the click function of your consent button.
function onbuttonClick() {
setTimeout(() => {
window.parent.window.postMessage(JSON.stringify({eventName: 'setTpccCookie'}), 'https://www.example.com');
}, 1000)
}
As a result, a 'tpcc_' + tpcc cookie is set (tpcc here is the name in address bar).