When you use redirect tracking but create conversions with Trackdesk scripts, a script on your landing page can save the Click ID from the URL in a cookie. Your conversion scripts then use it to credit the right affiliate.
⚠️ Important:
Cookie Naming: The cookie name
trakdesk_cidis intentional and must not be changed. The system specifically looks for this string to attribute conversions.
Before you start
Before implementing the script, ensure you have the following:
Your Tenant ID: Found in your Trackdesk account under Settings.
Landing Page Access: You must be able to edit the HTML code of the page where users land after the redirect.
Parameter Name: Identify which URL parameter will carry the Click ID (e.g.,
utm_term).
Step-by-step instructions
Step 1: Identify your tracking parameter
Decide which parameter you will use in your redirect link to pass the Click ID. While this guide uses utm_term as an example, you can use any parameter name as long as it matches the script configuration in the next step. In your Trackdesk offer, add this parameter with the {cid} token to the redirect landing page URL, for example https://yourwebsite.com/?utm_term={cid}. Trackdesk replaces {cid} with the Click ID on each click.
Step 2: Customize the redirect script
Copy the code block below:
<!-- 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();
// Secure and SameSite attributes for better modern security practices
document.cookie = name + "=" + value + ";" + expires + ";path=/;Secure;SameSite=Lax";
}
// Main script execution
(function() {
const utmTerm = getQueryParameter("utm_term");
// Regex for standard UUID format: 8-4-4-4-12 alphanumeric hex characters
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
// Check if utmTerm exists and matches the UUID pattern
if (utmTerm && uuidRegex.test(utmTerm)) {
const cookieContent = {
tenantId: "TENANT_ID",
cid: utmTerm
};
// Convert the cookie content to a JSON string
const cookieValue = encodeURIComponent(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 is not a valid UUID. Cookie not set.");
}
})();
</script>
<!-- Trackdesk help script redirect flow end -->
Replace these values:
TENANT_ID: your Tenant IDutm_term(optional): if you are not usingutm_term, replace it in the script (in thegetQueryParametercall and in the log message) with your chosen parameter name30(optional): how many days the cookie is kept. Set it to your Cookie expiration in Settings → Tracking → Conversions (30 days by default), or to the offer's own cookie expiration if the offer overrides it.
Step 3: Insert the script into your landing page
Open your landing page HTML file or your CMS editor (e.g., WordPress, Webflow).
Paste the customized script as high as possible in the
<head>of your landing page, so the Click ID is saved as soon as the page loads.
Step 4: Check the cookie
Open a tracking link for a test affiliate and, on your landing page, check in your browser's developer tools that a trakdesk_cid cookie was created. If it wasn't, the browser console shows utm_term parameter is missing or is not a valid UUID. Cookie not set.
