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.

Analytics breakdown by trigger

Steven Teyb9123c9da641
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.ts
index 67d935ab5f..3922c3fe63 100644
--- a/apps/web/lib/analytics/constants.ts
+++ b/apps/web/lib/analytics/constants.ts
@@ -122,6 +122,12 @@ export const SINGULAR_ANALYTICS_ENDPOINTS = {
referers: "referer",
referer_urls: "refererUrl",
os: "os",
+ trigger: "qr",
+};
+
+export const TRIGGER_DISPLAY = {
+ qr: "QR Scan",
+ link: "Link Click",
};
export const VALID_ANALYTICS_FILTERS = [
diff --git a/apps/web/lib/analytics/types.ts b/apps/web/lib/analytics/types.ts
index 1b632c4895..0bf28ac8af 100644
--- a/apps/web/lib/analytics/types.ts
+++ b/apps/web/lib/analytics/types.ts
@@ -27,7 +27,7 @@ export type AnalyticsView = (typeof ANALYTICS_VIEWS)[number];
export type LocationTabs = "countries" | "cities";
export type TopLinksTabs = "link" | "url";
-export type DeviceTabs = "devices" | "browsers" | "os";
+export type DeviceTabs = "devices" | "browsers" | "os" | "trigger";
export type RefererTabs = "referers" | "referer_urls";
export type AnalyticsFilters = z.infer<typeof analyticsQuerySchema> & {
diff --git a/apps/web/ui/analytics/device-icon.tsx b/apps/web/ui/analytics/device-icon.tsx
index ba8275f16e..2e0b94039e 100644
--- a/apps/web/ui/analytics/device-icon.tsx
+++ b/apps/web/ui/analytics/device-icon.tsx
@@ -2,9 +2,11 @@ import { DeviceTabs } from "@/lib/analytics/types";
import { Apple, Chrome, Safari } from "@/ui/shared/icons/devices";
import { BlurImage } from "@dub/ui";
import {
+ CursorRays,
Desktop,
GamingConsole,
MobilePhone,
+ QRCode,
TV,
Tablet,
Watch,
@@ -76,6 +78,12 @@ export default function DeviceIcon({
/>
);
}
+ } else if (tab === "trigger") {
+ if (display === "qr") {
+ return <QRCode className={className} />;
+ } else {
+ return <CursorRays className={className} />;
+ }
} else {
return (
<BlurImage
diff --git a/apps/web/ui/analytics/devices.tsx b/apps/web/ui/analytics/devices.tsx
index 4523006924..54210f0723 100644
--- a/apps/web/ui/analytics/devices.tsx
+++ b/apps/web/ui/analytics/devices.tsx
@@ -1,4 +1,7 @@
-import { SINGULAR_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
+import {
+ SINGULAR_ANALYTICS_ENDPOINTS,
+ TRIGGER_DISPLAY,
+} from "@/lib/analytics/constants";
import { DeviceTabs } from "@/lib/analytics/types";
import { useRouterStuff } from "@dub/ui";
import { useContext, useState } from "react";
@@ -25,6 +28,7 @@ export default function Devices() {
{ id: "devices", label: "Devices" },
{ id: "browsers", label: "Browsers" },
{ id: "os", label: "OS" },
+ { id: "trigger", label: "Trigger" },
]}
selectedTabId={tab}
onSelectTab={setTab}
@@ -46,11 +50,17 @@ export default function Devices() {
className="h-4 w-4"
/>
),
- title: d[singularTabName],
+ title:
+ tab === "trigger"
+ ? TRIGGER_DISPLAY[d.trigger]
+ : d[singularTabName],
href: queryParams({
- set: {
- [singularTabName]: d[singularTabName],
- },
+ set:
+ tab === "trigger"
+ ? {
+ qr: d.trigger === "link" ? "false" : "true",
+ }
+ : { [singularTabName]: d[singularTabName] },
getNewPath: true,
}) as string,
value: d[dataKey] || 0,
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index d4d1700f19..f724c3ca7c 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -2,6 +2,7 @@ import { generateFilters } from "@/lib/ai/generate-filters";
import {
INTERVAL_DATA,
INTERVAL_DISPLAYS,
+ TRIGGER_DISPLAY,
VALID_ANALYTICS_FILTERS,
} from "@/lib/analytics/constants";
import { validDateRangeForPlan } from "@/lib/analytics/utils";
@@ -168,6 +169,9 @@ export default function Toggle({
const os = useAnalyticsFilterOption("os", {
cacheOnly: !isRequested("os"),
});
+ const trigger = useAnalyticsFilterOption("trigger", {
+ cacheOnly: !isRequested("trigger"),
+ });
const referers = useAnalyticsFilterOption("referers", {
cacheOnly: !isRequested("referer"),
});
@@ -330,18 +334,13 @@ export default function Toggle({
key: "qr",
icon: CursorRays,
label: "Trigger",
- options: [
- {
- value: false,
- label: "Link click",
- icon: CursorRays,
- },
- {
- value: true,
- label: "QR Scan",
- icon: QRCode,
- },
- ],
+ options:
+ trigger?.map(({ trigger, count }) => ({
+ value: trigger,
+ label: TRIGGER_DISPLAY[trigger],
+ icon: trigger === "qr" ? QRCode : CursorRays,
+ right: nFormatter(count, { full: true }),
+ })) ?? null,
separatorAfter: !isPublicStatsPage,
},
{