This guide focuses on the ability to store CID in a cookie after using Redirect links.
Why might you need this?
This is beneficial when you want to use the redirect flow for traffic routing and use scripts to create conversions at the same time.
Therefore, if you are looking to have a script that will save the CID from redirect on landing page, this is it.
The script is designed to work with a redirect flow, where a user is redirected to a website with a specific URL parameter, in an example case `utm_term`. The script checks if this parameter is present and has a specific length. Then, it sets the standard tracking cookie, to comply with how the tracking cookie looks when used via Click script.
Below is the script that allows saving the CID from redirect to browser cookie after user landing.
This script needs to be placed on the landing page where user lands from the redirect tracking.
<!-- Trackdesk help script redirect flow begin -->
<script>
// Function to get a query parameter by name from the URL
function getQueryParameter(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
// Function to set a cookie
function setCookie(name, value, days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
const expires = "expires=" + date.toUTCString();
document.cookie = name + "=" + value + ";" + expires + ";path=/";
}
// Main script execution
(function() {
const utmTerm = getQueryParameter('utm_term');
if (utmTerm && utmTerm.length === 36) {
const cookieContent = {
tenantId: "yourtenantid",
cid: utmTerm
};
// Convert the cookie content to a JSON string
const cookieValue = JSON.stringify(cookieContent);
// Set the cookie
setCookie('trakdesk_cid', cookieValue, 30); // Cookie expires in 30 days
} else {
console.log("utm_term parameter is missing or doesn't have length of 36 characters. Cookie not set.");
}
})();
</script>
<!-- Trackdesk help script redirect flow end -->
Make sure to replace 'yourtenantid' with your actual Tenant ID.
And potentially change the value 'utm_term' if a different parameter will contain the Click ID on the landing page.
After the above update, you can continue with standard direct linking integration for conversions via scripts.