Integrate Trackdesk

Trackdesk is cloud-based affiliate tracking software. It enables you to create, track, and optimize your own affiliate programs. Memberful's affiliate tracking features can be used in conjunction with Trackdesk. For complete instructions on how to use Trackdesk, check out their knowledge base.

Memberful allows you to offer rewards to members who refer others to join your membership program in the form of a discount that will be applied to their active subscription. Learn more about our built-in referrals program.

In this help doc:

Review your options for affiliate tracking

Memberful works best with Tapfiliate as your affiliate tracking software. However, you can also use Trackdesk, which is a more affordable option.

If you use Trackdesk, you'll need to manually prepare and add the affiliate tracking codes to your site, as there is no WordPress plugin for this service. Tapfiliate does have a WordPress plugin that automates this for you, so setting it up is much simpler.

One advantage of TrackDesk is that it's able to track renewals, refunds, and disputes automatically and without custom development required via their Stripe integration.

In this article, we'll explore how to integrate Trackdesk with Memberful.

Create your affiliate program

From your Trackdesk account, create an offer. We'll keep things simple for now so you can get up and running quickly.

Select Custom built website as the offer type, then select Pay affiliates % from sales or Pay affiliates fixed commission from sales depending on your preference.

Custom built website

Percentage or fixed commission

Next, enter the URL of your Landing Page. This is where leads will arrive when they open the links that your affiliates will share.

Landing Page URL

Fill out the details of how much you'd like to pay your affiliates. You may see different fields depending on what you picked in previous steps.

Fill out payout details

Once you've created your offer, click the Invite button and copy the invite URL to share (on your website, via email, or through social media) so your affiliates can sign up.

Trackdesk affiliate invite

Trackdesk affiliate invite link

Once a person signs up to become an affiliate, they will receive their own unique referral link to share with their customers or followers. They can find their unique link in the Offers section of their Trackdesk dashboard.

Trackdesk affiliate unique link

Integrate Trackdesk with Memberful

Although we'll be using Trackdesk for our affiliate tracking, we'll be using Memberful's Tapfiliate integration to make this work. Memberful's Tapfiliate integration is really a generic integration that can be used with other affiliate tracking software, although it was initially desgined for Tapfiliate.

Navigate to Settings → Third-party services → Tapfiliate in your Memberful dashboard, and click Connect to Tapfiliate.

Then navigate to Customize → Checkout and fill the Redirect to this page after every order field. If you prefer, you can also set this on a per-plan basis by going to the desired plan and setting the redirect URL.

This should be the URL of a page on your website, usually a "Thank you" page. Memberful-hosted pages like our landing page or plan purchase URLs won't work.

Redirect URL

Track conversions on your website

You'll need to add some JavaScript code to your pages to track visits to your website via affiliate links. Trackdesk calls these "clicks" but they're really visits to your website.

Place this code in every page of your website between the <head> and </head> HTML tags:

<!-- 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 -->

Replace YOUR_TENANT_ID with your actual Trackdesk account ID, which can be found in your Trackdesk account by navigating to Settings → Your trackdesk identifiers → Tenant ID.

Trackdesk Tenant ID

Next, you have two options:

  1. If you just want to issue one-time commissions for new orders and you don't need Trackdesk to automatically detect renewals, refunds, or disputes, you can insert some simple JavaScript code into your "Thank You" page. This code will report the conversion to Trackdesk.
  2. However, if you want to issue recurring commissions to affiliates for the duration of the subscription, or you want Trackdesk to automatically react to refunds and disputes, you'll need to integrate Trackdesk with Stripe and insert some more complex code into your "Thank You" page. This code will fetch the member's email address via Memberful's API so that Trackdesk and Stripe can continue to track future events for that member's subscription. Skip over to the Integrate Trackdesk with Stripe section for instructions on how to do this.

If you picked option 1, place the following code inside the <head> tag of your "Thank You" page, configured in the Integrate Trackdesk with Memberful section. This will fetch the member's email address via Memberful's API and report your conversion to Trackdesk:

<!-- 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", "conversion", {
    "conversionType": "sale",
    "externalId": {queryParam: "order_id"},
    "cid": {queryParam: "member_id"},
    "revenueOriginId": "YOUR_REVENUE_ORIGIN_ID",
    "amount": {
      "value": {queryParam: "amount"}
    }
  });
</script>
<!-- Trackdesk tracker end -->

Replace the YOUR_TENANT_ID and YOUR_REVENUE_ORIGIN_ID values with your Trackdesk tenant ID and revenue origin ID, both of which can be found in your Trackdesk account by navigating to Settings → Your trackdesk identifiers.

Tenant ID and Revenue Origin ID

Integrate Trackdesk with Stripe

Trackdesk integrates with Stripe, which allows Trackdesk to automatically detect refunds, disputes, and renewals (to pay your affiliates a recurring commission for the duration of a subscription). To integrate Trackdesk with Stripe:

  1. From your Trackdesk dashboard, navigate to Integrations → Stripe via Customer Email.
  2. Follow the first 2 steps on this page to integrate Trackdesk with Stripe. Ignore the last two steps for now.
  3. The last two steps on this page instruct you to add some JavaScript code to your pages, but you can ignore that code. We've prepared some code for you here which is already adapted to work with Memberful.

Insert this code in the head section of every page of your website, as high as possible within the <head> and </head> HTML tags.

<!-- 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 -->

Next, you'll need to insert some code into the post-purchase page of your website, which is the page that your customers see after they complete a purchase. This is usually a "Thank you" page.

In this code, we're going to make an API call to Memberful to fetch the member's email address, which we'll then pass to Trackdesk. Trackdesk will use this email address to track renewals, refunds, and disputes.

This API call should be made on the server-side, so you'll need to use a server-side language like PHP, because you don't want to expose your Memberful API key to the public.

If you're using WordPress, you can use a plugin like WPCode to insert PHP code into your pages, although you should consult with a web developer to ensure that the code you insert is secure and won't break your website, and that you are handling any possible errors gracefully.

Our Tapfiliate integration doesn't require this step in order to track renewals (although refunds and disputes do require some extra work to track), so if you're looking for a simpler solution, use our Tapfiliate integration instead.

Here is some sample PHP code to extract the member ID from the URL, query the member's data from Memberful's API, and report the member's email address to TrackDesk in order to track renewals, refunds, and disputes. This is just a sample, though, so make sure to modify and expand the code accordingly.

<?php

$memberId = filter_input(INPUT_GET, 'member_id', FILTER_SANITIZE_NUMBER_INT);

if (!$memberId) {
    logError("memberID error: Invalid or missing memberId");
    return;
}

$responseData = executeGraphQlQuery($memberId);

if (!$responseData || !isset($responseData['data']['member']['email'])) {
    logError("Email not found in response");
    return;
}

$memberEmail = $responseData['data']['member']['email'];
$escapedEmail = htmlspecialchars($memberEmail, ENT_QUOTES, 'UTF-8');

outputTrackingScript($escapedEmail);

function executeGraphQlQuery($memberId) {
    $url = 'https://YOUR_MEMBERFUL_SUBDOMAIN.memberful.com/api/graphql';
    $authToken = "MEMBERFUL_API_KEY"; //Ideally, load this from an environment variable

    $query = <<<'GRAPHQL'
    query GetMember($id: ID!) {
        member(id: $id) {
            email
        }
    }
    GRAPHQL;

    $headers = [
        'Authorization: Bearer ' . $authToken,
        'Content-Type: application/json'
    ];

    $payload = json_encode([
        'query' => $query,
        'variables' => ['id' => (string)$memberId]
    ]);

    $ch = curl_init($url);
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $payload,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_SSL_VERIFYPEER => true
    ]);

    $response = curl_exec($ch);
    if (curl_errno($ch)) {
        logError('cURL error: ' . curl_error($ch));
        curl_close($ch);
        return null;
    }
    curl_close($ch);

    $responseData = json_decode($response, true);
    if (json_last_error() !== JSON_ERROR_NONE) {
        logError('JSON decode error: ' . json_last_error_msg());
        return null;
    }

    return $responseData;
}

function logError($message) {
    // Replace this with your chosen logging mechanism
    echo htmlspecialchars($message, ENT_QUOTES, 'UTF-8');
}

function outputTrackingScript($email) {
    $emailJson = json_encode($email);
    echo <<<HTML
<!-- 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", "externalCid", {
    "externalCid": $emailJson,
    "revenueOriginId": "YOUR_REVENUE_ORIGIN_ID"
  });
</script>
<!-- Trackdesk tracker end -->
HTML;
}
?>

Take the following steps to adapt this code to your account:

If you run into any issues, review Trackdesk's documentation about integrating with Stripe.

Track and manage affiliate activity

If a member uses an affiliate’s referral link to access your website and make a purchase, the information about the order is communicated to Trackdesk via the code you inserted into your website. You can manage your affiliates (and their payments) through your Trackdesk account.

Locate a Trackdesk conversion in Memberful

If you did not integrate Trackdesk with Stripe, you can locate a Trackdesk conversion in Memberful by replacing some values the URL below and opening it in your browser:

https://YOUR_MEMBERFUL_SUBDOMAIN.memberful.com/admin/orders/YOUR_ORDER_ID

Replace YOUR_MEMBERFUL_SUBDOMAIN with your actual Memberful Account URL sudomain, which can be found via Settings → Website name and URL.

Replace YOUR_ORDER_ID with the External ID for this conversion in Trackdesk. You'll probably need to scroll all the way to the right to see this column in the table of conversions.

Conversion External ID

If you integrated Trackdesk with Stripe, conversions are detected automatically in Stripe, so the Memberful Order ID isn't present in Trackdesk. However, you can still locate the order by searching for the member's email address (displayed in the "External CID" column in Trackdesk) in Memberful and looking for an order placed by that member with an amount and date that matches the conversion in Trackdesk. The date might be off by 1 day due to time zone differences.

Conversion External CID

Set up recurring commissions

If you've integrated your Trackdesk account with Stripe and implemented the conversion tracking script, Trackdesk will automatically track recurring conversions for you, as it will be able to identify a returning customer by their email address.

Automatically handle refunds

If you've integrated your Trackdesk account with Stripe and implemented the conversion tracking script, all refunds initiated inside Memberful will automatically be propagated to your Trackdesk account.

Full refunds will result in a commission being disapproved, while partial refunds will decrease the refunded amount from the total conversion amount.

Automatically handle disputes

If you've integrated your Trackdesk account with Stripe and implemented the conversion tracking script, all disputes in Stripe will automatically result in a Trackdesk commission being disapproved.

Related help docs:

Can't find what you're looking for? We'd love to help! 💪

Send us a message through the orange chat bubble in the lower right corner of the page. You'll hear back within a few hours Monday - Friday. 😀