Integrating Stripe via Payment Links is a quick and effective way to set up your affiliate program for your landing pages. Once configured, Trackdesk will automatically track all conversions from your customers, seamlessly updating them for billing events, refunds, and cancellations.
๐ก Tip: You can identify a standard Stripe payment link if it contains buy.stripe.com in the URL, as shown in the image below.
Step 1: Install and Configure the Trackdesk App in Stripe
Install our Trackdesk app directly from Stripe App Marketplace, which you can access by clicking here.
โOpen the app settings within your Stripe dashboard.
โFill in the required information to connect your account:
โSave your changes.
โ
Step 2: Set Up Click Tracking
To accurately track affiliate clicks, you need to add our click tracking script to every page of your website, including all landing pages associated with your offer.
For the best results, place this code as high as possible within the <head> tag of your HTML document.
<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");
// REPLACE 'YOUR_TENANT_ID' with your actual Trackdesk Tenant ID
trackdesk('YOUR_TENANT_ID', 'click');
</script>
โ ๏ธ Important: Remember to replace: YOUR_TENANT_ID with your actual Tenant ID.
Step 3: Add the Stripe Payment Link Script
To ensure the affiliate tracking ID is passed to Stripe, you need to add a "helper script" ideally right before the closing </body> tag of the page where your payment buttons/links are located.
Choose the scenario below that matches your website setup:
Scenario A: The Payment Link is on a DIFFERENT page than the Landing Page
Use this script if the customer lands on Page A, but clicks the actual Stripe payment link on Page B.
<script>
(function () {
/ Note: The spelling "trakdesk_cid" is intentional. Do not change it.
var cookie = document.cookie.match('(^|;)\\s*trakdesk_cid\\s*=\\s*([^;]+)');
if (Array.isArray(cookie)) {
try {
var trakdeskCid = JSON.parse(cookie.pop());
var cid = trakdeskCid['cid'];
document.querySelectorAll('a[href^="https://buy.stripe.com/"]').forEach(function (a) {
var url = new URL(a.href);
url.searchParams.set('client_reference_id', cid);
a.href = url.href;
});
} catch (e) {
console.log(e);
}
}
})();
</script>
โ ๏ธ Important: The spelling "trakdesk_cid" is intentional. Do not change it.
Scenario B: The Payment Link is on the SAME page as the Landing Page
Use this script if the customer lands on the page and clicks the Stripe payment link on that exact same page. This script includes a slight delay to ensure the click is registered first.
<script>
(function () {
var linksUpdated = false;
setInterval(function () {
// Note: The spelling "trakdesk_cid" is intentional. Do not change it.
var cookie = document.cookie.match('(^|;)\\s*trakdesk_cid\\s*=\\s*([^;]+)');
if (Array.isArray(cookie) && !linksUpdated) {
try {
var trakdeskCid = JSON.parse(cookie.pop());
var cid = trakdeskCid['cid'];
document.querySelectorAll('a[href^="https://buy.stripe.com/"]').forEach(function (a) {
var url = new URL(a.href);
url.searchParams.set('client_reference_id', cid);
a.href = url.href;
});
} catch (e) {
console.log(e);
} finally {
linksUpdated = true;
}
}
}, 300)
})();
</script>
โ ๏ธ Important: The spelling "trakdesk_cid" is intentional. Do not change it.
Scenario C: Automatically Apply a Stripe Promo Code (Same Page)
If you want to automatically apply a discount for users who use an affiliate link, use this modified version of the "Same Page" script.
โ ๏ธ Important: You must enable the option to accept promo codes inside your Stripe Payment Link settings for this to work.
<script>
(function () {
var linksUpdated = false;
setInterval(function () {
// Note: The spelling "trakdesk_cid" is intentional. Do not change it.
var cookie = document.cookie.match('(^|;)\\s*trakdesk_cid\\s*=\\s*([^;]+)');
if (Array.isArray(cookie) && !linksUpdated) {
try {
var trakdeskCid = JSON.parse(cookie.pop());
var cid = trakdeskCid['cid'];
document.querySelectorAll('a[href^="https://buy.stripe.com/"]').forEach(function (a) {
var url = new URL(a.href);
url.searchParams.set('client_reference_id', cid);
// REPLACE the text below with your actual Stripe discount code
url.searchParams.set('prefilled_promo_code', 'REPLACE_WITH_STRIPE_DISCOUNT_CODE');
a.href = url.href;
});
} catch (e) {
console.log(e);
} finally {
linksUpdated = true;
}
}
}, 300)
})();
</script>
โ ๏ธ Important: The spelling "trakdesk_cid" is intentional. Do not change it.
Advanced Configurations
Using Custom Domains for Payment Links
If you are using a custom domain for your Stripe payment links (e.g., https://customdomain.com/... instead of https://buy.stripe.com/...), you must update the script to match your domain.
Simply find this line in whichever script you chose above:
document.querySelectorAll('a[href^="https://buy.stripe.com/"]').forEach(function (a) {
And replace the Stripe URL with your custom domain URL:
document.querySelectorAll('a[href^="https://customdomain.com/"]').forEach(function (a) {
Tracking Free Trials
If you are tracking free trials through Stripe Payment Links, our system handles this automatically. However, you must ensure that the specific Offer in Trackdesk has the Conversion Type set to Free trial.
Testing Your Integration
Before officially launching your affiliate program, we highly recommend running a test click and conversion to verify everything is set up correctly. (Learn how to create a test click and conversion here).
โ ๏ธ Important Notes for Testing:
Our Stripe app works across all Stripe environments: Live mode, Test mode, and Sandbox mode.
To optimize performance, out Stripe app checks for new conversions every 15 minutes. If you want to speed this up during testing, go to the Trackdesk Stripe App settings in your Stripe Dashboard and click the Check Now button to force a manual sync.
If you run into any tracking issues, please refer to our Stripe Integration Troubleshooting Guide.
Other Stripe Integration Methods
Depending on your website's architecture, you might prefer a different method to connect Stripe. We also support:

