The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Analytics percentage view
Marcus Farrell56661e4bc3b0
diff --git a/apps/web/ui/analytics/analytics-card.tsx b/apps/web/ui/analytics/analytics-card.tsxindex 8589652e70..db76a4a50d 100644--- a/apps/web/ui/analytics/analytics-card.tsx+++ b/apps/web/ui/analytics/analytics-card.tsx@@ -65,8 +65,18 @@ export function AnalyticsCard<T extends string>({setShowModal={setShowModal}className="max-w-lg px-0">- <div className="border-b border-neutral-200 px-6 py-4">+ <div className="flex items-center justify-between border-b border-neutral-200 px-6 py-4"><h1 className="text-lg font-semibold">{selectedTab?.label}</h1>+ <div className="flex items-center gap-1 text-neutral-500">+ {event === "sales" ? (+ <InvoiceDollar className="h-4 w-4" />+ ) : event === "leads" ? (+ <UserCheck className="h-4 w-4" />+ ) : (+ <CursorRays className="h-4 w-4" />+ )}+ <p className="text-xs uppercase">{event}</p>+ </div></div>{subTabs && selectedSubTabId && onSelectSubTab && (<SubTabs@@ -79,7 +89,7 @@ export function AnalyticsCard<T extends string>({</Modal><divclassName={cn(- "relative z-0 h-[400px] overflow-hidden border border-neutral-200 bg-white sm:rounded-xl",+ "group relative z-0 h-[400px] overflow-hidden border border-neutral-200 bg-white sm:rounded-xl",className,)}>diff --git a/apps/web/ui/analytics/bar-list.tsx b/apps/web/ui/analytics/bar-list.tsxindex 63aeb9757f..6584ab3104 100644--- a/apps/web/ui/analytics/bar-list.tsx+++ b/apps/web/ui/analytics/bar-list.tsx@@ -49,6 +49,9 @@ export default function BarList({}) {const [search, setSearch] = useState("");+ // Calculate total sum for percentage calculations+ const totalSum = useMemo(() => data.reduce((sum, item) => sum + item.value, 0), [data]);+// TODO: mock pagination for better perf in Reactconst filteredData = useMemo(() => {if (limit) {@@ -69,11 +72,13 @@ export default function BarList({const itemProps = filteredData.map((data) => ({...data,maxValue,+ totalSum,tab,unit,setShowModal,barBackground,hoverBackground,+ limit,}));const bars = (@@ -131,24 +136,28 @@ export function LineItem({href,value,maxValue,+ totalSum,tab,unit,setShowModal,barBackground,hoverBackground,linkData,+ limit,}: {icon: ReactNode;title: string;href?: string;value: number;maxValue: number;+ totalSum: number;tab: string;unit: string;setShowModal: Dispatch<SetStateAction<boolean>>;barBackground: string;hoverBackground: string;linkData?: LinkProps;+ limit?: number;}) {const lineItem = useMemo(() => {return (@@ -162,9 +171,16 @@ export function LineItem({}, [icon, tab, title]);const { saleUnit } = useContext(AnalyticsContext);+ const { isMobile } = useMediaQuery();const As = href ? Link : "div";+ // Calculate percentage against total sum and round to 1 decimal+ const percentage = Math.round((value / totalSum) * 1000) / 10;++ // Check if we're in modal view - if limit is undefined, we're in the modal view+ const isModalView = !limit;+return (// @ts-ignore - we know if it's a Link it'll get its href<As@@ -176,9 +192,10 @@ export function LineItem({className={cn(`block min-w-0 border-l-2 border-transparent px-4 py-1 transition-all`,href && hoverBackground,+ (isMobile || isModalView) ? "group" : "")}>- <div className="group flex items-center justify-between">+ <div className="flex items-center justify-between"><div className="relative z-10 flex h-8 w-full min-w-0 max-w-[calc(100%-2rem)] items-center">{tab === "links" && linkData ? (<Tooltip content={<LinkPreviewTooltip data={linkData} />}>@@ -210,24 +227,38 @@ export function LineItem({animate={{ transform: "scaleX(1)" }}/></div>- <NumberFlow- value={- unit === "sales" && saleUnit === "saleAmount" ? value / 100 : value- }- className="z-10 px-2 text-sm text-neutral-600"- format={- unit === "sales" && saleUnit === "saleAmount"- ? {- style: "currency",- currency: "USD",- // @ts-ignore – trailingZeroDisplay is a valid option but TS is outdated- trailingZeroDisplay: "stripIfInteger",- }- : {- notation: value > 999999 ? "compact" : "standard",- }- }- />+ <div className="z-10 flex items-center">+ <NumberFlow+ value={+ unit === "sales" && saleUnit === "saleAmount" ? value / 100 : value+ }+ className={cn(+ "z-10 px-2 text-sm text-neutral-600 transition-transform duration-300",+ (isMobile || isModalView) ? "-translate-x-14" : "group-hover:-translate-x-14"+ )}+ format={+ unit === "sales" && saleUnit === "saleAmount"+ ? {+ style: "currency",+ currency: "USD",+ trailingZeroDisplay: "stripIfInteger",+ }+ : {+ notation: value > 999999 ? "compact" : "standard",+ }+ }+ />+ <div+ className={cn(+ "absolute right-0 px-6 text-sm text-neutral-600/70 transition-all duration-300",+ (isMobile || isModalView)+ ? "translate-x-0 visible opacity-100"+ : "translate-x-14 invisible opacity-0 group-hover:visible group-hover:translate-x-0 group-hover:opacity-100"+ )}+ >+ {percentage}%+ </div>+ </div></div></As>);