> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Affiliates

> Run an affiliate program on Dodo Payments with Affonso, Dub Partners, or Rekomi to track referrals, attribute sales, and calculate affiliate commissions.

## Introduction

Run an affiliate program while Dodo Payments processes your sales. An affiliate platform tracks referral visits, receives payment events from Dodo Payments through webhooks, and credits each sale to the affiliate who referred it. Dodo Payments integrates with three affiliate platforms: **Affonso**, **Dub Partners**, and **Rekomi**.

## Key Features

<CardGroup cols={2}>
  <Card title="Automated Commission Attribution" icon="robot">
    Referrals are attributed and logged automatically when a purchase is made, with no spreadsheets or manual tracking.
  </Card>

  <Card title="Real-Time Reporting" icon="chart-line">
    You and your affiliates can monitor performance and leads from dedicated dashboards.
  </Card>

  <Card title="Flexible Tracking Options" icon="code">
    Use tracking scripts, metadata fields, and webhook events to capture referral data across signups and transactions.
  </Card>

  <Card title="Encrypted Credentials and Signed Webhooks" icon="shield">
    Affonso encrypts the API key you give it, and every webhook event is signed so the platform can verify that it came from Dodo Payments.
  </Card>

  <Card title="Quick Setup" icon="bolt">
    Setup takes an API key, a webhook, and a tracking script. The only code you add is the script snippet and the referral metadata at checkout.
  </Card>

  <Card title="Checkout Integration" icon="plug">
    Add affiliate tracking to your checkout flows with the Affonso, Dub Partners, and Rekomi integrations.
  </Card>
</CardGroup>

## Integration Options

Dodo Payments integrates with these affiliate management platforms:

* **[Affonso](https://affonso.io)**: An affiliate management platform with automated commission tracking, real-time reporting, and dedicated affiliate dashboards.
* **[Dub Partners](https://dub.co)**: Dub's link management and conversion tracking, with attribution analytics for each affiliate link.
* **[Rekomi](https://rekomi.com)**: An affiliate tracking and management platform with a one-paste Dodo Payments connection. Rekomi also pays your affiliates and handles their tax forms.

Choose the platform that fits your program, or combine several for different use cases.

## Affonso Integration

Affonso is an affiliate management platform that partners with Dodo Payments. To connect your Dodo Payments account to Affonso and start tracking affiliate-driven sales, follow these steps.

<Frame>
  <iframe className="w-full aspect-video rounded-md" src="https://www.youtube.com/embed/8tw8o9yOjsA" title="Affiliate Integration | Dodo Payments" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen />
</Frame>

<Steps>
  <Step title="Connect with Dodo Payments">
    To connect your Dodo Payments account, add a Dodo Payments API key to Affonso.

    ### How to Get Your Dodo Payments API Key

    1. Log in to the Dodo Payments dashboard.
    2. Go to **Developer → API Keys**.
    3. Click **Add API key**.
    4. Enter a name, for example "Affonso Integration".
    5. Click **Create**, then copy your API key. The dashboard shows the key only once.

    ### Add Your API Key to Affonso

    1. Open your Affonso dashboard at [affonso.io](https://affonso.io/).
    2. Go to **Program Details > Connect**.
    3. Click the **Dodo Payments** integration card.
    4. Paste your Dodo Payments API key.
    5. Click **Connect**.

    <Info>
      Affonso encrypts your API key.
    </Info>
  </Step>

  <Step title="Add Webhook to Dodo Payments">
    After you connect, Affonso gives you a unique webhook URL. Dodo Payments sends payment events to this URL, and Affonso uses them to track payments and trigger affiliate commissions.

    ### Add Webhook URL in Dodo Payments

    1. In the Dodo Payments dashboard, go to **Developer → Webhooks**.
    2. Click **Add endpoint**.
    3. Paste your Affonso webhook URL from your Affonso program settings.
    4. Click **Create endpoint**.

    ### Add Webhook Secret in Affonso

    1. In Dodo Payments, open the endpoint you created and copy its **Signing secret**.
    2. Paste it into Affonso under the Dodo Payments webhook settings.

    <Info>
      Affonso uses the signing secret to verify that incoming events come from Dodo Payments.
    </Info>
  </Step>

  <Step title="Add the Tracking Script">
    To track affiliate visits and conversions, add the Affonso pixel to your site. Replace `YOUR_PUBLIC_PROGRAM_ID` with your Affonso program ID and `YOUR_COOKIE_DURATION` with how long the referral cookie lasts.

    ```html theme={null}
    <!-- 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>
    ```

    The script:

    * Tracks affiliate visits.
    * Sets a cookie with the referral ID (`affonso_referral`) and exposes it as `window.affonso_referral`.
    * Enables signup and payment tracking.

    <Info>
      Add the script to every domain where users visit or convert, such as your marketing site and your app.
    </Info>
  </Step>

  <Step title="Track User Signups">
    To see your full funnel and improve affiliate performance, track user signups as leads.

    ```js theme={null}
    // After successful registration. userEmail is the new user's email address.
    window.Affonso.signup(userEmail);
    ```

    This call:

    * Logs a new referral as a **LEAD** if the user came through an affiliate link.
    * Shows the lead in your dashboard and in the affiliate's stats.

    <Info>
      Call it after a successful registration or after double opt-in (DOI).
    </Info>
  </Step>

  <Step title="Pass Referral Data to Dodo Payments">
    To attribute commissions correctly, pass the Affonso referral ID to Dodo Payments at checkout as `affonso_referral` metadata. Read `window.affonso_referral` in the browser, then send it to your server, where your API key is available.

    ### Payments Integration

    ```js theme={null}
    import DodoPayments from 'dodopayments';

    const client = new DodoPayments({
      bearerToken: process.env['DODO_PAYMENTS_API_KEY'],
    });

    // Note: POST /payments is deprecated — prefer checkout sessions for new
    // integrations. `metadata` is passed the same way.
    // Runs on your server. referralId is window.affonso_referral from the browser.
    async function createPayment(referralId) {
      const payment = await client.payments.create({
        payment_link: true,
        billing: { city: 'San Francisco', country: 'US', state: 'CA', street: '123 Main St', zipcode: '94102' },
        customer: { email: 'customer@example.com', name: 'John Doe' },
        product_cart: [{ product_id: 'pdt_123', quantity: 1 }],
        metadata: {
          affonso_referral: referralId,
        },
      });

      console.log(payment.payment_id);
    }
    ```

    ### Subscription Integration

    ```js theme={null}
    import DodoPayments from 'dodopayments';

    const client = new DodoPayments({
      bearerToken: process.env['DODO_PAYMENTS_API_KEY'],
    });

    // Note: POST /subscriptions is deprecated — prefer checkout sessions for new
    // integrations. `metadata` is passed the same way.
    // Runs on your server. referralId is window.affonso_referral from the browser.
    async function createSubscription(referralId) {
      const subscription = await client.subscriptions.create({
        billing: { city: 'San Francisco', country: 'US', state: 'CA', street: '123 Main St', zipcode: '94102' },
        customer: { customer_id: 'cus_123' },
        product_id: 'pdt_123',
        payment_link: true,
        return_url: 'https://example.com/success',
        quantity: 1,
        metadata: {
          affonso_referral: referralId,
        },
      });

      console.log(subscription.subscription_id);
    }
    ```

    ### Payment Links

    ```js theme={null}
    // Original Dodo Payments link
    const originalLink = 'https://checkout.dodopayments.com/buy/pdt_123';

    // Append the referral ID as metadata
    const linkWithReferral = `${originalLink}?metadata_affonso_referral=${window.affonso_referral}`;
    ```

    <Info>
      For more details, see the [Dodo Payments API documentation](https://docs.dodopayments.com/api-reference/introduction).
    </Info>
  </Step>

  <Step title="Testing Your Integration">
    Before you launch publicly, test your setup with live affiliate links and test transactions. Work through this checklist:

    1. Create an affiliate and generate a tracking link.
    2. Visit your website through the affiliate link.
    3. Check that the Affonso script loads and sets the `affonso_referral` cookie.
    4. Complete a signup (optional).
    5. Complete a payment through Dodo Payments.
    6. Confirm the tracking and attribution in your Affonso dashboard.
  </Step>
</Steps>

## Dub Partners Integration

You can also use [Dub Partners](https://dub.co) to track affiliate referrals and conversions. Dub's conversion tracking attributes sales to your affiliate links, so you can see which partners drive the most revenue.

<Info>
  For detailed setup instructions, see the [Dub integration guide](/integrations/dub). It covers how to track sale conversion events and attribute revenue to your affiliate links.
</Info>

### Quick Setup with Dub Partners

1. **Enable conversion tracking** in your Dub dashboard for affiliate links.
2. **Capture the Dub click ID** (`dub_id` cookie) when you create checkout sessions.
3. **Store the click ID** in payment metadata, along with customer information.
4. **Configure the webhook integration** to send sale data to Dub when payments succeed.

The integration tracks these events automatically:

* One-time payments
* Subscription activations
* Recurring subscription payments

<Card title="Learn More" icon="book" href="/integrations/dub">
  The complete Dub integration guide, with code examples and transformation templates.
</Card>

## Rekomi Integration

You can also use [Rekomi](https://rekomi.com) to run your affiliate program end to end. Rekomi tracks clicks and conversions, calculates commissions on the pre-tax sale amount, and pays your affiliates in 130+ countries, including their tax forms.

<Info>
  For detailed setup instructions, see the [Rekomi integration guide](/integrations/rekomi). The connection is a single pasted API key: Rekomi creates the webhook endpoint in your Dodo Payments account itself, so there is no manual webhook setup.
</Info>

### Quick Setup with Rekomi

1. **Create an API key** in your Dodo Payments dashboard under **Developer → API Keys**, with **Enable write access** turned on.
2. **Paste the key into Rekomi**, which validates it and creates the webhook endpoint automatically.
3. **Install the Rekomi tracking script** on your site so affiliate clicks are captured.
4. **Pass the referral** into checkout as `rekomi_ref` metadata, or as the `metadata_rekomi_ref` payment link parameter.

The integration tracks these events automatically:

* One-time payments
* Subscription activations and renewals
* Refunds and disputes, with automatic commission clawback

<Card title="Learn More" icon="book" href="/integrations/rekomi">
  The complete Rekomi integration guide, with code examples for checkout sessions and payment links.
</Card>

## Need Help?

If you run into issues during integration, contact the platform involved:

<CardGroup cols={2}>
  <Card title="Affonso Support" icon="headset">
    * Use the live chat on [affonso.io](https://affonso.io/).
    * Email **[support@affonso.io](mailto:support@affonso.io)**.
  </Card>

  <Card title="Dub Support" icon="headset">
    * Read the [Dub documentation](https://dub.co/docs) for conversion tracking guides.
    * Contact Dub support through the [Dub dashboard](https://app.dub.co).
  </Card>

  <Card title="Rekomi Support" icon="headset">
    * Read the [Rekomi documentation](https://rekomi.com/docs) for setup and troubleshooting guides.
    * Email **[support@rekomi.com](mailto:support@rekomi.com)**, or use the live chat in the [Rekomi dashboard](https://app.rekomi.com).
  </Card>

  <Card title="Dodo Payments Support" icon="headset">
    For questions about the Dodo Payments API, see the [API reference](/api-reference/introduction) or email **[support@dodopayments.com](mailto:support@dodopayments.com)**.
  </Card>

  <Card title="Integration Guides" icon="book">
    * [Affonso Integration](#affonso-integration) (on this page)
    * [Dub Partners Integration](/integrations/dub)
    * [Rekomi Integration](/integrations/rekomi)
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.