Skip to main content
Conversion tracking requires a Business plan subscription or higher.
When it comes to conversion tracking, a sale event happens when a user purchases your product or service. Examples include:
  • Subscribing to a paid plan
  • Usage expansion (upgrading from one plan to another)
  • Purchasing a product from your online store
A diagram showing how lead events are tracked in the conversion funnel
In this guide, we will be focusing on tracking sales conversion events with Dub.

Prerequisites

First, you’ll need to enable conversion tracking for your Dub links to be able to start tracking conversions:
If you’re using Dub Partners, you can skip this step since partner links will have conversion tracking enabled by default.
To enable conversion tracking for all future links in a workspace, you can do the following: To enable conversion tracking for all future links in a workspace, you can do the following:
  1. Navigate to your workspace’s Analytics settings page.
  2. Toggle the Workspace-level Conversion Tracking switch to enable conversion tracking for the workspace.
Enabling conversion tracking for a workspace
This option will enable conversion tracking in the Dub Link Builder for all future links.
Alternatively, you can also enable conversion tracking programmatically via the Dub API. All you need to do is pass trackConversion: true when creating or updating a link:
const link = await dub.links.create({
  url: "https://dub.co",
  trackConversion: true,
});
Then, you’d want to install the @dub/analytics script to your website to track conversion events. You can install the @dub/analytics script in several different ways:
You can verify the installation with the following tests:
  1. Open the browser console and type in _dubAnalytics – if the script is installed correctly, you should see the _dubAnalytics object in the console.
  2. Add the ?dub_id=test query parameter to your website URL and make sure that the dub_id cookie is being set in your browser.
If both of these checks pass, the script is installed correctly. Otherwise, please make sure:
  • The analytics script was added to the <head> section of the page
  • If you’re using a content delivery network (CDN), make sure to purge any cached content

Step 1: Configure sale tracking

Next, depending on which payment processor you’re using, you can leverage our native integrations to track sale events: If you’re not using any of the providers listed above, you can also manually track sale events using our native SDKs within your backend code:
import { Dub } from "dub";

const dub = new Dub();

await dub.track.sale({
  customerExternalId: "cus_RBfbD57HDzPKpduI8elr5qHA",
  amount: 100,
  paymentProcessor: "stripe",
  eventName: "E-book purchase",
  invoiceId: "123456",
  currency: "usd",
});
Here are the properties you can include when sending a sale event:
PropertyRequiredDescription
customerExternalIdYesThe unique ID of the customer in your system. Will be used to identify and attribute all future events to this customer.
amountYesThe amount of the sale in cents.
paymentProcessorNoThe payment processor that processed the sale (e.g. Stripe, Shopify). Defaults to “custom”.
eventNameNoThe name of the event. Defaults to “Purchase”.
invoiceIdNoThe invoice ID of the sale. Can be used as a idempotency key – only one sale event can be recorded for a given invoice ID.
currencyNoThe currency of the sale. Defaults to “usd”.
metadataNoAn object containing additional information about the sale.

Step 2: View conversion results

And that’s it – you’re all set! You can now sit back, relax, and watch your conversion revenue grow. We provide 3 different views to help you understand your conversions:
Time-series line chart
  • Funnel chart: A funnel chart view visualizing the conversion & dropoff rates across the different steps in the conversion funnel (clicks → leads → sales).
Funnel chart view showing the conversion & dropoff rates from clicks → leads → sales
  • Real-time events stream: A real-time events stream of every single conversion event that occurs across all your links in your workspace.
The Events Stream dashboard on Dub

Currency conversion support

For simplicity, Dub records all sales in the default currency of your Dub workspace. This means that if you pass a different currency, it will be automatically converted to USD for reporting consistency – using the latest foreign exchange rates.
TypScript
await dub.track.sale({
  customerExternalId: "cus_RBfbD57HDzPKpduI8elr5qHA",
  amount: 15480, // this will be converted from PLN to USD
  currency: "pln",
  paymentProcessor: "stripe",
  eventName: "Purchase",
});
The default currency for all Dub workspaces is currently set to USD. We will add the ability to customize that in the future.
I