Segment
Learn how to track sales conversion events with Segment and Dub
Conversion tracking require a Business plan subscription or higher.
When it comes to conversion tracking, a sale
event happens when a user purchases your product or service.
In this guide, we will be focusing on tracking sales conversion events for a SaaS application that uses Segment to collect customer data.
Prerequisites
Before you get started, make sure you follow the Dub Conversions quickstart guide to get Dub Conversions set up for your links:
If you’ve already set up the Dub (Actions) destination, you can skip the first two steps and jump straight to the Add Mapping section.
Configure Segment Action
Next, configure Segment Dub (Actions) to track sales conversion events.
Add Dub (Actions) destination
Head to Segment Dub (Actions) and add the destination to your Segment workspace.
Configure Dub API Key
In the Dub (Actions) destination settings, fill out the following fields:
- Name: Enter a name to help you identify this destination in Segment.
- API Key: Enter your Dub API key. You can find this in the Dub Dashboard.
- Enable Destination: Toggle this on to allow Segment to send data to Dub.
Once completed, click Save Changes.
Add Mapping
Next, you’ll choose the Track a sale action from the list of available actions.
By default, this action is configured to send sale data to Dub when the Event Name is Order Completed.
Below the selected action, you’ll see the mapping for that action.
You can customize the trigger and mapping to fit the specific needs of your application.
Finally, click Next and then Save and enable to add the mapping to the destination.
Send sale events to Dub
On the server side, you’ll use the @segment/analytics-node
SDK to send sale events to Segment.
Make sure to include relevant properties such as userId
, payment_processor
, order_id
, currency
, and revenue
in the payload.
Once the event is tracked, Segment will forward the sale data to Dub based on the mappings you’ve configured.
Here are the properties you can include when sending a sale event:
Property | Required | Description |
---|---|---|
externalId | Yes | The unique ID of the customer in your system. Will be used to identify and attribute all future events to this customer. |
amount | Yes | The amount of the sale in cents. |
paymentProcessor | Yes | The payment processor that processed the sale. (E.g. Stripe, Shopify) |
eventName | No | The name of the event. Defaults to “Purchase”. |
invoiceId | No | The invoice ID of the sale. Can be used as a idempotency key – only one sale event can be recorded for a given invoice ID. |
currency | No | The currency of the sale. Defaults to “usd”. |
metadata | No | An object containing additional information about the sale. |
Example App
To learn more about how to track sales with Segment, check out the following example app:
Segment + Next.js App Router Example
Next.js app using Segment to track sales.
- Time-series: A time-series view of the number clicks, leads and sales.
- Funnel chart: A funnel chart view visualizing the conversion & dropoff rates across the different steps in the conversion funnel (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.