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 click details

Tim Wilsonc02bfbb51dc2
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 12d5bd67cb..fa8e27a455 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
@@ -3,19 +3,22 @@
import useCustomer from "@/lib/swr/use-customer";
import useWorkspace from "@/lib/swr/use-workspace";
import { CustomerActivityResponse } from "@/lib/types";
+import DeviceIcon from "@/ui/analytics/device-icon";
import { BackLink } from "@/ui/shared/back-link";
-import { CopyButton } from "@dub/ui";
+import { CopyButton, UTM_PARAMETERS } from "@dub/ui";
import {
+ capitalize,
cn,
COUNTRIES,
currencyFormatter,
DICEBEAR_AVATAR_URL,
fetcher,
+ getParamsFromURL,
getPrettyUrl,
} from "@dub/utils";
import Link from "next/link";
import { notFound, useParams } from "next/navigation";
-import { HTMLProps } from "react";
+import { Fragment, HTMLProps, useMemo } from "react";
import useSWR from "swr";
export function CustomerPageClient() {
@@ -39,13 +42,28 @@ export function CustomerPageClient() {
fetcher,
);
+ const link = customerActivity?.link;
+ const click = customerActivity?.events.find((e) => e.event === "click");
+
+ if (click)
+ click.url =
+ "https://dub.co/brand?utm_source=dub&utm_medium=referral&utm_campaign=brand";
+
+ const utmParams = useMemo(() => {
+ if (!click?.url) return null;
+ const allParams = getParamsFromURL(click.url);
+
+ return UTM_PARAMETERS.map((p) => ({
+ ...p,
+ value: allParams?.[p.key],
+ })).filter(({ value }) => value);
+ }, [click?.url]);
+
if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
if (!customer) notFound();
- const link = customerActivity?.link;
-
return (
<div className="mt-2">
<BackLink href={`/${slug}/links`}>Dashboard</BackLink>
@@ -90,20 +108,63 @@ export function CustomerPageClient() {
</div>
{/* Right side details */}
- <div className="-order-1 grid grid-cols-2 gap-6 text-sm text-neutral-900 lg:order-1 lg:grid-cols-1">
- {customer.country && (
- <div className="flex flex-col gap-2">
- <DetailHeading>Details</DetailHeading>
+ <div className="-order-1 grid grid-cols-2 gap-6 overflow-hidden whitespace-nowrap text-sm text-neutral-900 lg:order-1 lg:grid-cols-1">
+ <div className="flex flex-col gap-2">
+ <DetailHeading>Details</DetailHeading>
+ {customer.country && (
<span className="flex items-center gap-2">
<img
src={`https://hatscripts.github.io/circle-flags/flags/${customer.country.toLowerCase()}.svg`}
alt=""
className="size-3.5"
/>
- {COUNTRIES[customer.country]}
+ <span className="truncate">{COUNTRIES[customer.country]}</span>
</span>
- </div>
- )}
+ )}
+ {click
+ ? [
+ {
+ icon: (
+ <DeviceIcon
+ display={capitalize(click.os)!}
+ tab="os"
+ className="size-3.5 shrink-0"
+ />
+ ),
+ value: click.os,
+ },
+ {
+ icon: (
+ <DeviceIcon
+ display={capitalize(click.device)!}
+ tab="devices"
+ className="size-3.5 shrink-0"
+ />
+ ),
+ value: click.device,
+ },
+ {
+ icon: (
+ <DeviceIcon
+ display={capitalize(click.browser)!}
+ tab="browsers"
+ className="size-3.5 shrink-0"
+ />
+ ),
+ value: click.browser,
+ },
+ ]
+ .filter(({ value }) => value)
+ .map(({ icon, value }, idx) => (
+ <span className="flex items-center gap-2">
+ {icon}
+ <span className="truncate">{value}</span>
+ </span>
+ ))
+ : isCustomerActivityLoading && (
+ <div className="h-5 w-12 animate-pulse rounded-md bg-neutral-100" />
+ )}
+ </div>
<div className="flex flex-col gap-2">
<DetailHeading>Customer since</DetailHeading>
@@ -148,6 +209,20 @@ export function CustomerPageClient() {
<span>-</span>
)}
</div>
+
+ {utmParams && (
+ <div className="flex flex-col gap-2">
+ <DetailHeading>UTM</DetailHeading>
+ <div className="grid w-full grid-cols-[min-content,minmax(0,1fr)] gap-x-4 gap-y-2 overflow-hidden">
+ {utmParams.map(({ label, value }) => (
+ <Fragment key={label}>
+ <span className="truncate">{label}</span>
+ <span className="truncate text-neutral-500">{value}</span>
+ </Fragment>
+ ))}
+ </div>
+ </div>
+ )}
</div>
</div>
</div>