Skip to main content

Magento Integration

Written by David Rolenc
Updated over 2 weeks ago

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.


1. 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.


2. Step-by-Step Instructions

Step 1: Install the Click Tracking Script

The click script must be present on every page to track users arriving via affiliate links. The easiest way to achieve this in Magento is through the Footer configuration.

  1. Log in to your Magento Admin panel.

  2. Navigate to Configuration > General > Design.

  3. Expand the Footer section.

  4. Locate the Miscellaneous HTML box and paste the following code:

    <!-- Trackdesk tracker begin -->
    <script async src="//cdn.trackdesk.com/tracking.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('YOUR_TENANT_ID', 'click');
    </script>
    <!-- Trackdesk tracker end -->

  5. Replace YOUR_TENANT_ID with your actual identifier.

  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:

    <!-- 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="//cdn.trackdesk.com/tracking.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('YOUR_TENANT_ID', 'conversion', {
    conversionType: 'YOUR_SELECTED_CONVERSION_TYPE',
    customParams: {
    advS1: '<?php echo $this->getOrderId() ?>',
    },
    amount: {
    value: '<?php echo $amount ?>'
    }
    });
    </script>
    <!-- Trackdesk tracker end -->


  4. Remember to replace:

    • Replace YOUR_TENANT_ID with your actual Tenant ID.

    • Replace YOUR_SELECTED_CONVERSION_TYPE with your chosen type (e.g., sale).

  5. Save the file and upload it back to your server.


3. 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 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?