Introduction
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.
How It Works
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_idcookie 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
Prerequisites
Before setting up this integration, ensure you have:- A Dub account with a workspace
- Conversion tracking enabled for your links
- Your Dub API key (available in your Dub dashboard under Settings → API Keys)
Getting Started
1
Enable Conversion Tracking in Dub
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.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.
Implementation Guide
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.Step 2: Send Sale Data to Dub
Configure a webhook endpoint to send sale data to Dub’s Track API when payments succeed.1
Open the Webhook Section
In your Dodo Payments dashboard, navigate to Webhooks → + Add Endpoint and expand the integrations dropdown.

2
Select Dub
Choose the Dub integration card.
3
Enter API Key
Provide your Dub API Key in the configuration field.

4
Configure Transformation
Edit the transformation code to format payment data for Dub’s Track Sale API.
5
Test & Create
Test with sample payloads and click Create to activate the integration.
Transformation Code Examples
Basic Sale Tracking
Track sales when payments succeed:basic_sale.js
Track Subscription Sales
Track both initial subscriptions and recurring payments:subscription_sale.js
Track Sales with Tax Exclusion
Send only the pre-tax amount to Dub for accurate revenue tracking:sale_without_tax.js
Track Sales with Custom Event Names
Use custom event names to categorize different types of sales:custom_events.js
Alternative: Client-Side Implementation
If you prefer to track sales from your server instead of using webhooks, you can call Dub’s Track API directly after a successful payment:Best Practices
- 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 = truewhen 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
Important Notes
- Amount format: Dub expects amounts in cents (e.g., $10.00 = 1000)
- Currency: Use ISO 4217 currency codes (USD, EUR, GBP, etc.)
- Free trials: $0 payments are not tracked as sales
- Refunds: Consider tracking refunds separately if needed for accurate revenue reporting
Troubleshooting
Sales not appearing in Dub
Sales not appearing in Dub
- Verify your Dub API key is correct and has
conversions.writescope - Check that the
dub_click_idis being captured and stored in payment metadata - Ensure the webhook transformation is correctly formatting the payload
- Verify the webhook is triggering on
payment.succeededevents - Confirm conversion tracking is enabled for your Dub links
Revenue attribution not working
Revenue attribution not working
- Confirm users are clicking through your Dub short links before checkout
- Verify the
dub_idcookie is being set correctly on your domain - Check that click IDs match between checkout creation and payment completion
- Ensure you’re capturing the click ID before creating the checkout session
Transformation errors
Transformation errors
- Validate the JSON structure matches Dub’s Track Sale API format
- Check that all required fields (
clickId,externalId,amount) are present - Ensure amount is in cents (integer, not decimal)
- Verify the API endpoint URL is correct:
https://api.dub.co/track/sale - Test the transformation with sample webhook payloads
Duplicate sales being tracked
Duplicate sales being tracked
- Ensure you’re only tracking on
payment.succeededevents, notpayment.processing - Use unique
invoiceIdvalues for each sale - For subscriptions, append timestamps or billing period to prevent duplicates on renewals
Additional Resources
Dub Conversions Documentation
Learn more about Dub’s conversion tracking and analytics features.
Dub Track Sale API
View the complete API reference for Dub’s Track Sale endpoint.
Dub Dashboard
Access your Dub dashboard to view conversion analytics and attribution data.
Webhook Events Guide
Learn about all available Dodo Payments webhook events.
Need help? Contact Dodo Payments support at [email protected] for assistance with the integration.