Skip to main content

Magento Integration

Track affiliate clicks and sales on a Magento store.

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.

  1. Log in to your Magento Admin panel.

  2. Navigate to System → Configuration → General → Design.

  3. Expand the HTML Head section.

  4. 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 -->
  5. Replace both occurrences of TENANT_ID with your Tenant ID.

  6. Click Save Config.

Step 2: Implement conversion tracking

To track successful sales, you must add the conversion script to the order success page.

  1. Access your server files and navigate to the following path (page after successful checkout):

    app/design/frontend/XXXX/XXXX/template/checkout/success.phtml
  2. Open the success.phtml file in a text editor.

  3. 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 -->
  4. Replace these values:

    • TENANT_ID: your Tenant ID (in both places)

    • CONVERSION_TYPE: the code of your Conversion Type, for example sale

  5. 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:

  1. Create a test click: Use an affiliate tracking link to visit your store.

  2. Complete a purchase: Perform a test transaction.

  3. Check your reports: Log in to Trackdesk and verify that both the Click and the Conversion appear in your reports.

Did this answer your question?