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.

Add activity list

Tim Wilson0cb40891b6c8
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
index cd8da17061..bcc32d6bd9 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/customers/[customerId]/page-client.tsx
@@ -4,6 +4,7 @@ import useCustomer from "@/lib/swr/use-customer";
import useWorkspace from "@/lib/swr/use-workspace";
import { CustomerActivityResponse, SaleEvent } from "@/lib/types";
import DeviceIcon from "@/ui/analytics/device-icon";
+import { CustomerActivityList } from "@/ui/customers/customer-activity-list";
import { CustomerEarningsTable } from "@/ui/customers/customer-earnings-table";
import { BackLink } from "@/ui/shared/back-link";
import { CopyButton, UTM_PARAMETERS } from "@dub/ui";
@@ -104,7 +105,10 @@ export function CustomerPageClient() {
<section className="flex flex-col gap-4">
<h2 className="text-lg font-semibold text-neutral-900">Activity</h2>
- <div className="h-64 rounded-lg bg-neutral-100" />
+ <CustomerActivityList
+ activity={customerActivity}
+ isLoading={isCustomerActivityLoading}
+ />
</section>
</div>
diff --git a/apps/web/ui/customers/customer-activity-list.tsx b/apps/web/ui/customers/customer-activity-list.tsx
new file mode 100644
index 0000000000..be594de658
--- /dev/null
+++ b/apps/web/ui/customers/customer-activity-list.tsx
@@ -0,0 +1,94 @@
+import { CustomerActivityResponse } from "@/lib/types";
+import { LinkLogo } from "@dub/ui";
+import { CursorRays, MoneyBill2, UserCheck } from "@dub/ui/icons";
+import { getApexDomain, getPrettyUrl } from "@dub/utils";
+
+const activityData = {
+ click: {
+ icon: CursorRays,
+ content: (event) => {
+ const referer =
+ !event.click?.referer || event.click.referer === "(direct)"
+ ? "direct"
+ : event.click.referer;
+ return (
+ <span className="flex items-center gap-1.5 [&>*]:min-w-0 [&>*]:truncate">
+ Found{" "}
+ <span className="flex items-center gap-2 rounded-md bg-neutral-100 px-1.5 py-1 font-mono text-xs leading-none">
+ <LinkLogo
+ className="size-3 shrink-0 sm:size-3"
+ apexDomain={getApexDomain(event.click.url)}
+ />
+ <span className="min-w-0 truncate">
+ {getPrettyUrl(event.link.shortLink)}
+ </span>
+ </span>
+ via
+ <span className="flex items-center gap-2 rounded-md bg-neutral-100 px-1.5 py-1 font-mono text-xs leading-none">
+ <LinkLogo
+ className="size-3 shrink-0 sm:size-3"
+ apexDomain={getApexDomain(referer)}
+ />
+ <span className="min-w-0 truncate">
+ {referer === "direct" ? referer : getPrettyUrl(referer)}
+ </span>
+ </span>
+ </span>
+ );
+ },
+ },
+ lead: { icon: UserCheck, content: (event) => event.eventName || "New lead" },
+ sale: { icon: MoneyBill2, content: (event) => event.eventName || "New sale" },
+};
+
+export function CustomerActivityList({
+ activity,
+ isLoading,
+}: {
+ activity?: CustomerActivityResponse;
+ isLoading: boolean;
+}) {
+ console.log({ activity });
+ return isLoading ? (
+ "loading"
+ ) : !activity?.events.length ? (
+ "no activity"
+ ) : (
+ <ul className="flex flex-col gap-5 text-sm">
+ {activity.events.map((event, index, events) => {
+ const isLast = index === events.length - 1;
+ const timestamp = new Date(event.timestamp);
+
+ const month = timestamp.toLocaleDateString("en-US", {
+ month: "short",
+ day: "numeric",
+ });
+
+ const time = timestamp.toLocaleTimeString("en-US", {
+ hour: "numeric",
+ minute: "numeric",
+ hour12: true,
+ });
+
+ const { icon: Icon, content } = activityData[event.event];
+
+ return (
+ <li className="flex items-start gap-2">
+ <div className="relative mr-3 flex-shrink-0">
+ <Icon className="mt-0.5 size-4" />
+ {!isLast && (
+ <div className="absolute left-1/2 mt-2 h-8 border-l border-neutral-300" />
+ )}
+ </div>
+ <div className="flex min-w-0 flex-col gap-1 whitespace-nowrap text-sm text-neutral-800">
+ <div className="truncate">{content(event)}</div>
+ <span className="truncate text-sm text-neutral-500">
+ {month}, {time}
+ </span>
+ </div>
+ </li>
+ );
+ })}
+ </ul>
+ );
+}
diff --git a/apps/web/ui/customers/customer-earnings-table.tsx b/apps/web/ui/customers/customer-earnings-table.tsx
index 6e4113d5d2..84f36b45cf 100644
--- a/apps/web/ui/customers/customer-earnings-table.tsx
+++ b/apps/web/ui/customers/customer-earnings-table.tsx
@@ -1,5 +1,4 @@
import { SaleEvent } from "@/lib/types";
-import { Tooltip } from "@dub/ui";
import { currencyFormatter } from "@dub/utils";
import {
flexRender,
@@ -28,27 +27,15 @@ export function CustomerEarningsTable({
enableHiding: false,
minSize: 100,
cell: ({ getValue }) => (
- <Tooltip
- content={getValue().toLocaleTimeString("en-US", {
- year: "numeric",
+ <span>
+ {getValue().toLocaleTimeString("en-US", {
month: "short",
day: "numeric",
hour: "numeric",
minute: "numeric",
- second: "numeric",
hour12: true,
})}
- >
- <div className="w-full truncate">
- {getValue().toLocaleTimeString("en-US", {
- month: "short",
- day: "numeric",
- hour: "numeric",
- minute: "numeric",
- hour12: true,
- })}
- </div>
- </Tooltip>
+ </span>
),
},
{
diff --git a/packages/tinybird/pipes/v2_customer_events.pipe b/packages/tinybird/pipes/v2_customer_events.pipe
index 8e7660d8d5..25cec50319 100644
--- a/packages/tinybird/pipes/v2_customer_events.pipe
+++ b/packages/tinybird/pipes/v2_customer_events.pipe
@@ -64,7 +64,8 @@ SQL >
ip,
CONCAT(country, '-', region) as region_processed,
splitByString('?', referer_url)[1] as referer_url_processed,
- 'lead' as event
+ 'lead' as event,
+ event_name
FROM dub_lead_events_mv
WHERE
customer_id = {{ String(customerId) }}
@@ -102,6 +103,7 @@ SQL >
CONCAT(country, '-', region) as region_processed,
splitByString('?', referer_url)[1] as referer_url_processed,
'sale' as event,
+ event_name,
amount as saleAmount
FROM dub_sale_events_mv
WHERE
@@ -118,7 +120,7 @@ SQL >
%
SELECT * FROM (
{% if defined(clickId) %}
- SELECT *, NULL AS saleAmount
+ SELECT *, NULL AS event_name, NULL AS saleAmount
FROM click_events
UNION ALL
{% end %}