The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add noop response to /track/lead (instead of error)
Steven Teyf727540d4bd3
diff --git a/apps/web/lib/api/conversions/track-lead.ts b/apps/web/lib/api/conversions/track-lead.tsindex f408c62e7c..fe15d151a2 100644--- a/apps/web/lib/api/conversions/track-lead.ts+++ b/apps/web/lib/api/conversions/track-lead.ts@@ -53,10 +53,9 @@ export const trackLead = async ({// otherwise, throw an error (this is for mode="deferred" lead tracking)if (!clickId) {if (!customer || !customer.clickId) {- throw new DubApiError({- code: "bad_request",- message:- "The `clickId` property was not provided in the request, and no existing customer with the provided `customerExternalId` was found.",+ return trackLeadResponseSchema.parse({+ click: null,+ customer: null,});}diff --git a/apps/web/lib/api/conversions/track-sale.ts b/apps/web/lib/api/conversions/track-sale.tsindex 702e638d9c..a37ea4242e 100644--- a/apps/web/lib/api/conversions/track-sale.ts+++ b/apps/web/lib/api/conversions/track-sale.ts@@ -123,7 +123,7 @@ export const trackSale = async ({}}- // No existing customer is found, find the click event and create a new customer (for sale tracking without a pre-existing lead event)+ // No existing customer is found, find the click event and create a new customer (for direct sale tracking)else {if (!clickId) {waitUntil(@@ -131,7 +131,7 @@ export const trackSale = async ({workspace_id: workspace.id,path: "/track/sale",body: JSON.stringify(rawBody),- error: `No existing customer with the provided customerExternalId (${customerExternalId}) was found, and there was no clickId provided for sale tracking without a pre-existing lead event.`,+ error: `No existing customer with the provided customerExternalId (${customerExternalId}) was found, and there was no clickId provided for direct sale tracking.`,}),);diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.tsindex 0d8d9f9ffd..1e836f3564 100644--- a/apps/web/lib/zod/schemas/leads.ts+++ b/apps/web/lib/zod/schemas/leads.ts@@ -73,15 +73,19 @@ export const trackLeadRequestSchema = z.object({});export const trackLeadResponseSchema = z.object({- click: z.object({- id: z.string(),- }),- customer: z.object({- name: z.string().nullable(),- email: z.string().nullable(),- avatar: z.string().nullable(),- externalId: z.string().nullable(),- }),+ click: z+ .object({+ id: z.string(),+ })+ .nullable(),+ customer: z+ .object({+ name: z.string().nullable(),+ email: z.string().nullable(),+ avatar: z.string().nullable(),+ externalId: z.string().nullable(),+ })+ .nullable(),});export const leadEventSchemaTB = clickEventSchemaTBdiff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.tsindex f6403e0fde..863f9a8113 100644--- a/apps/web/lib/zod/schemas/sales.ts+++ b/apps/web/lib/zod/schemas/sales.ts@@ -57,13 +57,13 @@ export const trackSaleRequestSchema = z.object({.describe("Additional metadata to be stored with the sale event. Max 10,000 characters when stringified.",),- // advanced fields: leadEventName + fields for sale tracking without a pre-existing lead event+ // advanced fields: leadEventName + fields for sale tracking without a lead eventleadEventName: z.string().nullish().default(null).describe(- "The name of the lead event that occurred before the sale (case-sensitive). This is used to associate the sale event with a particular lead event (instead of the latest lead event for a link-customer combination, which is the default behavior). For sale tracking without a pre-existing lead event, this field can also be used to specify the lead event name.",+ "The name of the lead event that occurred before the sale (case-sensitive). This is used to associate the sale event with a particular lead event (instead of the latest lead event for a link-customer combination, which is the default behavior). For direct sale tracking, this field can also be used to specify the lead event name.",).openapi({ example: "Cloned template 1481267" }),clickId: z@@ -71,7 +71,7 @@ export const trackSaleRequestSchema = z.object({.trim().nullish().describe(- "[For sale tracking without a pre-existing lead event]: The unique ID of the click that the sale conversion event is attributed to. You can read this value from `dub_id` cookie.",+ "[For direct sale tracking]: The unique ID of the click that the sale conversion event is attributed to. You can read this value from `dub_id` cookie.",),customerName: z.string()@@ -79,7 +79,7 @@ export const trackSaleRequestSchema = z.object({.nullish().default(null).describe(- "[For sale tracking without a pre-existing lead event]: The name of the customer. If not passed, a random name will be generated (e.g. “Big Red Caribou”).",+ "[For direct sale tracking]: The name of the customer. If not passed, a random name will be generated (e.g. “Big Red Caribou”).",),customerEmail: z.string()@@ -87,16 +87,12 @@ export const trackSaleRequestSchema = z.object({.max(100).nullish().default(null)- .describe(- "[For sale tracking without a pre-existing lead event]: The email address of the customer.",- ),+ .describe("[For direct sale tracking]: The email address of the customer."),customerAvatar: z.string().nullish().default(null)- .describe(- "[For sale tracking without a pre-existing lead event]: The avatar URL of the customer.",- ),+ .describe("[For direct sale tracking]: The avatar URL of the customer."),});export const trackSaleResponseSchema = z.object({diff --git a/apps/web/tests/tracks/track-sale.test.ts b/apps/web/tests/tracks/track-sale.test.tsindex db75d28d72..3873cfacf4 100644--- a/apps/web/tests/tracks/track-sale.test.ts+++ b/apps/web/tests/tracks/track-sale.test.ts@@ -227,7 +227,7 @@ describe("POST /track/sale", async () => {expect(response.data.sale?.amount).toBeLessThanOrEqual(1100); // 1100 cents});- test("track a sale without a pre-existing lead event", async () => {+ test("track a sale with direct sale tracking", async () => {const clickResponse = await http.post<{ clickId: string }>({path: "/track/click",headers: E2E_TRACK_CLICK_HEADERS,