The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add eventQuantity support
Steven Tey7a8a0cedf138
diff --git a/apps/web/app/api/track/lead/route.ts b/apps/web/app/api/track/lead/route.tsindex 3a34a4d9ed..2f48117202 100644--- a/apps/web/app/api/track/lead/route.ts+++ b/apps/web/app/api/track/lead/route.ts@@ -25,6 +25,7 @@ export const POST = withWorkspaceEdge(const {clickId,eventName,+ eventQuantity,externalId,customerId, // deprecated (but we'll support it for backwards compatibility)customerName,@@ -106,15 +107,25 @@ export const POST = withWorkspaceEdge(});const eventId = nanoid(16);+ const leadEventPayload = {+ ...clickData,+ event_id: eventId,+ event_name: eventName,+ customer_id: customer.id,+ metadata: metadata ? JSON.stringify(metadata) : "",+ };const [_lead, link, _project] = await Promise.all([- recordLead({- ...clickData,- event_id: eventId,- event_name: eventName,- customer_id: customer.id,- metadata: metadata ? JSON.stringify(metadata) : "",- }),+ recordLead(+ eventQuantity+ ? Array(eventQuantity)+ .fill(null)+ .map(() => ({+ ...leadEventPayload,+ event_id: nanoid(16),+ }))+ : leadEventPayload,+ ),// update link leads countprismaEdge.link.update({@@ -123,7 +134,7 @@ export const POST = withWorkspaceEdge(},data: {leads: {- increment: 1,+ increment: eventQuantity ?? 1,},},include: includeTags,@@ -136,7 +147,7 @@ export const POST = withWorkspaceEdge(},data: {usage: {- increment: 1,+ increment: eventQuantity ?? 1,},},}),@@ -160,8 +171,10 @@ export const POST = withWorkspaceEdge(customerId: customer.id,type: "lead",amount: 0,- quantity: 1,- earnings: reward.amount,+ quantity: eventQuantity ?? 1,+ earnings: eventQuantity+ ? reward.amount * eventQuantity+ : reward.amount,},});}diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.tsindex a84b8e5604..113b6b84a3 100644--- a/apps/web/lib/zod/schemas/leads.ts+++ b/apps/web/lib/zod/schemas/leads.ts@@ -10,15 +10,21 @@ export const trackLeadRequestSchema = z.object({.trim().min(1, "clickId is required").describe(- "The ID of the click in th Dub. You can read this value from `dub_id` cookie.",+ "The ID of the click in Dub. You can read this value from `dub_id` cookie.",),eventName: z.string({ required_error: "eventName is required" }).trim().min(1, "eventName is required").max(255)- .describe("The name of the event to track.")+ .describe("The name of the lead event to track.").openapi({ example: "Sign up" }),+ eventQuantity: z+ .number()+ .nullish()+ .describe(+ "The numerical value associated with this lead event (e.g., number of provisioned seats in a free trial). If defined as N, the lead event will be tracked N times.",+ ),externalId: z.string().trim()diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.tsindex 2df999b924..b5853b4f00 100644--- a/apps/web/lib/zod/schemas/sales.ts+++ b/apps/web/lib/zod/schemas/sales.ts@@ -60,7 +60,7 @@ export const trackSaleRequestSchema = z.object({.nullish().default(null).describe(- "The name of the lead event that occurred before the sale (case-sensitive).",+ "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, which is the default behavior).",).openapi({ example: "Cloned template 1481267" }),});