The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix events SDK
Steven Tey1aaae6ed476a
diff --git a/apps/web/app/api/customers/[id]/activity/route.ts b/apps/web/app/api/customers/[id]/activity/route.tsindex 3fc3b2c422..576c819be4 100644--- a/apps/web/app/api/customers/[id]/activity/route.ts+++ b/apps/web/app/api/customers/[id]/activity/route.ts@@ -17,6 +17,7 @@ export const GET = withWorkspace(async ({ workspace, params }) => {const events = await getCustomerEvents({customerId: customer.id,+ includeMetadata: true,});// get the first partner link that this customer interacted withdiff --git a/apps/web/app/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/customers/[customerId]/route.tsindex c141d63da4..0dfd98e3a4 100644--- a/apps/web/app/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts+++ b/apps/web/app/api/partner-profile/programs/[programId]/customers/[customerId]/route.ts@@ -33,7 +33,6 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {const events = await getCustomerEvents({customerId: customer.id,linkIds: links.map((link) => link.id),- hideMetadata: true, // don't expose metadata to partners});if (events.length === 0) {diff --git a/apps/web/lib/analytics/get-customer-events.ts b/apps/web/lib/analytics/get-customer-events.tsindex e96ab21aa2..80b942a261 100644--- a/apps/web/lib/analytics/get-customer-events.ts+++ b/apps/web/lib/analytics/get-customer-events.ts@@ -8,17 +8,23 @@ import {clickEventResponseSchema,clickEventSchema,} from "../zod/schemas/clicks";-import { leadEventResponseSchema } from "../zod/schemas/leads";-import { saleEventResponseSchema } from "../zod/schemas/sales";+import {+ leadEventResponseSchema,+ leadEventResponseSchemaExtended,+} from "../zod/schemas/leads";+import {+ saleEventResponseSchema,+ saleEventResponseSchemaExtended,+} from "../zod/schemas/sales";export const getCustomerEvents = async ({customerId,linkIds,- hideMetadata = false,+ includeMetadata,}: {customerId: string;linkIds?: string[];- hideMetadata?: boolean;+ includeMetadata?: boolean;}) => {const pipe = tb.buildPipe({pipe: "v2_customer_events",@@ -62,7 +68,6 @@ export const getCustomerEvents = async ({? {eventId: evt.event_id,eventName: evt.event_name,- metadata: hideMetadata ? null : evt.metadata,...(evt.event === "sale"? {sale: {@@ -78,8 +83,14 @@ export const getCustomerEvents = async ({return {click: clickEventResponseSchema,- lead: leadEventResponseSchema.omit({ customer: true }),- sale: saleEventResponseSchema.omit({ customer: true }),+ lead: (includeMetadata+ ? leadEventResponseSchemaExtended+ : leadEventResponseSchema+ ).omit({ customer: true }),+ sale: (includeMetadata+ ? saleEventResponseSchemaExtended+ : saleEventResponseSchema+ ).omit({ customer: true }),}[evt.event].parse(eventData);}).filter((d) => d !== null);diff --git a/apps/web/lib/zod/schemas/clicks.ts b/apps/web/lib/zod/schemas/clicks.tsindex 0bcf4bf84f..28c97c71ee 100644--- a/apps/web/lib/zod/schemas/clicks.ts+++ b/apps/web/lib/zod/schemas/clicks.ts@@ -77,4 +77,4 @@ export const clickEventResponseSchema = zlink: linkEventSchema,}).merge(commonDeprecatedEventFields)- .openapi({ ref: "ClickEvent" });+ .openapi({ ref: "ClickEvent", title: "ClickEvent" });diff --git a/apps/web/lib/zod/schemas/customer-activity.ts b/apps/web/lib/zod/schemas/customer-activity.tsindex 9bceb6862e..bb737e0829 100644--- a/apps/web/lib/zod/schemas/customer-activity.ts+++ b/apps/web/lib/zod/schemas/customer-activity.ts@@ -1,20 +1,11 @@import { z } from "zod";-import { clickEventResponseSchema } from "./clicks";-import { leadEventResponseSchema } from "./leads";import { LinkSchema } from "./links";-import { saleEventResponseSchema } from "./sales";--export const customerActivityEventSchema = z.discriminatedUnion("event", [- clickEventResponseSchema,- leadEventResponseSchema.omit({ customer: true }),- saleEventResponseSchema.omit({ customer: true }),-]);export const customerActivityResponseSchema = z.object({ltv: z.number(),timeToLead: z.number().nullable(),timeToSale: z.number().nullable(),- events: z.array(customerActivityEventSchema),+ events: z.array(z.any()), // we've already parsed the events in get-customer-events.tslink: LinkSchema.pick({id: true,domain: true,diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.tsindex c972c83661..afadbee257 100644--- a/apps/web/lib/zod/schemas/leads.ts+++ b/apps/web/lib/zod/schemas/leads.ts@@ -127,16 +127,21 @@ export const leadEventResponseSchema = ztimestamp: z.coerce.string(),eventId: z.string(),eventName: z.string(),- metadata: z- .string()- .nullish()- .transform((val) => (val === "" ? null : val))- .default(null)- .openapi({ type: "string" }),// nested objectsclick: clickEventSchema,link: linkEventSchema,customer: CustomerSchema,}).merge(commonDeprecatedEventFields)- .openapi({ ref: "LeadEvent" });+ .openapi({ ref: "LeadEvent", title: "LeadEvent" });++export const leadEventResponseSchemaExtended = leadEventResponseSchema.merge(+ z.object({+ metadata: z+ .string()+ .nullish()+ .transform((val) => (val === "" ? null : val))+ .default(null)+ .openapi({ type: "string" }),+ }),+);diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.tsindex c7dea11efa..9695569932 100644--- a/apps/web/lib/zod/schemas/sales.ts+++ b/apps/web/lib/zod/schemas/sales.ts@@ -152,12 +152,17 @@ export const saleEventResponseSchema = zpayment_processor: z.string().describe("Deprecated. Use `sale.paymentProcessor` instead."),+ })+ .merge(commonDeprecatedEventFields)+ .openapi({ ref: "SaleEvent", title: "SaleEvent" });++export const saleEventResponseSchemaExtended = saleEventResponseSchema.merge(+ z.object({metadata: z.string().nullish().transform((val) => (val === "" ? null : val)).default(null).openapi({ type: "string" }),- })- .merge(commonDeprecatedEventFields)- .openapi({ ref: "SaleEvent" });+ }),+);