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.Các ví dụ dưới đây sử dụng
POST /payments, hiện đã deprecated. Tính năng này vẫn hoạt động với các integration hiện có, nhưng các integration mới nên sử dụng Checkout Sessions (POST /checkouts) — metadata được truyền theo cùng cách.Bước 2: Gửi dữ liệu giao dịch đến Dub
Cấu hình một webhook endpoint để gửi dữ liệu giao dịch đến Track API của Dub khi thanh toán thành công.1
Open the Webhook Section
Trong dashboard Dodo Payments, điều hướng đến Webhooks → + Add Endpoint và mở rộng danh sách thả xuống integrations.

2
Select Dub
Chọn integration card Dub.
3
Enter API Key
Nhập Dub API Key vào trường cấu hình.

4
Configure Transformation
Chỉnh sửa transformation code để định dạng dữ liệu thanh toán cho Track Sale API của Dub.
5
Test & Create
Kiểm tra bằng sample payload và nhấp Create để kích hoạt integration.
Ví dụ về Transformation Code
Theo dõi giao dịch cơ bản
Theo dõi các giao dịch khi thanh toán thành công:basic_sale.js
Theo dõi giao dịch Subscription
Theo dõi cả subscription ban đầu và các khoản thanh toán định kỳ:subscription_sale.js
Theo dõi giao dịch không bao gồm thuế
Chỉ gửi số tiền trước thuế đến Dub để theo dõi doanh thu chính xác:sale_without_tax.js
Theo dõi giao dịch với tên Event tùy chỉnh
Sử dụng tên event tùy chỉnh để phân loại các loại giao dịch khác nhau:custom_events.js
Phương án thay thế: Triển khai phía Client
Nếu muốn theo dõi giao dịch từ server thay vì sử dụng webhook, bạn có thể gọi trực tiếp Track API của Dub sau khi thanh toán thành công:Best Practices
- Luôn include click ID trong metadata: Nếu không có click ID, Dub không thể xác định doanh thu đến từ các link của bạn
- Sử dụng external ID nhất quán: Truyền cùng customer ID mà bạn sử dụng trong hệ thống để có analytics chính xác ở cấp độ customer
- Xử lý organic traffic phù hợp: Set
webhook.cancel = truekhi không có click ID để tránh các API call không cần thiết - Kiểm tra bằng sample payment: Xác minh integration hoạt động chính xác trước khi go live
- Theo dõi dashboard Dub: Kiểm tra để đảm bảo các giao dịch xuất hiện chính xác với attribution phù hợp
Lưu ý quan trọng
- Định dạng amount: Dub yêu cầu amount tính bằng cents (ví dụ: $10.00 = 1000)
- Currency: Sử dụng mã currency ISO 4217 (USD, EUR, GBP, v.v.)
- Free trial: Các khoản thanh toán $0 không được theo dõi là giao dịch
- Refund: Nếu cần, hãy cân nhắc theo dõi refund riêng để báo cáo doanh thu chính xác
Khắc phục sự cố
Sales not appearing in Dub
Sales not appearing in Dub
- Xác minh Dub API key chính xác và có scope
conversions.write - Kiểm tra
dub_click_idđã được capture và lưu trong payment metadata - Đảm bảo webhook transformation định dạng payload chính xác
- Xác minh webhook được trigger bởi các event
payment.succeeded - Xác nhận conversion tracking đã được bật cho các link Dub
Revenue attribution not working
Revenue attribution not working
- Xác nhận người dùng nhấp qua short link Dub trước khi checkout
- Xác minh cookie
dub_idđược set chính xác trên domain của bạn - Kiểm tra click ID khớp nhau giữa lúc tạo checkout và hoàn tất thanh toán
- Đảm bảo bạn capture click ID trước khi tạo checkout session
Transformation errors
Transformation errors
- Xác thực cấu trúc JSON khớp với format của Track Sale API của Dub
- Kiểm tra tất cả các field bắt buộc (
clickId,externalId,amount) đều có mặt - Đảm bảo amount tính bằng cents (integer, không phải decimal)
- Xác minh URL API endpoint chính xác:
https://api.dub.co/track/sale - Kiểm tra transformation bằng sample webhook payload
Duplicate sales being tracked
Duplicate sales being tracked
- Đảm bảo bạn chỉ theo dõi các event
payment.succeeded, không phảipayment.processing - Sử dụng các giá trị
invoiceIdduy nhất cho mỗi giao dịch - Đối với subscription, thêm timestamp hoặc billing period để ngăn trùng lặp khi gia hạn
Tài nguyên bổ sung
Dub Conversions Documentation
Tìm hiểu thêm về các tính năng conversion tracking và analytics của Dub.
Dub Track Sale API
Xem tài liệu tham chiếu API đầy đủ cho Track Sale endpoint của Dub.
Dub Dashboard
Truy cập dashboard Dub để xem conversion analytics và dữ liệu attribution.
Webhook Events Guide
Tìm hiểu về tất cả webhook event hiện có của Dodo Payments.
Cần trợ giúp? Liên hệ bộ phận hỗ trợ của Dodo Payments qua support@dodopayments.com để được hỗ trợ về integration.