This guide explains how to capture and store a Click ID (CID) in a browser cookie when using a redirect tracking flow. This configuration is beneficial when you want to route traffic through redirect links but still use scripts to create conversions at the same time.
By implementing this script, your landing page will detect the tracking parameter from the URL, format it to be compatible with standard Trackdesk Click scripts, and save it as a cookie.
⚠️ Important:
Cookie Naming: The cookie name
trakdesk_cidis intentional and must not be changed. The system specifically looks for this string to attribute conversions.
1. 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).
2. 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.
Step 2: Customize the Redirect Script
Copy the code block below and replace the placeholder variables with your specific details:
Replace
YOUR_TENANT_IDwith your actual Trackdesk Tenant ID.
(Optional) If you are not using
utm_term, replace both instances of'utm_term'in the script with your chosen parameter name.
<!-- 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: "YOUR_TENANT_ID",
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 -->
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 within the
<head>section, or immediately before the closing</body>tag.
