Skip to main content

Shopify Integration

Track affiliate clicks and Shopify orders.

Integrating Trackdesk with your Shopify store allows you to track affiliate clicks and conversions. By setting up this integration, you can automatically monitor affiliate-generated traffic and attribute sales directly from your checkout, ensuring accurate tracking and commission payouts for your affiliate program.

⚠️ Important: Before you begin, you must set up your system by following the instructions in the Quick Setup section within the Trackdesk platform.


​

Before you start

Make sure you have the following information from your Trackdesk account ready:

  • Your Tenant ID.

  • Your Conversion Type (e.g., sale, lead).

Step-by-step integration

Step 1: Set up click tracking

To track when a user arrives at your store via an affiliate link, you need to add the click tracking script to your Shopify theme.

  1. In your Shopify admin dashboard, go to Sales channels → Online Store → Themes.

  2. In the Current theme box, click on the three dots button and select Edit code from the dropdown menu.

  3. In the layout folder, click on the theme.liquid file to open it.

  4. Copy the following base tracking code and paste it right after the opening <head> tag, so the click is recorded before the visitor can leave the page.

    <!-- 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 in the top right corner to apply the changes.

Step 2: Set up conversion tracking

To record successful purchases, you need to configure a Shopify Custom Pixel.

  1. In your Shopify admin, go to Settings → Customer events.

  2. Click Add custom pixel and name it Trackdesk conversion script.

  3. Set Permissions to Not required and Data sale to Data collected does not qualify as data sale.

  4. In the Code field, paste the following script:

    var script = document.createElement("script");
    script.type = "text/javascript";
    script.async = true;
    script.src = "//TENANT_ID.trackdesk.com/main.js";
    document.head.appendChild(script);

    analytics.subscribe("checkout_completed", event => {
    (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",
    amount: {
    value: event.data.checkout.totalPrice.amount.toString()
    },
    externalId: event.data.checkout.order.id
    });
    });
  5. Replace these values:

    • TENANT_ID: your Tenant ID

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

  6. Click Save and then click the Connect button to apply the changes to your website.

Optional configurations

Using amount without tax

If you prefer to track revenue excluding taxes, shipping, and duties, modify the conversion script in Step 2 by replacing totalPrice with subtotalPrice.

Coupon tracking

For coupon tracking, you also need your Revenue Origin ID.

If you want to attribute conversions via Shopify discount codes, use the following code in your Customer Event pixel instead of the one provided in Step 2:

var script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
script.src = "//TENANT_ID.trackdesk.com/main.js";
document.head.appendChild(script);

analytics.subscribe("checkout_completed", event => {
(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");

const discountApplications = event.data.checkout.discountApplications || [];
const discountTitles = discountApplications.map(discount => discount.title);

trackdesk("TENANT_ID", "conversion", {
couponCodes: discountTitles,
conversionType: "CONVERSION_TYPE",
revenueOriginId: "REVENUE_ORIGIN_ID",
amount: {
value: event.data.checkout.totalPrice.amount.toString()
},
externalId: event.data.checkout.order.id
});
});

Replace these values:

  • TENANT_ID: your Tenant ID

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

  • REVENUE_ORIGIN_ID: your Revenue Origin ID

Advanced

If you need to pass additional Shopify variables (like customer tags or currency), refer to the Shopify Web Pixels API documentation for a full list of available properties.


​

Testing & troubleshooting

Testing

Before officially launching your affiliate program, we highly recommend running a test to verify everything is set up correctly.

  1. Generate a test affiliate link in your Trackdesk account and click on it.

  2. Complete a test purchase on your Shopify store to trigger a conversion.

  3. Go to your Trackdesk dashboard and verify that both the click and the resulting conversion were recorded correctly.

Troubleshooting

  • Check variables: Ensure the values you entered for TENANT_ID, CONVERSION_TYPE, and REVENUE_ORIGIN_ID exactly match your Trackdesk settings (case-sensitive).

  • Pixel status: Confirm that the custom pixel in Shopify Settings → Customer events is marked as Connected.

Did this answer your question?