Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions apps/web/app/(ee)/api/track/lead/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export const POST = withWorkspace(
metadata,
} = trackLeadRequestSchema
.extend({
// we if clickId is undefined/nullish, we'll coerce into an empty string
clickId: z.string().trim().nullish(),
// add backwards compatibility
customerExternalId: z.string().nullish(),
externalId: z.string().nullish(),
customerId: z.string().nullish(),
customerExternalId: z.string().trim().nullish(),
externalId: z.string().trim().nullish(),
customerId: z.string().trim().nullish(),
})
.parse(body);

Expand All @@ -42,7 +44,7 @@ export const POST = withWorkspace(
}

const response = await trackLead({
clickId,
clickId: clickId ?? "",
eventName,
eventQuantity,
customerExternalId,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/lib/api/conversions/track-lead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const trackLead = async ({
},
});

// if clickId is not provided, use the existing customer's clickId if it exists
// if clickId is an empty string, use the existing customer's clickId if it exists
// otherwise, throw an error (this is for mode="deferred" lead tracking)
if (!clickId) {
if (!customer || !customer.clickId) {
Expand Down
3 changes: 1 addition & 2 deletions apps/web/lib/zod/schemas/leads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ export const trackLeadRequestSchema = z.object({
clickId: z
.string()
.trim()
.nullish()
.describe(
"The unique ID of the click that the lead conversion event is attributed to. You can read this value from `dub_id` cookie. If not provided, Dub will try to find an existing customer with the provided `customerExternalId` and use the `clickId` from the customer if found.",
"The unique ID of the click that the lead conversion event is attributed to. You can read this value from `dub_id` cookie. If an empty string is provided, Dub will try to find an existing customer with the provided `customerExternalId` and use the `clickId` from the customer if found.",
),
eventName: z
.string()
Expand Down