Integrate your Magento-based website with Trackdesk to automatically track affiliate-driven traffic and sales. This guide explains how to implement the necessary scripts to monitor clicks across your site and record successful conversions on your checkout page.
⚠️ Important:
Compatibility: This guide is designed for websites built on Magento. These steps and the code are for Magento 1 (the code uses the
Mage::API).
Before you start
Locate your Trackdesk Tenant ID (found in Settings → Your Trackdesk identifiers).
Ensure you have administrative access to your Magento backend.
Ensure you have access to your server's file system (via FTP, SFTP, or SSH) to edit template files.
Step-by-step instructions
Step 1: Install the click tracking script
The click script must be present on every page, as high as possible in the page head, so the click is recorded before the visitor can leave the page. In Magento, add it through the HTML Head configuration.
Log in to your Magento Admin panel.
Navigate to System → Configuration → General → Design.
Expand the HTML Head section.
Locate the Miscellaneous Scripts box and paste the following code at the top of it:
<!-- Trackdesk tracker begin -->
<script async src="//TENANT_ID.trackdesk.com/main.js"></script>
<script>
(function(t,d,k){(t[k]=t[k]||[]).push(d);t[d]=t[d]||t[k].f||function(){(t[d].q=t[d].q||[]).push(arguments)}})(window,"trackdesk","TrackdeskObject");
trackdesk("TENANT_ID", "click");
</script>
<!-- Trackdesk tracker end -->Replace both occurrences of
TENANT_IDwith your Tenant ID.Click Save Config.
Step 2: Implement conversion tracking
To track successful sales, you must add the conversion script to the order success page.
Access your server files and navigate to the following path (page after successful checkout):
app/design/frontend/XXXX/XXXX/template/checkout/success.phtml
Open the
success.phtmlfile in a text editor.Paste the following code at the end of the template, so any order details shown on the page are already loaded if you later extend the script to read them:
<!-- Trackdesk tracker begin -->
<?php
$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
$amount = number_format($order->getGrandTotal() - $order->getShippingAmount() - $order->getShippingTaxAmount(), 2, '.', '');
?>
<script async src="//TENANT_ID.trackdesk.com/main.js"></script>
<script>
(function(t,d,k){(t[k]=t[k]||[]).push(d);t[d]=t[d]||t[k].f||function(){(t[d].q=t[d].q||[]).push(arguments)}})(window,"trackdesk","TrackdeskObject");
trackdesk("TENANT_ID", "conversion", {
conversionType: "CONVERSION_TYPE",
customParams: {
advS1: "<?php echo $this->getOrderId() ?>"
},
amount: {
value: "<?php echo $amount ?>"
}
});
</script>
<!-- Trackdesk tracker end -->Replace these values:
TENANT_ID: your Tenant ID (in both places)CONVERSION_TYPE: the code of your Conversion Type, for examplesale
Save the file and upload it back to your server.
Testing
Testing the integration
It is vital to verify the setup before launching your affiliate program:
Create a test click: Use an affiliate tracking link to visit your store.
Complete a purchase: Perform a test transaction.
Check your reports: Log in to Trackdesk and verify that both the Click and the Conversion appear in your reports.
