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.

Short Links x Destination URLs

Steven Teyf0a09eadfd77
diff --git a/apps/web/app/api/analytics/export/route.ts b/apps/web/app/api/analytics/export/route.ts
index 2a378abf21..98a9307fe7 100644
--- a/apps/web/app/api/analytics/export/route.ts
+++ b/apps/web/app/api/analytics/export/route.ts
@@ -50,8 +50,6 @@ export const GET = withWorkspace(
// no need to fetch top links data if there's a link specified
// since this is just a single link
if (endpoint === "top_links" && link) return;
- // we're not fetching top URLs data if there's no link specified
- if (endpoint === "top_urls" && !link) return;
// skip clicks count
if (endpoint === "count") return;
diff --git a/apps/web/ui/analytics/bar-list.tsx b/apps/web/ui/analytics/bar-list.tsx
index 4e8b4e44ec..a19e694366 100644
--- a/apps/web/ui/analytics/bar-list.tsx
+++ b/apps/web/ui/analytics/bar-list.tsx
@@ -137,11 +137,11 @@ export function LineItem({
>
<div className="group flex items-center justify-between">
<div className="relative z-10 flex h-8 w-full max-w-[calc(100%-2rem)] items-center">
- {tab === "link" && linkData ? (
+ {tab === "links" && linkData ? (
<Tooltip content={<LinkPreviewTooltip data={linkData} />}>
{lineItem}
</Tooltip>
- ) : tab === "url" ? (
+ ) : tab === "urls" ? (
<Tooltip
content={
<div className="overflow-auto px-4 py-2">
diff --git a/apps/web/ui/analytics/referer.tsx b/apps/web/ui/analytics/referer.tsx
index 1c41dff4bf..147f3fd47a 100644
--- a/apps/web/ui/analytics/referer.tsx
+++ b/apps/web/ui/analytics/referer.tsx
@@ -23,8 +23,8 @@ export default function Referer() {
return (
<AnalyticsCard
tabs={[
- { id: "referers", label: "Referers" },
- { id: "referer_urls", label: "Referer URLs" },
+ { id: "referers", label: "Referrers" },
+ { id: "referer_urls", label: "Referrer URLs" },
]}
selectedTabId={tab}
onSelectTab={setTab}
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index ce52f8a833..9a7e0dd132 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -537,27 +537,23 @@ export default function Toggle({
right: nFormatter(count, { full: true }),
})) ?? null,
},
- ...(key && domain
- ? [
- {
- key: "url",
- icon: LinkBroken,
- label: "Destination URL",
- getOptionIcon: (_, props) => (
- <LinkLogo
- apexDomain={getApexDomain(props.option?.data?.url)}
- className="size-4 sm:size-4"
- />
- ),
- options:
- urls?.map(({ url, count }) => ({
- value: url,
- label: url.replace(/^https?:\/\//, "").replace(/\/$/, ""),
- right: nFormatter(count, { full: true }),
- })) ?? null,
- },
- ]
- : []),
+ {
+ key: "url",
+ icon: LinkBroken,
+ label: "Destination URL",
+ getOptionIcon: (_, props) => (
+ <LinkLogo
+ apexDomain={getApexDomain(props.option?.value)}
+ className="size-4 sm:size-4"
+ />
+ ),
+ options:
+ urls?.map(({ url, count }) => ({
+ value: url,
+ label: url.replace(/^https?:\/\//, "").replace(/\/$/, ""),
+ right: nFormatter(count, { full: true }),
+ })) ?? null,
+ },
],
[
isPublicStatsPage,
diff --git a/apps/web/ui/analytics/top-links.tsx b/apps/web/ui/analytics/top-links.tsx
index d96e10426d..16bc7a59ee 100644
--- a/apps/web/ui/analytics/top-links.tsx
+++ b/apps/web/ui/analytics/top-links.tsx
@@ -1,6 +1,6 @@
import { LinkLogo, useRouterStuff } from "@dub/ui";
import { getApexDomain } from "@dub/utils";
-import { useContext } from "react";
+import { useContext, useState } from "react";
import { AnalyticsCard } from "./analytics-card";
import { AnalyticsLoadingSpinner } from "./analytics-loading-spinner";
import { AnalyticsContext } from "./analytics-provider";
@@ -10,30 +10,30 @@ import { useAnalyticsFilterOption } from "./utils";
export default function TopLinks() {
const { queryParams } = useRouterStuff();
- const { selectedTab, domain, key } = useContext(AnalyticsContext);
+ const { selectedTab } = useContext(AnalyticsContext);
const dataKey = selectedTab === "sales" ? "saleAmount" : "count";
- const showUrls = domain && key;
+ const [tab, setTab] = useState<"links" | "urls">("links");
const data = useAnalyticsFilterOption({
- groupBy: `top_${showUrls ? "urls" : "links"}`,
+ groupBy: `top_${tab}`,
});
return (
<AnalyticsCard
- tabs={
- showUrls
- ? [{ id: "urls", label: "URLs" }]
- : [{ id: "links", label: "Links" }]
- }
+ tabs={[
+ { id: "links", label: "Short Links" },
+ { id: "urls", label: "Destination URLs" },
+ ]}
expandLimit={8}
hasMore={(data?.length ?? 0) > 8}
- selectedTabId={showUrls ? "urls" : "links"}
+ selectedTabId={tab}
+ onSelectTab={setTab}
>
{({ limit, setShowModal }) =>
data ? (
data.length > 0 ? (
<BarList
- tab={showUrls ? "url" : "link"}
+ tab={tab}
data={
data
?.map((d) => ({
@@ -44,11 +44,12 @@ export default function TopLinks() {
/>
),
title:
- (!showUrls && d["shortLink"] ? d["shortLink"] : d.url) ??
- "Unknown",
+ (tab === "links" && d["shortLink"]
+ ? d["shortLink"]
+ : d.url) ?? "Unknown",
href: queryParams({
set: {
- ...(!showUrls
+ ...(tab === "links"
? { domain: d.domain, key: d.key || "_root" }
: {
url: d.url,
@@ -57,7 +58,7 @@ export default function TopLinks() {
getNewPath: true,
}) as string,
value: d[dataKey] || 0,
- ...(!showUrls && { linkData: d }),
+ ...(tab === "links" && { linkData: d }),
}))
?.sort((a, b) => b.value - a.value) || []
}