The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
stash
Steven Teyc9c3cb71e282
diff --git a/apps/web/app/api/track/route.ts b/apps/web/app/api/track/route.tsindex f1850b25c8..e76b3fe3ec 100644--- a/apps/web/app/api/track/route.ts+++ b/apps/web/app/api/track/route.ts@@ -10,7 +10,7 @@ export const runtime = "edge";// POST /api/track – Post a conversion eventexport const POST = withSessionEdge(async ({ req }) => {const body = conversionRequestSchema.parse(await parseRequestBody(req));- const { clickId, eventName, eventType, eventMetadata, customerId } = body;+ const { clickId, eventName, eventType, metadata, customerId } = body;waitUntil((async () => {@@ -20,13 +20,14 @@ export const POST = withSessionEdge(async ({ req }) => {return;}+ console.log(body);+await recordConversion({...clickEvent.data[0],event_name: eventName,event_type: eventType,- event_metadata: eventMetadata,+ metadata,customer_id: customerId,- timestamp: new Date(Date.now()).toISOString(),});})(),);diff --git a/apps/web/lib/zod/schemas/conversions.ts b/apps/web/lib/zod/schemas/conversions.tsindex 335732ed20..74c0372846 100644--- a/apps/web/lib/zod/schemas/conversions.ts+++ b/apps/web/lib/zod/schemas/conversions.ts@@ -40,7 +40,7 @@ export const conversionEventSchemaTB = clickEventSchemaTBz.object({event_name: z.string(),event_type: eventType,- event_metadata: z.string(), // TODO: Fix the type+ metadata: z.string(), // TODO: Fix the typecustomer_id: z.string(),}),);@@ -49,7 +49,7 @@ export const conversionRequestSchema = z.object({clickId: z.string({ required_error: "clickId is required" }),eventName: z.string().max(50).default(""),eventType,- eventMetadata: z+ metadata: z.record(z.unknown()).nullish().transform((val) => (val ? JSON.stringify(val) : "")),diff --git a/packages/tinybird/datasources/dub_conversion_events.datasource b/packages/tinybird/datasources/dub_conversion_events.datasourceindex 9fb696f888..89c361569a 100644--- a/packages/tinybird/datasources/dub_conversion_events.datasource+++ b/packages/tinybird/datasources/dub_conversion_events.datasource@@ -1,12 +1,12 @@SCHEMA >`timestamp` DateTime64(3) `json:$.timestamp`,- `link_id` String `json:$.link_id`,- `click_id` String `json:$.click_id`,`event_name` LowCardinality(String) `json:$.event_name`,`event_type` LowCardinality(String) `json:$.event_type`,`metadata` String `json:$.metadata`,- `customer_key` String `json:$.customer_key`,+ `customer_id` String `json:$.customer_id`,+ `click_id` String `json:$.click_id`,+ `link_id` String `json:$.link_id`,`country` LowCardinality(String) `json:$.country`,`city` String `json:$.city`,`region` String `json:$.region`,@@ -29,4 +29,4 @@ SCHEMA >ENGINE "MergeTree"ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"-ENGINE_SORTING_KEY "timestamp, link_id, click_id, customer_key"\ No newline at end of file+ENGINE_SORTING_KEY "timestamp, link_id, click_id"\ No newline at end of file