Dub is a powerful link management platform that helps you create, share, and track short links. By integrating Dodo Payments with Dub, you can automatically track sale conversion events when customers complete purchases, enabling you to measure the ROI of your marketing campaigns and referral programs.A “sale” event is recorded in Dub when a customer:
Completes a one-time payment
Subscribes to a paid plan
Makes a recurring subscription payment
This integration requires a Dub account with conversion tracking enabled on your links.
Affiliate Program Integration: This integration also works seamlessly with Dub Partners for tracking affiliate referrals and commissions. Use Dub’s conversion tracking to attribute sales to your affiliate links and measure partner performance. Learn more about setting up affiliate programs in our Affiliates feature guide.
Dub tracks visitors through a unique click ID (dub_id) stored in a cookie when users click your Dub short links. To attribute sales to your links, you need to:
Capture Dub’s click ID from the dub_id cookie when creating checkout sessions
Store the click ID in your payment metadata along with the customer’s external ID
Send sale data to Dub when payments succeed using their Track API
This allows Dub to match successful sales with the original link click, giving you complete conversion attribution.
In your Dub dashboard, enable conversion tracking for the links you want to track sales for. This allows Dub to record sale events when customers complete purchases.
Learn more about enabling conversion tracking in the Dub documentation.
2
Get Your Dub API Key
Navigate to your Dub dashboard → Settings → API Keys and create a new API key with conversions.write scope.
Keep your API key secure and never expose it in client-side code.
3
Capture Click ID in Checkout
When creating a checkout session, capture the Dub click ID from the cookie and add it to your payment metadata.
4
Send Sale Data via Webhook
Configure a webhook to send sale data to Dub’s Track API when payments succeed.
5
Done!
Sale conversion events will now appear in your Dub analytics dashboard with full attribution to your links.
Step 1: Add Click ID and Customer ID to Checkout Metadata
When creating a checkout session, capture the Dub click ID from the cookie and include it in your payment metadata along with your customer’s external ID.
import { cookies } from 'next/headers';import DodoPayments from 'dodopayments';const client = new DodoPayments();export async function createCheckout(productId: string, customerId: string) { // Capture Dub click ID from cookie const dubClickId = cookies().get('dub_id')?.value; const payment = await client.payments.create({ billing: { city: 'New York', country: 'US', state: 'NY', street: '123 Main St', zipcode: '10001', }, customer: { email: 'customer@example.com', name: 'John Doe', }, product_cart: [{ product_id: productId, quantity: 1 }], metadata: { dub_click_id: dubClickId, // Store Dub click ID dub_external_id: customerId, // Store your customer's unique ID }, }); return payment;}
const express = require('express');const DodoPayments = require('dodopayments').default;const router = express.Router();const client = new DodoPayments();router.post('/create-checkout', async (req, res) => { // Capture Dub click ID from cookie const dubClickId = req.cookies?.dub_id; const payment = await client.payments.create({ billing: { city: 'New York', country: 'US', state: 'NY', street: '123 Main St', zipcode: '10001', }, customer: { email: req.body.email, name: req.body.name, }, product_cart: [{ product_id: req.body.productId, quantity: 1 }], metadata: { dub_click_id: dubClickId, // Store Dub click ID dub_external_id: req.body.customerId, // Store your customer's unique ID }, }); res.json({ payment });});
from fastapi import FastAPI, Requestfrom dodopayments import DodoPaymentsapp = FastAPI()client = DodoPayments()@app.post("/create-checkout")async def create_checkout(request: Request): # Capture Dub click ID from cookie dub_click_id = request.cookies.get("dub_id") body = await request.json() payment = client.payments.create( billing={ "city": "New York", "country": "US", "state": "NY", "street": "123 Main St", "zipcode": "10001", }, customer={ "email": body["email"], "name": body["name"], }, product_cart=[{"product_id": body["product_id"], "quantity": 1}], metadata={ "dub_click_id": dub_click_id, # Store Dub click ID "dub_external_id": body["customer_id"], # Store your customer's unique ID }, ) return {"payment": payment}
Capture the click ID early: Store the Dub click ID as soon as possible in your checkout flow to ensure accurate attribution, even if the user navigates away and returns later.
Always include click ID in metadata: Without the click ID, Dub cannot attribute revenue to your links
Use external IDs consistently: Pass the same customer ID you use in your system for accurate customer-level analytics
Handle organic traffic gracefully: Set webhook.cancel = true when there’s no click ID to avoid unnecessary API calls
Test with sample payments: Verify the integration works correctly before going live
Monitor your Dub dashboard: Check that sales are appearing correctly with proper attribution