The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix export route and use v2_events
Steven Teyadffb52f7541
diff --git a/apps/web/app/api/events/export/route.ts b/apps/web/app/api/events/export/route.tsindex d2c2480c09..e2dea2c0ef 100644--- a/apps/web/app/api/events/export/route.ts+++ b/apps/web/app/api/events/export/route.ts@@ -5,15 +5,15 @@ import { getLinkOrThrow } from "@/lib/api/links/get-link-or-throw";import { throwIfClicksUsageExceeded } from "@/lib/api/links/usage-checks";import { withWorkspace } from "@/lib/auth";import { eventsQuerySchema } from "@/lib/zod/schemas/analytics";-import { clickEventEnrichedSchema } from "@/lib/zod/schemas/clicks";-import { leadEventEnrichedSchema } from "@/lib/zod/schemas/leads";-import { saleEventEnrichedSchema } from "@/lib/zod/schemas/sales";+import { clickEventResponseSchema } from "@/lib/zod/schemas/clicks";+import { leadEventResponseSchema } from "@/lib/zod/schemas/leads";+import { saleEventResponseSchema } from "@/lib/zod/schemas/sales";import { COUNTRIES, capitalize } from "@dub/utils";import { z } from "zod";-type ClickEvent = z.infer<typeof clickEventEnrichedSchema>;-type LeadEvent = z.infer<typeof leadEventEnrichedSchema>;-type SaleEvent = z.infer<typeof saleEventEnrichedSchema>;+type ClickEvent = z.infer<typeof clickEventResponseSchema>;+type LeadEvent = z.infer<typeof leadEventResponseSchema>;+type SaleEvent = z.infer<typeof saleEventResponseSchema>;type Row = ClickEvent | LeadEvent | SaleEvent;@@ -27,14 +27,14 @@ const columnNames: Record<string, string> = {const columnAccessors = {trigger: (r: Row) => (r.qr ? "QR scan" : "Link click"),- event: (r: LeadEvent | SaleEvent) => r.event_name,+ event: (r: LeadEvent | SaleEvent) => r.eventName,link: (r: Row) => r.domain + (r.key === "_root" ? "" : `/${r.key}`),country: (r: Row) =>r.country ? COUNTRIES[r.country] ?? r.country : r.country,customer: (r: LeadEvent | SaleEvent) =>- r.customer_name + (r.customer_email ? ` <${r.customer_email}>` : ""),- invoiceId: (r: SaleEvent) => r.invoice_id,- saleAmount: (r: SaleEvent) => "$" + (r.saleAmount / 100).toFixed(2),+ r.customer.name + (r.customer.email ? ` <${r.customer.email}>` : ""),+ invoiceId: (r: SaleEvent) => r.sale.invoiceId,+ saleAmount: (r: SaleEvent) => "$" + (r.sale.amount / 100).toFixed(2),};// GET /api/events/export – get export data for analyticsdiff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.tsindex 98cba78ce6..20a35009cb 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: "v1_events",+ pipe: "v2_events",parameters: eventsFilterTB,data:{@@ -83,6 +83,9 @@ export const getEvents = async (params: EventsFilters) => {const eventData = {...evt,+ // use link domain & key from mysql instead of tinybird+ domain: link.domain,+ key: link.key,// timestamp is always in UTCtimestamp: new Date(evt.timestamp + "Z"),click: clickEventSchema.parse({diff --git a/apps/web/lib/zod/schemas/clicks.ts b/apps/web/lib/zod/schemas/clicks.tsindex 563f945e56..6ef623ce7a 100644--- a/apps/web/lib/zod/schemas/clicks.ts+++ b/apps/web/lib/zod/schemas/clicks.ts@@ -36,8 +36,6 @@ export const clickEventEnrichedSchema = z.object({timestamp: z.string(),click_id: z.string(),link_id: z.string(),- domain: z.string(),- key: z.string(),url: z.string(),continent: z.string().nullable(),country: z.string().nullable(),diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.tsindex 8375e53cc6..8db19fe6ab 100644--- a/apps/web/lib/zod/schemas/leads.ts+++ b/apps/web/lib/zod/schemas/leads.ts@@ -89,8 +89,6 @@ export const leadEventEnrichedSchema = z.object({customer_avatar: z.string(),click_id: z.string(),link_id: z.string(),- domain: z.string(),- key: z.string(),url: z.string(),continent: z.string().nullable(),country: z.string().nullable(),diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.tsindex 8d829f995b..48455d9378 100644--- a/apps/web/lib/zod/schemas/sales.ts+++ b/apps/web/lib/zod/schemas/sales.ts@@ -95,8 +95,6 @@ export const saleEventEnrichedSchema = z.object({saleAmount: z.number(),click_id: z.string(),link_id: z.string(),- domain: z.string(),- key: z.string(),url: z.string(),continent: z.string().nullable(),country: z.string().nullable(),diff --git a/apps/web/ui/analytics/events/events-table.tsx b/apps/web/ui/analytics/events/events-table.tsxindex 2d2e691116..294c169ed4 100644--- a/apps/web/ui/analytics/events/events-table.tsx+++ b/apps/web/ui/analytics/events/events-table.tsx@@ -2,9 +2,9 @@import { editQueryString } from "@/lib/analytics/utils";import useWorkspace from "@/lib/swr/use-workspace";-import { clickEventEnrichedSchema } from "@/lib/zod/schemas/clicks";-import { leadEventEnrichedSchema } from "@/lib/zod/schemas/leads";-import { saleEventEnrichedSchema } from "@/lib/zod/schemas/sales";+import { clickEventResponseSchema } from "@/lib/zod/schemas/clicks";+import { leadEventResponseSchema } from "@/lib/zod/schemas/leads";+import { saleEventResponseSchema } from "@/lib/zod/schemas/sales";import EmptyState from "@/ui/shared/empty-state";import {LinkLogo,@@ -46,9 +46,9 @@ import { RowMenuButton } from "./row-menu-button";import { eventColumns, useColumnVisibility } from "./use-column-visibility";export type EventDatum =- | z.infer<typeof clickEventEnrichedSchema>- | z.infer<typeof leadEventEnrichedSchema>- | z.infer<typeof saleEventEnrichedSchema>;+ | z.infer<typeof clickEventResponseSchema>+ | z.infer<typeof leadEventResponseSchema>+ | z.infer<typeof saleEventResponseSchema>;type ColumnMeta = {filterParams?: (@@ -135,19 +135,6 @@ export default function EventsTable() {</span>) || <span className="text-gray-400">-</span>,},- // Sale invoice ID- {- id: "invoiceId",- header: "Invoice ID",- accessorKey: "invoice_id",- maxSize: 200,- cell: ({ getValue }) =>- (- <span className="truncate" title={getValue()}>- {getValue()}- </span>- ) || <span className="text-gray-400">-</span>,- },{id: "link",header: "Link",@@ -364,6 +351,19 @@ export default function EventsTable() {</div>),},+ // Sale invoice ID+ {+ id: "invoiceId",+ header: "Invoice ID",+ accessorKey: "sale.invoiceId",+ maxSize: 200,+ cell: ({ getValue }) =>+ (+ <span className="truncate" title={getValue()}>+ {getValue()}+ </span>+ ) || <span className="text-gray-400">-</span>,+ },// Date{id: "timestamp",diff --git a/apps/web/ui/analytics/events/use-column-visibility.ts b/apps/web/ui/analytics/events/use-column-visibility.tsindex 5ed9675d93..389690ea8e 100644--- a/apps/web/ui/analytics/events/use-column-visibility.ts+++ b/apps/web/ui/analytics/events/use-column-visibility.ts@@ -1,8 +1,6 @@import { EventType } from "@/lib/analytics/types";import { useLocalStorage } from "@dub/ui";import { VisibilityState } from "@tanstack/react-table";-import { useContext } from "react";-import { AnalyticsContext } from "../analytics-provider";export const eventColumns: Record<EventType,@@ -85,8 +83,6 @@ const getDefaultColumnVisibility = (tab: EventType) =>);export function useColumnVisibility() {- const { selectedTab } = useContext(AnalyticsContext);-const [columnVisibility, setColumnVisibility] = useLocalStorage<Record<EventType, VisibilityState>>("events-columns", {