apps/web/guides/segment-track-lead.md
Configuring Segment to track lead events when a new user signs up.
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 lead action from the list of available actions.
By default, this action is configured to send lead data to Dub when the Event Name is Sign Up.
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 lead events to Segment.
Make sure to include relevant user traits such as name, email, and clickId in the payload.
You’ll also need to ensure that the clickId field is properly mapped in your Segment Actions destination so that it’s forwarded correctly to Dub.
import { Analytics } from "@segment/analytics-node";
const segment = new Analytics({
writeKey: "<YOUR_SEGMENT_WRITE_KEY>",
});
const cookieStore = await cookies();
const clickId = cookieStore.get("dub_id")?.value;
segment.track({
userId: id,
event: "Sign Up",
context: {
traits: {
name,
email,
avatar,
clickId,
},
},
integrations: {
All: true,
},
});
Once the event is tracked, Segment will forward the lead data to Dub based on the mappings you’ve configured.