Skip to main content

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.
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.

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:
  1. Capture Dub’s click ID from the dub_id cookie when creating checkout sessions
  2. Store the click ID in your payment metadata along with the customer’s external ID
  3. 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.

Prerequisites

Before setting up this integration, ensure you have:
  1. A Dub account with a workspace
  2. Conversion tracking enabled for your links
  3. 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.
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.

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.
Add Endpoint and integrations dropdown
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.
Add API Key
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

Thu thập click ID sớm: Lưu Dub click ID sớm nhất có thể trong quy trình checkout để đảm bảo attribution chính xác, ngay cả khi người dùng rời đi và quay lại sau.
  • 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 = true khi 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ố

  • 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
  • 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
  • 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
  • Đảm bảo bạn chỉ theo dõi các event payment.succeeded, không phải payment.processing
  • Sử dụng các giá trị invoiceId duy 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.
Lần sửa đổi cuối 6 tháng 8, 2026