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.

Enhance Analytics Filters: Add Referer, add OpenAPI examples

Steven Tey5f858292c7b3
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index a767e4a937..5416a08621 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -92,26 +92,92 @@ export const analyticsQuerySchema = z.object({
.optional()
.describe("The country to retrieve analytics for.")
.openapi({ ref: "countryCode" }),
- city: z.string().optional().describe("The city to retrieve analytics for."),
+ city: z
+ .string()
+ .optional()
+ .describe("The city to retrieve analytics for.")
+ .openapi({
+ examples: [
+ "New York",
+ "Los Angeles",
+ "Chicago",
+ "Houston",
+ "Phoenix",
+ "Philadelphia",
+ "San Antonio",
+ "San Diego",
+ "Dallas",
+ "Tokyo",
+ "Delhi",
+ "Shanghai",
+ "São Paulo",
+ "Mumbai",
+ "Beijing",
+ ],
+ }),
device: z
.string()
.optional()
.transform((v) => capitalize(v) as string | undefined)
- .describe("The device to retrieve analytics for."),
+ .describe("The device to retrieve analytics for.")
+ .openapi({
+ examples: ["Desktop", "Mobile", "Tablet", "Wearable", "Smarttv"],
+ }),
browser: z
.string()
.optional()
.transform((v) => capitalize(v) as string | undefined)
- .describe("The browser to retrieve analytics for."),
+ .describe("The browser to retrieve analytics for.")
+ .openapi({
+ examples: [
+ "Chrome",
+ "Mobile Safari",
+ "Edge",
+ "Instagram",
+ "Firefox",
+ "Facebook",
+ "WebKit",
+ "Samsung Browser",
+ "Chrome WebView",
+ "Safari",
+ "Opera",
+ "IE",
+ "Yandex",
+ ],
+ }),
os: z
.string()
.optional()
.transform((v) => capitalize(v) as string | undefined)
- .describe("The OS to retrieve analytics for."),
+ .describe("The OS to retrieve analytics for.")
+ .openapi({
+ examples: [
+ "Windows",
+ "iOS",
+ "Android",
+ "Mac OS",
+ "Linux",
+ "Ubuntu",
+ "Chromium OS",
+ "Fedora",
+ ],
+ }),
referer: z
.string()
.optional()
- .describe("The referer to retrieve analytics for."),
+ .describe("The referer to retrieve analytics for.")
+ .openapi({
+ examples: [
+ "(direct)",
+ "t.co",
+ "youtube.com",
+ "perplexity.ai",
+ "l.instagram.com",
+ "m.facebook.com",
+ "linkedin.com",
+ "google.com",
+ ],
+ }),
url: z.string().optional().describe("The URL to retrieve analytics for."),
tagId: z
.string()
diff --git a/apps/web/ui/analytics/referer-icon.tsx b/apps/web/ui/analytics/referer-icon.tsx
new file mode 100644
index 0000000000..7458a4042f
--- /dev/null
+++ b/apps/web/ui/analytics/referer-icon.tsx
@@ -0,0 +1,20 @@
+import { cn } from "@dub/utils";
+import { Link2 } from "lucide-react";
+import LinkLogo from "../links/link-logo";
+
+export default function RefererIcon({
+ display,
+ className,
+}: {
+ display: string;
+ className?: string;
+}) {
+ return display === "(direct)" ? (
+ <Link2 className={cn("h-4 w-4", className)} />
+ ) : (
+ <LinkLogo
+ apexDomain={display}
+ className={cn("h-4 w-4 sm:h-4 sm:w-4", className)}
+ />
+ );
+}
diff --git a/apps/web/ui/analytics/referer.tsx b/apps/web/ui/analytics/referer.tsx
index cbbef5ebed..ba6178a7c0 100644
--- a/apps/web/ui/analytics/referer.tsx
+++ b/apps/web/ui/analytics/referer.tsx
@@ -5,6 +5,7 @@ import { useState } from "react";
import { AnalyticsCard } from "./analytics-card";
import { AnalyticsLoadingSpinner } from "./analytics-loading-spinner";
import BarList from "./bar-list";
+import RefererIcon from "./referer-icon";
import { useAnalyticsFilterOption } from "./utils";
function RefererOld() {
@@ -18,18 +19,7 @@ function RefererOld() {
tab="Referrer"
data={
data?.map((d) => ({
- icon:
- d.referer === "(direct)" ? (
- <Link2 className="h-4 w-4" />
- ) : (
- <BlurImage
- src={`${GOOGLE_FAVICON_URL}${d.referer}`}
- alt={d.referer}
- width={20}
- height={20}
- className="h-4 w-4 rounded-full"
- />
- ),
+ icon: <RefererIcon display={d.referer} />,
title: d.referer,
href: queryParams({
set: {
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index 1800eeaf2e..ecca9dafef 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -30,6 +30,7 @@ import {
MobilePhone,
OfficeBuilding,
QRCode,
+ ReferredVia,
Tag,
Window,
} from "@dub/ui/src/icons";
@@ -59,6 +60,7 @@ import LinkLogo from "../links/link-logo";
import { COLORS_LIST } from "../links/tag-badge";
import DeviceIcon from "./device-icon";
import ExportButton from "./export-button";
+import RefererIcon from "./referer-icon";
import SharePopover from "./share-popover";
import { useAnalyticsFilterOption } from "./utils";
@@ -79,8 +81,18 @@ export default function Toggle() {
const [requestedFilters, setRequestedFilters] = useState<string[]>([]);
const activeFilters = useMemo(() => {
- const { domain, tagId, qr, country, city, device, browser, os, key } =
- searchParamsObj;
+ const {
+ domain,
+ key,
+ tagId,
+ qr,
+ country,
+ city,
+ device,
+ browser,
+ os,
+ referer,
+ } = searchParamsObj;
return [
...(domain && !key ? [{ key: "domain", value: domain }] : []),
...(domain && key
@@ -93,6 +105,7 @@ export default function Toggle() {
...(device ? [{ key: "device", value: device }] : []),
...(browser ? [{ key: "browser", value: browser }] : []),
...(os ? [{ key: "os", value: os }] : []),
+ ...(referer ? [{ key: "referer", value: referer }] : []),
];
}, [searchParamsObj]);
@@ -121,6 +134,9 @@ export default function Toggle() {
const os = useAnalyticsFilterOption("os", {
cacheOnly: !isRequested("os"),
});
+ const referers = useAnalyticsFilterOption("referers", {
+ cacheOnly: !isRequested("referers"),
+ });
// Some suggestions will only appear if previously requested (see isRequested above)
const aiFilterSuggestions = useMemo(
@@ -130,11 +146,11 @@ export default function Toggle() {
icon: Globe,
},
{
- value: "Mobile Chrome users, US only",
+ value: "Mobile users, US only",
icon: MobilePhone,
},
{
- value: "Capital of Japan, last 3 months",
+ value: "Tokyo, Chrome users",
icon: OfficeBuilding,
},
{
@@ -275,6 +291,7 @@ export default function Toggle() {
icon: QRCode,
},
],
+ separatorAfter: true,
},
{
key: "country",
@@ -359,6 +376,20 @@ export default function Toggle() {
right: nFormatter(count, { full: true }),
})) ?? null,
},
+ {
+ key: "referer",
+ icon: ReferredVia,
+ label: "Referer",
+ getOptionIcon: (value, props) => (
+ <RefererIcon display={value} className="h-4 w-4" />
+ ),
+ options:
+ referers?.map(({ referer, count }) => ({
+ value: referer,
+ label: referer,
+ right: nFormatter(count, { full: true }),
+ })) ?? null,
+ },
],
[
isPublicStatsPage,
@@ -371,6 +402,7 @@ export default function Toggle() {
devices,
browsers,
os,
+ referers,
],
);
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index e15e9561ad..d252a53f2f 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -8,5 +8,6 @@ export * from "./invoice-dollar";
export * from "./mobile-phone";
export * from "./office-building";
export * from "./qrcode";
+export * from "./referred-via";
export * from "./tag";
export * from "./window";
diff --git a/packages/ui/src/icons/nucleo/referred-via.tsx b/packages/ui/src/icons/nucleo/referred-via.tsx
new file mode 100644
index 0000000000..38e2f29b9e
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/referred-via.tsx
@@ -0,0 +1,40 @@
+import { SVGProps } from "react";
+
+export function ReferredVia(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <path
+ d="M2.75,10.75v2.5c0,1.105,.895,2,2,2H15.25"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ d="M15,6h-4c-2.347,0-4.25,1.903-4.25,4.25h0"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <polyline
+ fill="none"
+ points="12 2.75 15.25 6 12 9.25"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ </g>
+ </svg>
+ );
+}