Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

amount → saleAmount

Steven Teyd1b8ffc32755
diff --git a/apps/web/app/api/events/export/route.ts b/apps/web/app/api/events/export/route.ts
index 3198d33d43..d2c2480c09 100644
--- a/apps/web/app/api/events/export/route.ts
+++ b/apps/web/app/api/events/export/route.ts
@@ -22,7 +22,7 @@ const columnNames: Record<string, string> = {
os: "OS",
timestamp: "Date",
invoiceId: "Invoice ID",
- amount: "Sales Amount",
+ saleAmount: "Sale Amount",
};
const columnAccessors = {
@@ -34,7 +34,7 @@ const columnAccessors = {
customer: (r: LeadEvent | SaleEvent) =>
r.customer_name + (r.customer_email ? ` <${r.customer_email}>` : ""),
invoiceId: (r: SaleEvent) => r.invoice_id,
- amount: (r: SaleEvent) => "$" + (r.amount / 100).toFixed(2),
+ saleAmount: (r: SaleEvent) => "$" + (r.saleAmount / 100).toFixed(2),
};
// GET /api/events/export – get export data for analytics
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
index 740e858399..a860a95f92 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/activity-list.tsx
@@ -2,9 +2,6 @@
import { EventType } from "@/lib/analytics/types";
import { REFERRAL_REVENUE_SHARE } from "@/lib/referrals/constants";
-import { clickEventEnrichedSchema } from "@/lib/zod/schemas/clicks";
-import { leadEventEnrichedSchema } from "@/lib/zod/schemas/leads";
-import { saleEventEnrichedSchema } from "@/lib/zod/schemas/sales";
import { EventList } from "@dub/blocks";
import {
CaretUpFill,
@@ -15,18 +12,20 @@ import {
UserCheck,
} from "@dub/ui/src/icons";
import { capitalize, COUNTRIES, currencyFormatter, timeAgo } from "@dub/utils";
+import { ClickEvents } from "dub/dist/commonjs/models/components";
import { useSearchParams } from "next/navigation";
-import { z } from "zod";
+
+interface SaleEvent extends ClickEvents {
+ event_name: string;
+ amount: number;
+}
export function ActivityList({
events,
totalEvents,
demo,
}: {
- events:
- | z.infer<typeof clickEventEnrichedSchema>[]
- | z.infer<typeof leadEventEnrichedSchema>[]
- | z.infer<typeof saleEventEnrichedSchema>[];
+ events: ClickEvents[] | SaleEvent[];
totalEvents: number;
demo?: boolean;
}) {
@@ -71,11 +70,7 @@ export function ActivityList({
);
}
-function ClickDescription({
- event,
-}: {
- event: z.infer<typeof clickEventEnrichedSchema>;
-}) {
+function ClickDescription({ event }: { event: ClickEvents }) {
return (
<>
Someone from{" "}
@@ -98,11 +93,7 @@ function ClickDescription({
);
}
-function LeadDescription({
- event,
-}: {
- event: z.infer<typeof leadEventEnrichedSchema>;
-}) {
+function LeadDescription({ event }: { event: ClickEvents }) {
return (
<>
Someone from{" "}
@@ -132,11 +123,7 @@ const saleText = {
default: "made a payment",
};
-function SaleDescription({
- event,
-}: {
- event: z.infer<typeof saleEventEnrichedSchema>;
-}) {
+function SaleDescription({ event }: { event: SaleEvent }) {
return (
<div className="flex items-center justify-between gap-3">
<div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
index 60aa79a70d..e94a686544 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/page.tsx
@@ -157,7 +157,7 @@ const placeholderEvents = {
"Subscription paid",
"Plan upgraded",
][idx % 3],
- amount: [1100, 4900, 2400][idx % 3],
+ saleAmount: [1100, 4900, 2400][idx % 3],
}) as z.infer<typeof saleEventEnrichedSchema>,
),
};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
index 1a9c91b51f..1e4b70402e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
@@ -150,9 +150,11 @@ async function loadData(linkId: string) {
date: new Date(d.start),
value: d.clicks,
})),
+ // TODO update to saleAmount
totalSales: totalEvents.amount,
sales: sales.map((d) => ({
date: new Date(d.start),
+ // TODO update to saleAmount
value: d.amount,
})),
referredSignups: Math.min(totalEvents.leads, 32),
diff --git a/apps/web/lib/actions/get-total-events.ts b/apps/web/lib/actions/get-total-events.ts
index a050dddf27..bcb01ab24b 100644
--- a/apps/web/lib/actions/get-total-events.ts
+++ b/apps/web/lib/actions/get-total-events.ts
@@ -20,6 +20,7 @@ export const getTotalEvents = unstable_cache(async (linkId: string) => {
clicks: number;
leads: number;
sales: number;
+ // TODO update to saleAmount
amount: number;
}>;
});
diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.ts
index 4261263c6f..18c048d824 100644
--- a/apps/web/lib/analytics/get-analytics.ts
+++ b/apps/web/lib/analytics/get-analytics.ts
@@ -32,9 +32,9 @@ export const getAnalytics = async (params: AnalyticsFilters) => {
if (linkId && groupBy === "count" && interval === "all_unfiltered") {
const columns =
event === "composite"
- ? `clicks, leads, sales, saleAmount as amount`
+ ? `clicks, leads, sales, saleAmount`
: event === "sales"
- ? `sales, saleAmount as amount`
+ ? `sales, saleAmount`
: `${event}`;
let response = await conn.execute(
diff --git a/apps/web/lib/analytics/types.ts b/apps/web/lib/analytics/types.ts
index 312be44d32..77ea06a23d 100644
--- a/apps/web/lib/analytics/types.ts
+++ b/apps/web/lib/analytics/types.ts
@@ -15,7 +15,11 @@ export type IntervalOptions = (typeof intervals)[number];
export type AnalyticsGroupByOptions =
(typeof VALID_ANALYTICS_ENDPOINTS)[number];
-export type AnalyticsResponseOptions = "clicks" | "leads" | "sales" | "amount";
+export type AnalyticsResponseOptions =
+ | "clicks"
+ | "leads"
+ | "sales"
+ | "saleAmount";
export type EventType = (typeof EVENT_TYPES)[number];
diff --git a/apps/web/lib/zod/schemas/analytics-response.ts b/apps/web/lib/zod/schemas/analytics-response.ts
index a7d0d8361a..eb8e39363a 100644
--- a/apps/web/lib/zod/schemas/analytics-response.ts
+++ b/apps/web/lib/zod/schemas/analytics-response.ts
@@ -7,7 +7,7 @@ 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),
- amount: z.number().describe("The total amount of sales").default(0),
+ saleAmount: z.number().describe("The total amount of sales").default(0),
})
.openapi({ ref: "AnalyticsCount", title: "AnalyticsCount" }),
timeseries: z
@@ -25,7 +25,7 @@ export const analyticsResponse = {
.number()
.describe("The number of sales in the interval")
.default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales in the interval")
.default(0),
@@ -51,7 +51,7 @@ export const analyticsResponse = {
.number()
.describe("The number of sales from this continent")
.default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales from this continent")
.default(0),
@@ -77,7 +77,7 @@ export const analyticsResponse = {
.number()
.describe("The number of sales from this country")
.default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales from this country")
.default(0),
@@ -102,7 +102,7 @@ export const analyticsResponse = {
.number()
.describe("The number of sales from this city")
.default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales from this city")
.default(0),
@@ -124,7 +124,7 @@ export const analyticsResponse = {
.number()
.describe("The number of sales from this device")
.default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales from this device")
.default(0),
@@ -146,7 +146,7 @@ export const analyticsResponse = {
.number()
.describe("The number of sales from this browser")
.default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales from this browser")
.default(0),
@@ -162,7 +162,7 @@ export const analyticsResponse = {
.default(0),
leads: z.number().describe("The number of leads from this OS").default(0),
sales: z.number().describe("The number of sales from this OS").default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales from this OS")
.default(0),
@@ -188,7 +188,7 @@ export const analyticsResponse = {
.number()
.describe("The number of sales from this referer")
.default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales from this referer")
.default(0),
@@ -221,7 +221,7 @@ export const analyticsResponse = {
.number()
.describe("The number of sales from this link")
.default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales from this link")
.default(0),
@@ -243,7 +243,7 @@ export const analyticsResponse = {
.number()
.describe("The number of sales from this URL")
.default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales from this URL")
.default(0),
@@ -267,7 +267,7 @@ export const analyticsResponse = {
.number()
.describe("The number of sales from this trigger method.")
.default(0),
- amount: z
+ saleAmount: z
.number()
.describe("The total amount of sales from this trigger method.")
.default(0),
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index 524a8a5648..9b4575f296 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -202,7 +202,7 @@ export const eventsFilterTB = analyticsFilterTB
offset: z.coerce.number().default(0),
limit: z.coerce.number().default(PAGINATION_LIMIT),
order: z.enum(["asc", "desc"]).default("desc"),
- sortBy: z.enum(["timestamp", "amount"]).default("timestamp"),
+ sortBy: z.enum(["timestamp"]).default("timestamp"),
}),
);
@@ -213,6 +213,6 @@ export const eventsQuerySchema = analyticsQuerySchema
page: z.coerce.number().default(0),
limit: z.coerce.number().default(PAGINATION_LIMIT),
order: z.enum(["asc", "desc"]).default("desc"),
- sortBy: z.enum(["timestamp", "amount"]).default("timestamp"),
+ sortBy: z.enum(["timestamp"]).default("timestamp"),
}),
);
diff --git a/apps/web/lib/zod/schemas/sales.ts b/apps/web/lib/zod/schemas/sales.ts
index 8dd608540d..cf608a1c72 100644
--- a/apps/web/lib/zod/schemas/sales.ts
+++ b/apps/web/lib/zod/schemas/sales.ts
@@ -49,7 +49,7 @@ export const trackSaleRequestSchema = z.object({
export const trackSaleResponseSchema = z.object({
eventName: z.string(),
customerId: z.string(),
- amount: z.number(),
+ saleAmount: z.number(),
paymentProcessor: z.string(),
invoiceId: z.string().nullable(),
currency: z.string(),
@@ -82,7 +82,7 @@ export const saleEventEnrichedSchema = z
customer_avatar: z.string(),
payment_processor: z.string(),
invoice_id: z.string(),
- amount: z.number(),
+ saleAmount: z.number(),
click_id: z.string(),
link_id: z.string(),
domain: z.string(),
diff --git a/apps/web/ui/analytics/analytics-area-chart.tsx b/apps/web/ui/analytics/analytics-area-chart.tsx
index 19a83c5c21..e37293d1d6 100644
--- a/apps/web/ui/analytics/analytics-area-chart.tsx
+++ b/apps/web/ui/analytics/analytics-area-chart.tsx
@@ -24,7 +24,7 @@ export default function AnalyticsAreaChart({
clicks: number;
leads: number;
sales: number;
- amount: number;
+ saleAmount: number;
}[]
>(
`${baseApiPath}?${editQueryString(queryString, {
@@ -39,13 +39,13 @@ export default function AnalyticsAreaChart({
const chartData = useMemo(
() =>
- data?.map(({ start, clicks, leads, sales, amount }) => ({
+ data?.map(({ start, clicks, leads, sales, saleAmount }) => ({
date: new Date(start),
values: {
clicks,
leads,
sales,
- amount: (amount ?? 0) / 100,
+ saleAmount: (saleAmount ?? 0) / 100,
},
})) ?? null,
[data],
@@ -109,7 +109,7 @@ export default function AnalyticsAreaChart({
},
{
id: "sales",
- valueAccessor: (d) => d.values.amount,
+ valueAccessor: (d) => d.values.saleAmount,
isActive: resource === "sales",
colorClassName: "text-teal-400",
},
@@ -126,7 +126,8 @@ export default function AnalyticsAreaChart({
series={series}
tooltipClassName="p-0"
tooltipContent={(d) => {
- const value = d.values[resource === "sales" ? "amount" : resource];
+ const value =
+ d.values[resource === "sales" ? "saleAmount" : resource];
return (
<>
<p className="border-b border-gray-200 px-4 py-3 text-sm text-gray-900">
diff --git a/apps/web/ui/analytics/analytics-funnel-chart.tsx b/apps/web/ui/analytics/analytics-funnel-chart.tsx
index 32a1f1f1e3..c0ef3830aa 100644
--- a/apps/web/ui/analytics/analytics-funnel-chart.tsx
+++ b/apps/web/ui/analytics/analytics-funnel-chart.tsx
@@ -212,7 +212,7 @@ export function AnalyticsFunnelChartInner({
{tooltipStep.id === "sales" && (
<span className="text-gray-500">
{" "}
- (${nFormatter(totalEvents.amount / 100)})
+ (${nFormatter(totalEvents.saleAmount / 100)})
</span>
)}
</p>
diff --git a/apps/web/ui/analytics/devices.tsx b/apps/web/ui/analytics/devices.tsx
index 73a2012b87..4523006924 100644
--- a/apps/web/ui/analytics/devices.tsx
+++ b/apps/web/ui/analytics/devices.tsx
@@ -13,7 +13,7 @@ export default function Devices() {
const { queryParams } = useRouterStuff();
const { selectedTab } = useContext(AnalyticsContext);
- const dataKey = selectedTab === "sales" ? "amount" : "count";
+ const dataKey = selectedTab === "sales" ? "saleAmount" : "count";
const [tab, setTab] = useState<DeviceTabs>("devices");
const data = useAnalyticsFilterOption(tab);
diff --git a/apps/web/ui/analytics/events/events-table.tsx b/apps/web/ui/analytics/events/events-table.tsx
index 63214d8b98..eb71272c3f 100644
--- a/apps/web/ui/analytics/events/events-table.tsx
+++ b/apps/web/ui/analytics/events/events-table.tsx
@@ -349,6 +349,20 @@ export default function EventsTable() {
</Tooltip>
),
},
+ // Sale amount
+ {
+ id: "saleAmount",
+ header: "Sale Amount",
+ accessorKey: "saleAmount",
+ enableHiding: false,
+ minSize: 120,
+ cell: ({ getValue }) => (
+ <div className="flex items-center gap-2">
+ <span>${nFormatter(getValue() / 100)}</span>
+ <span className="text-gray-400">USD</span>
+ </div>
+ ),
+ },
// Date
{
id: "timestamp",
@@ -380,20 +394,6 @@ export default function EventsTable() {
</Tooltip>
),
},
- // Sales amount
- {
- id: "amount",
- header: "Sales Amount",
- accessorKey: "amount",
- enableHiding: false,
- minSize: 120,
- cell: ({ getValue }) => (
- <div className="flex items-center gap-2">
- <span>${nFormatter(getValue() / 100)}</span>
- <span className="text-gray-400">USD</span>
- </div>
- ),
- },
// Menu
{
id: "menu",
@@ -465,7 +465,7 @@ export default function EventsTable() {
rowCount: needsHigherPlan ? 0 : totalEvents?.[tab] ?? 0,
columnVisibility: columnVisibility[tab],
onColumnVisibilityChange: (args) => setColumnVisibility(tab, args),
- sortableColumns: ["timestamp", "amount"],
+ sortableColumns: ["timestamp"],
sortBy: sortBy,
sortOrder: order,
onSortChange: ({ sortBy, sortOrder }) =>
diff --git a/apps/web/ui/analytics/events/events-tabs.tsx b/apps/web/ui/analytics/events/events-tabs.tsx
index ce00267911..52a23837bb 100644
--- a/apps/web/ui/analytics/events/events-tabs.tsx
+++ b/apps/web/ui/analytics/events/events-tabs.tsx
@@ -14,7 +14,7 @@ type TimeseriesData = {
clicks: number;
leads: number;
sales: number;
- amount: number;
+ saleAmount: number;
}[];
export default function EventsTabs() {
@@ -57,7 +57,7 @@ export default function EventsTabs() {
const onEventTabClick = useCallback(
(event: string) => {
const sortOptions =
- event === "sales" ? ["timestamp", "amount"] : ["date"];
+ event === "sales" ? ["timestamp", "saleAmount"] : ["date"];
const currentSort = searchParams.get("sort");
queryParams({
set: { event },
@@ -109,7 +109,7 @@ export default function EventsTabs() {
{...(event === "sales" && { fullNumber: true })}
>
{event === "sales"
- ? (totalEvents?.amount ?? 0) / 100
+ ? (totalEvents?.saleAmount ?? 0) / 100
: totalEvents?.[event] ?? 0}
</CountingNumbers>
) : (
@@ -129,7 +129,7 @@ export default function EventsTabs() {
timeseriesData?.map((d) => ({
date: new Date(d.start),
value:
- ((event === "sales" ? d?.amount : d?.[event]) as
+ ((event === "sales" ? d?.saleAmount : d?.[event]) as
| number
| undefined) ?? 0,
})) || []
diff --git a/apps/web/ui/analytics/events/example-data.ts b/apps/web/ui/analytics/events/example-data.ts
index e4bfd33bd0..a2bbca3b16 100644
--- a/apps/web/ui/analytics/events/example-data.ts
+++ b/apps/web/ui/analytics/events/example-data.ts
@@ -143,7 +143,7 @@ export const exampleData = {
event_name: "Purchase",
payment_processor: "stripe",
invoice_id: "123456",
- amount: 900,
+ saleAmount: 900,
continent: "NA",
country: "US",
city: "San Francisco",
@@ -158,7 +158,7 @@ export const exampleData = {
event_name: "Purchase",
payment_processor: "stripe",
invoice_id: "123456",
- amount: 700,
+ saleAmount: 700,
continent: "NA",
country: "US",
city: "Pittsburgh",
@@ -173,7 +173,7 @@ export const exampleData = {
event_name: "Purchase",
payment_processor: "stripe",
invoice_id: "123456",
- amount: 1000,
+ saleAmount: 1000,
continent: "AS",
country: "IN",
city: "Kerala",
diff --git a/apps/web/ui/analytics/events/use-column-visibility.ts b/apps/web/ui/analytics/events/use-column-visibility.ts
index c1b82a66a8..5ed9675d93 100644
--- a/apps/web/ui/analytics/events/use-column-visibility.ts
+++ b/apps/web/ui/analytics/events/use-column-visibility.ts
@@ -63,14 +63,14 @@ export const eventColumns: Record<
"referer",
"ip",
"timestamp",
- "amount",
+ "saleAmount",
],
defaultVisible: [
"event",
"link",
"customer",
"country",
- "amount",
+ "saleAmount",
"timestamp",
],
},
diff --git a/apps/web/ui/analytics/locations.tsx b/apps/web/ui/analytics/locations.tsx
index 39a9e0e1ee..8a5c8ad282 100644
--- a/apps/web/ui/analytics/locations.tsx
+++ b/apps/web/ui/analytics/locations.tsx
@@ -13,7 +13,7 @@ export default function Locations() {
const { queryParams } = useRouterStuff();
const { selectedTab } = useContext(AnalyticsContext);
- const dataKey = selectedTab === "sales" ? "amount" : "count";
+ const dataKey = selectedTab === "sales" ? "saleAmount" : "count";
const [tab, setTab] = useState<"countries" | "cities" | "continents">(
"countries",
diff --git a/apps/web/ui/analytics/main.tsx b/apps/web/ui/analytics/main.tsx
index 8c69d471a1..d9be775b44 100644
--- a/apps/web/ui/analytics/main.tsx
+++ b/apps/web/ui/analytics/main.tsx
@@ -64,7 +64,7 @@ export default function Main() {
const total = {
clicks: totalEvents?.clicks,
leads: totalEvents?.leads,
- sales: totalEvents ? totalEvents.amount / 100 : undefined,
+ sales: totalEvents ? totalEvents.saleAmount / 100 : undefined,
}[id];
return (
diff --git a/apps/web/ui/analytics/referer.tsx b/apps/web/ui/analytics/referer.tsx
index f00f3af642..6fcf2b94dd 100644
--- a/apps/web/ui/analytics/referer.tsx
+++ b/apps/web/ui/analytics/referer.tsx
@@ -12,7 +12,7 @@ export default function Referer() {
const { queryParams } = useRouterStuff();
const { selectedTab } = useContext(AnalyticsContext);
- const dataKey = selectedTab === "sales" ? "amount" : "count";
+ const dataKey = selectedTab === "sales" ? "saleAmount" : "count";
const data = useAnalyticsFilterOption("referers");
diff --git a/apps/web/ui/analytics/top-links.tsx b/apps/web/ui/analytics/top-links.tsx
index f1ea027b94..d96e10426d 100644
--- a/apps/web/ui/analytics/top-links.tsx
+++ b/apps/web/ui/analytics/top-links.tsx
@@ -11,7 +11,7 @@ export default function TopLinks() {
const { queryParams } = useRouterStuff();
const { selectedTab, domain, key } = useContext(AnalyticsContext);
- const dataKey = selectedTab === "sales" ? "amount" : "count";
+ const dataKey = selectedTab === "sales" ? "saleAmount" : "count";
const showUrls = domain && key;
const data = useAnalyticsFilterOption({
diff --git a/apps/web/ui/analytics/utils.ts b/apps/web/ui/analytics/utils.ts
index 25e690c928..9738f47092 100644
--- a/apps/web/ui/analytics/utils.ts
+++ b/apps/web/ui/analytics/utils.ts
@@ -54,7 +54,7 @@ export function useAnalyticsFilterOption(
data?.map((d) => ({
...d,
count: d[selectedTab] as number | undefined,
- amount: d.amount as number | undefined,
+ saleAmount: d.saleAmount as number | undefined,
})) ?? null
);
}