apps/web/guides/segment-track-sale.md
Configuring Segment to track sale events when a user purchases your product or service.
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.
Head to Segment Dub (Actions) and add the destination to your Segment workspace.
In the Dub (Actions) destination settings, fill out the following fields:
Once completed, click Save Changes.
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.
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.
import { Analytics } from "@segment/analytics-node";
const segment = new Analytics({
writeKey: "<YOUR_SEGMENT_WRITE_KEY>",
});
segment.track({
userId: id,
event: "Order Completed",
properties: {
payment_processor: "stripe",
order_id: "ORD_123",
currency: "USD",
revenue: 1000,
},
integrations: {
All: true,
},
});
Once the event is tracked, Segment will forward the sale data to Dub based on the mappings you’ve configured.