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 QR filter, improve root domains filter

Steven Teyd6cb1d1363f9
diff --git a/apps/web/app/api/cron/usage/utils.ts b/apps/web/app/api/cron/usage/utils.ts
index 246760bd52..b0d4dc2e02 100644
--- a/apps/web/app/api/cron/usage/utils.ts
+++ b/apps/web/app/api/cron/usage/utils.ts
@@ -119,7 +119,7 @@ export const updateUsage = async (skip?: number) => {
workspaceId: workspace.id,
endpoint: "top_links",
interval: "30d",
- excludeRoot: true,
+ root: false,
}).then(async (data) => {
const topFive = data.slice(0, 5);
return await Promise.all(
diff --git a/apps/web/app/api/domains/[domain]/transfer/route.ts b/apps/web/app/api/domains/[domain]/transfer/route.ts
index a70ee2ca5e..58d68631c3 100644
--- a/apps/web/app/api/domains/[domain]/transfer/route.ts
+++ b/apps/web/app/api/domains/[domain]/transfer/route.ts
@@ -93,7 +93,7 @@ export const POST = withAuth(
workspaceId: workspace.id,
endpoint: "clicks",
interval: "30d",
- excludeRoot: true,
+ root: false,
});
// Update the domain to use the new workspace
diff --git a/apps/web/lib/analytics.ts b/apps/web/lib/analytics.ts
index b6df68dc6f..fe97933e0a 100644
--- a/apps/web/lib/analytics.ts
+++ b/apps/web/lib/analytics.ts
@@ -88,8 +88,9 @@ export const VALID_ANALYTICS_FILTERS = [
"browser",
"os",
"referer",
- "excludeRoot",
"tagId",
+ "qr",
+ "root",
];
export const getAnalytics = async ({
@@ -163,7 +164,7 @@ export const getAnalytics = async ({
}
VALID_ANALYTICS_FILTERS.forEach((filter) => {
- if (rest[filter]) {
+ if (rest[filter] !== undefined) {
url.searchParams.append(filter, rest[filter]);
}
});
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index 693aff8101..658c230c34 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -29,13 +29,18 @@ export const getAnalyticsQuerySchema = z.object({
.optional()
.describe("The referer to retrieve analytics for."),
url: z.string().optional().describe("The URL to retrieve analytics for."),
- excludeRoot: booleanQuerySchema
- .optional()
- .describe("Whether to exclude the root link from the response."),
tagId: z
.string()
.optional()
.describe("The tag ID to retrieve analytics for."),
+ qr: booleanQuerySchema
+ .optional()
+ .describe("Filter for QR code scans vs link clicks."),
+ root: booleanQuerySchema
+ .optional()
+ .describe(
+ "Root domains filter: If true, filter for domains only. If false, filter for links only. If undefined, return both.",
+ ),
});
export const getAnalyticsEdgeQuerySchema = getAnalyticsQuerySchema.required({
diff --git a/apps/web/scripts/download-top-links.ts b/apps/web/scripts/download-top-links.ts
index 8bfd68409e..09fe864237 100644
--- a/apps/web/scripts/download-top-links.ts
+++ b/apps/web/scripts/download-top-links.ts
@@ -10,7 +10,7 @@ async function main() {
workspaceId: "xxx",
endpoint: "top_links",
interval: "30d",
- excludeRoot: true,
+ root: false,
}).then(async (data) => {
return await Promise.all(
data.map(
diff --git a/apps/web/scripts/get-top-links-for-workspace.ts b/apps/web/scripts/get-top-links-for-workspace.ts
index 1909855684..532f455874 100644
--- a/apps/web/scripts/get-top-links-for-workspace.ts
+++ b/apps/web/scripts/get-top-links-for-workspace.ts
@@ -38,7 +38,7 @@ async function main() {
workspaceId: workspace.id,
endpoint: "top_links",
interval: "30d",
- excludeRoot: true,
+ root: false,
}).then(async (data) => {
const topFive = data.slice(0, 5);
return await Promise.all(
diff --git a/apps/web/ui/analytics/clicks.tsx b/apps/web/ui/analytics/clicks.tsx
index 551b9ed0a6..64fd04e9c2 100644
--- a/apps/web/ui/analytics/clicks.tsx
+++ b/apps/web/ui/analytics/clicks.tsx
@@ -1,5 +1,4 @@
import { VALID_ANALYTICS_FILTERS } from "@/lib/analytics";
-import useDomains from "@/lib/swr/use-domains";
import useTags from "@/lib/swr/use-tags";
import { Chart } from "@/ui/shared/icons";
import { CountingNumbers, NumberTooltip, useRouterStuff } from "@dub/ui";
@@ -14,17 +13,16 @@ import ClicksChart from "./clicks-chart";
export default function Clicks() {
const { totalClicks } = useContext(AnalyticsContext);
const searchParams = useSearchParams();
- const domain = searchParams?.get("domain");
- const key = searchParams?.get("key");
+ const domain = searchParams.get("domain");
+ const key = searchParams.get("key");
const { queryParams } = useRouterStuff();
// Tag related
- const tagId = searchParams?.get("tagId");
+ const tagId = searchParams.get("tagId");
const { tags } = useTags();
- // Domain related
- const domainSlug = searchParams?.get("domainSlug");
- const { allActiveDomains: domains } = useDomains();
+ // Root domain related
+ const root = searchParams.get("root");
return (
<div className="max-w-4xl overflow-hidden border border-gray-200 bg-white p-5 sm:rounded-lg sm:border-gray-100 sm:p-10 sm:shadow-lg">
@@ -99,8 +97,23 @@ export default function Clicks() {
<X className="h-4 w-4" />
</Link>
)}
+ {root && (
+ <Link
+ href={
+ queryParams({
+ del: "root",
+ getNewPath: true,
+ }) as string
+ }
+ className="flex items-center space-x-1 rounded-lg border border-gray-200 bg-gray-50 px-3 py-1 text-sm text-gray-800 transition-all hover:bg-gray-100"
+ >
+ <strong>{root === "true" ? "Domains Only" : "Links Only"}</strong>
+ <X className="h-4 w-4" />
+ </Link>
+ )}
{VALID_ANALYTICS_FILTERS.map((filter) => {
- if (filter === "excludeRoot" || filter === "tagId") return null;
+ if (filter === "tagId" || filter === "qr" || filter === "root")
+ return null;
const value = searchParams?.get(filter);
if (!value) return null;
return (
diff --git a/apps/web/ui/analytics/top-links.tsx b/apps/web/ui/analytics/top-links.tsx
index 5491919eff..5a6244c57b 100644
--- a/apps/web/ui/analytics/top-links.tsx
+++ b/apps/web/ui/analytics/top-links.tsx
@@ -1,5 +1,5 @@
import { TopLinksTabs } from "@/lib/analytics";
-import { LoadingSpinner, Modal, Switch, useRouterStuff } from "@dub/ui";
+import { LoadingSpinner, Modal, TabSelect, useRouterStuff } from "@dub/ui";
import { fetcher, linkConstructor, truncate } from "@dub/utils";
import { Maximize, X } from "lucide-react";
import Link from "next/link";
@@ -31,7 +31,7 @@ export default function TopLinks() {
const { queryParams } = useRouterStuff();
const searchParams = useSearchParams();
- const excludeRoot = !!searchParams.get("excludeRoot");
+ const root = searchParams.get("root");
const [showModal, setShowModal] = useState(false);
const barList = (limit?: number) => (
@@ -65,14 +65,16 @@ export default function TopLinks() {
className="max-w-lg"
>
<div className="border-b border-gray-200 px-6 py-4">
- <h1 className="text-lg font-semibold">Top Links</h1>
+ <h1 className="text-lg font-semibold">
+ {tab === "link" ? "Links" : "URLs"}
+ </h1>
</div>
{barList()}
</Modal>
<div className="scrollbar-hide relative z-0 h-[400px] border border-gray-200 bg-white px-7 py-5 sm:rounded-lg sm:border-gray-100 sm:shadow-lg">
<div className="mb-3 flex justify-between">
<h1 className="text-lg font-semibold capitalize">
- Top {tab === "link" ? "Links" : "URLs"}
+ {tab === "link" ? "Links" : "URLs"}
</h1>
{domain && key ? (
!basePath.startsWith("/stats") && (
@@ -92,31 +94,25 @@ export default function TopLinks() {
</Link>
)
) : (
- <Link
- href={
+ <TabSelect
+ options={["Links", "Domains"]}
+ selected={
+ root === "false" ? "Links" : root === "true" ? "Domains" : null
+ }
+ selectAction={(option) =>
queryParams({
- ...(excludeRoot
- ? {
- del: "excludeRoot",
- }
+ ...((root === "false" && option === "Links") ||
+ (root === "true" && option === "Domains")
+ ? { del: ["root"] }
: {
set: {
- excludeRoot: "true",
+ root: option === "Links" ? "false" : "true",
},
}),
- getNewPath: true,
- }) as string
+ replace: true,
+ })
}
- className="flex items-center space-x-2 rounded-lg border border-gray-200 bg-gray-50 px-3 py-1 hover:bg-gray-100"
- >
- <p className="text-sm font-medium">Exclude Root Domains</p>
- <Switch
- checked={excludeRoot}
- trackDimensions="h-3 w-6"
- thumbDimensions="w-2 h-2"
- thumbTranslate="translate-x-3"
- />
- </Link>
+ />
)}
</div>
{data ? (
diff --git a/packages/ui/src/tab-select.tsx b/packages/ui/src/tab-select.tsx
index afaf5f146f..ccdf241ddc 100644
--- a/packages/ui/src/tab-select.tsx
+++ b/packages/ui/src/tab-select.tsx
@@ -7,7 +7,7 @@ export function TabSelect({
selectAction,
}: {
options: string[];
- selected: string;
+ selected: string | null;
selectAction: (option: string) => void;
}) {
return (