The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix get-analytics + other updates
Steven Tey01408e928ef7
diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.tsindex f06bc59502..39d3d75767 100644--- a/apps/web/lib/analytics/get-analytics.ts+++ b/apps/web/lib/analytics/get-analytics.ts@@ -116,8 +116,12 @@ export const getAnalytics = async (params: AnalyticsFilters) => {},});- return links.map((link) =>- analyticsResponse[groupBy].parse({+ return topLinksData.map((topLink) => {+ const link = links.find((l) => l.id === topLink.link);+ if (!link) {+ return null;+ }+ return analyticsResponse[groupBy].parse({id: link.id,domain: link.domain,key: link.key,@@ -126,11 +130,10 @@ export const getAnalytics = async (params: AnalyticsFilters) => {domain: link.domain,key: link.key,}),- link: link.id,createdAt: link.createdAt.toISOString(),- ...topLinksData.find((l) => l.link === link.id),- }),- );+ ...topLink,+ });+ });}// Return array for other endpointsdiff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.tsindex 20a35009cb..fde27e5788 100644--- a/apps/web/lib/analytics/get-events.ts+++ b/apps/web/lib/analytics/get-events.ts@@ -39,7 +39,7 @@ export const getEvents = async (params: EventsFilters) => {}const pipe = (isDemo ? tbDemo : tb).buildPipe({- pipe: "v2_events",+ pipe: "v1_events",parameters: eventsFilterTB,data:{diff --git a/apps/web/lib/zod/schemas/analytics-response.ts b/apps/web/lib/zod/schemas/analytics-response.tsindex baeb6492f2..9e3e95de33 100644--- a/apps/web/lib/zod/schemas/analytics-response.ts+++ b/apps/web/lib/zod/schemas/analytics-response.ts@@ -7,7 +7,10 @@ export const analyticsResponse = {clicks: z.number().describe("The total number of clicks").default(0),leads: z.number().describe("The total number of leads").default(0),sales: z.number().describe("The total number of sales").default(0),- saleAmount: z.number().describe("The total amount of sales").default(0),+ saleAmount: z+ .number()+ .describe("The total amount of sales, in cents")+ .default(0),}).openapi({ ref: "AnalyticsCount", title: "AnalyticsCount" }),timeseries: z@@ -27,7 +30,7 @@ export const analyticsResponse = {.default(0),saleAmount: z.number()- .describe("The total amount of sales in the interval")+ .describe("The total amount of sales in the interval, in cents").default(0),}).openapi({ ref: "AnalyticsTimeseries" }),@@ -53,7 +56,7 @@ export const analyticsResponse = {.default(0),saleAmount: z.number()- .describe("The total amount of sales from this continent")+ .describe("The total amount of sales from this continent, in cents").default(0),}).openapi({ ref: "AnalyticsContinents" }),@@ -80,7 +83,7 @@ export const analyticsResponse = {.default(0),saleAmount: z.number()- .describe("The total amount of sales from this country")+ .describe("The total amount of sales from this country, in cents").default(0),}).openapi({ ref: "AnalyticsCountries" }),@@ -105,7 +108,7 @@ export const analyticsResponse = {.default(0),saleAmount: z.number()- .describe("The total amount of sales from this city")+ .describe("The total amount of sales from this city, in cents").default(0),}).openapi({ ref: "AnalyticsCities" }),@@ -127,7 +130,7 @@ export const analyticsResponse = {.default(0),saleAmount: z.number()- .describe("The total amount of sales from this device")+ .describe("The total amount of sales from this device, in cents").default(0),}).openapi({ ref: "AnalyticsDevices" }),@@ -149,7 +152,7 @@ export const analyticsResponse = {.default(0),saleAmount: z.number()- .describe("The total amount of sales from this browser")+ .describe("The total amount of sales from this browser, in cents").default(0),}).openapi({ ref: "AnalyticsBrowsers" }),@@ -165,7 +168,7 @@ export const analyticsResponse = {sales: z.number().describe("The number of sales from this OS").default(0),saleAmount: z.number()- .describe("The total amount of sales from this OS")+ .describe("The total amount of sales from this OS, in cents").default(0),}).openapi({ ref: "AnalyticsOS" }),@@ -191,7 +194,7 @@ export const analyticsResponse = {.default(0),saleAmount: z.number()- .describe("The total amount of sales from this referer")+ .describe("The total amount of sales from this referer, in cents").default(0),}).openapi({ ref: "AnalyticsReferers" }),@@ -224,7 +227,7 @@ export const analyticsResponse = {.default(0),saleAmount: z.number()- .describe("The total amount of sales from this link")+ .describe("The total amount of sales from this link, in cents").default(0),}).openapi({ ref: "AnalyticsTopLinks" }),@@ -246,7 +249,7 @@ export const analyticsResponse = {.default(0),saleAmount: z.number()- .describe("The total amount of sales from this URL")+ .describe("The total amount of sales from this URL, in cents").default(0),}).openapi({ ref: "AnalyticsTopUrls" }),@@ -258,19 +261,21 @@ export const analyticsResponse = {.describe("The type of trigger method: link click or QR scan"),clicks: z.number()- .describe("The number of clicks from this trigger method.")+ .describe("The number of clicks from this trigger method").default(0),leads: z.number()- .describe("The number of leads from this trigger method.")+ .describe("The number of leads from this trigger method").default(0),sales: z.number()- .describe("The number of sales from this trigger method.")+ .describe("The number of sales from this trigger method").default(0),saleAmount: z.number()- .describe("The total amount of sales from this trigger method.")+ .describe(+ "The total amount of sales from this trigger method, in cents",+ ).default(0),}).openapi({ ref: "AnalyticsTrigger" }),