Skip to main content

Integrate with Dodo Payments

This guide walks you through connecting Affonso with your Dodo Payments account to enable affiliate tracking, payment attribution, and commission management. We'll go through each step, including best practices and important details to ensure a smooth setup.

Written By Silvestro

Last updated About 1 year ago

1. Connect with Dodo Payments

To get started, connect your Dodo Payments account by adding your API key.

How to Get Your Dodo Payments API Key

  1. Log in to your Dodo Payments Dashboard

  2. Go to the Developer section in the left menu

  3. Click on API Keys

  4. Select Add API Key

  5. Give it a name (e.g. “Affonso Integration”)

  6. Click Create and copy your API key

Add Your API Key to Affonso

  1. Open your Affonso Dashboard

  2. Go to Program Details > Connect

  3. Click the Dodo Payments integration card

  4. Paste your Dodo Payments API key

  5. Click Connect

Your key will be securely encrypted.


2. Add Webhook to Dodo Payments

Once connected, you’ll receive a unique webhook URL from Affonso. This is required to track payments and trigger affiliate commissions.

Add Webhook URL in Dodo Payments

  1. In your Dodo Payments Dashboard, go to Developer → Webhooks

  2. Click Add Webhook

  3. Paste your Affonso webhook URL (from your program settings)

  4. Save the webhook

Add Webhook Secret in Affonso

After saving the webhook in Dodo Payments, copy the signing key provided and paste it back into Affonso under the Dodo Payments webhook settings.

This allows Affonso to securely verify incoming events.


3. Add the Tracking Script

Add the Affonso pixel to your website to enable affiliate tracking:

<!-- Place in <head> tag --> 
<script async defer 
src="https://affonso.io/js/pixel.min.js" 
data-affonso="YOUR_PUBLIC_PROGRAM_ID" 
data-cookie_duration="YOUR_COOKIE_DURATION">
</script>

This script:

  • Tracks affiliate visits

  • Sets a cookie for the referral ID (affonso_referral)

  • Enables signup and payment tracking

📌 Place it on all domains where users visit or convert (e.g. marketing site, app)


4. Track User Signups (Optional but Recommended)

You can optionally track signups to gain better funnel insights and help your affiliates improve performance.

// After successful registration 
window.Affonso.signup(userEmail);

This will:

  • Log a new referral as a “LEAD” if the user came via an affiliate link

  • Display it in your dashboard and the affiliate’s stats

Best practice:
Call this on successful signup or after double opt-in (DOI), regardless of referral source.


5. Pass Referral Data to Dodo Payments

To ensure proper attribution, the referral ID needs to be passed to Dodo Payments when creating a payment.

Example Integration

Payments Integration

// Get the referral ID from the Affonso global variable
import DodoPayments from 'dodopayments';

const referralId = window.affonso_referral;

const client = new DodoPayments({
bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
});

async function main() {
const payment = await client.payments.create({
payment_link: true,
billing: { city: 'city', country: 'AF', state: 'state', street: 'street', zipcode: 0 },
customer: { email: 'email@email.com', name: 'name' },
product_cart: [{ product_id: 'product_id', quantity: 0 }],
metadata: {
  affonso_referral: referralId, // Include referral ID from Affonso
}
});

console.log(payment.payment_id);
}

main();

Subscription Integration

// Get the referral ID from the Affonso global variable
import DodoPayments from 'dodopayments';

const referralId = window.affonso_referral;

const client = new DodoPayments({
bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
});

async function main() {
const subscription = await client.subscriptions.create({
billing: { city: 'city', country: 'IN', state: 'state', street: 'street', zipcode: 89789 },
customer: { customer_id: 'customer_id' },
product_id: 'product_id',
payment_link: true,
return_url: 'https://example.com/success',
quantity: 1,
metadata: {
  affonso_referral: referralId, // Include referral ID from Affonso
}
});

console.log(subscription.subscription_id);
}

main();

Payment Links

If you're using Dodo Payments Checkout Links (URLs that start with checkout.dodopayments.com), you need to add an enhancement script to automatically include referral tracking.

What This Script Does

  • Automatically finds all Dodo Payments Checkout Links on your website

  • Adds referral tracking to them without you having to modify each link manually

  • Works with existing links - no need to change your current setup

  • Ensures affiliates get credited when customers purchase through their links

Where to Add the Script

Add this script to every page where you have Dodo Payments Checkout Links. This includes:

  • Your main website pages

  • Landing pages

  • Product pages

  • Any page with "Buy Now" buttons that use Dodo Payments Checkout Links

How to Implement

Place this code in your website's <head> section, after the main Affonso tracking script:

<script>
function enhanceDodoLinks() {
  if (window.affonso_referral) {
    document.querySelectorAll('a[href*="checkout.dodopayments.com"]').forEach(link => {
      if (link.href.includes("metadata_affonso_referral=")) return;
      const separator = link.href.includes('?') ? '&' : '?';
      link.href = link.href + separator + 'metadata_affonso_referral=' + window.affonso_referral;
    });
  }
}

setTimeout(enhanceDodoLinks, 800);
setTimeout(enhanceDodoLinks, 1500);
setTimeout(enhanceDodoLinks, 2500);
window.addEventListener("affonso_referral_ready", enhanceDodoLinks);
</script>

How It Works

  1. Visitor clicks affiliate link → Affonso tracking script sets a cookie

  2. Visitor browses your site → Enhancement script runs automatically

  3. Script finds Dodo Links → Adds referral ID to each Dodo Payments Checkout Link

  4. Visitor clicks "Buy Now" → Goes to Dodo Payments with referral tracking included

  5. Purchase completes → Affiliate gets credited automatically

No Manual Work Required

  • ✅ No need to modify existing Checkout Links

  • ✅ Works with all current and future Dodo Links

  • ✅ Automatically handles multiple links per page

  • ✅ Safe to use - won't break existing functionality

Benefits

  • ✅ No-code setup - just copy and paste the script

  • ✅ Fully compatible with Affonso referral tracking

  • ✅ No backend changes required

  • ✅ Works with existing Dodo Payments Checkout Links

📚 For more details, see the official Dodo Payments API documentation


6. Testing Your Integration

We recommend testing with real affiliate links and transactions.

Checklist:

  • Create an affiliate and generate a tracking link

  • Visit your site via that link

  • Confirm the script loads and affonso_referral cookie is set

  • Complete a signup (optional)

  • Complete a payment via Dodo Payments

  • Check your Affonso dashboard for tracking and attribution


💬 Need Help?

We’re here to help!
If you have any issues or questions:

  • Reach out via live chat

  • Email us at support@affonso.io

Was this helpful?

Still need help? Ask the team