The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Make clickId required in SDK
Steven Tey3fdcd406c7ea
diff --git a/apps/web/app/(ee)/api/track/lead/route.ts b/apps/web/app/(ee)/api/track/lead/route.tsindex bdd3f7eccf..8919035b18 100644--- a/apps/web/app/(ee)/api/track/lead/route.ts+++ b/apps/web/app/(ee)/api/track/lead/route.ts@@ -25,6 +25,8 @@ export const POST = withWorkspace(metadata,} = trackLeadRequestSchema.extend({+ // we if clickId is undefined/nullish, we'll coerce into an empty string+ clickId: z.string().nullish(),// add backwards compatibilitycustomerExternalId: z.string().nullish(),externalId: z.string().nullish(),@@ -42,7 +44,7 @@ export const POST = withWorkspace(}const response = await trackLead({- clickId,+ clickId: clickId ?? "",eventName,eventQuantity,customerExternalId,diff --git a/apps/web/lib/api/conversions/track-lead.ts b/apps/web/lib/api/conversions/track-lead.tsindex 13a63dc0c7..f408c62e7c 100644--- a/apps/web/lib/api/conversions/track-lead.ts+++ b/apps/web/lib/api/conversions/track-lead.ts@@ -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) {diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.tsindex 7eeb73be3d..0d8d9f9ffd 100644--- a/apps/web/lib/zod/schemas/leads.ts+++ b/apps/web/lib/zod/schemas/leads.ts@@ -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()