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.

Use link data if interval="all"

Steven Tey49d9f6359bbf
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.ts
index 4ade6daeff..868df62762 100644
--- a/apps/web/lib/analytics/constants.ts
+++ b/apps/web/lib/analytics/constants.ts
@@ -10,7 +10,6 @@ export const intervals = [
"qtd",
"ytd",
"all",
- "all_unfiltered",
] as const;
export const eventIntervals = [
@@ -187,7 +186,7 @@ export const VALID_ANALYTICS_FILTERS = [
"tagId",
"folderId",
"tagIds",
- "qr",
+ "qr", // deprecated, but keeping for now for backwards compatibility
"root",
"utm_source",
"utm_medium",
@@ -196,6 +195,27 @@ export const VALID_ANALYTICS_FILTERS = [
"utm_content",
];
+// possible analytics filters for a given linkId
+export const DIMENSIONAL_ANALYTICS_FILTERS = [
+ "country",
+ "city",
+ "region",
+ "continent",
+ "device",
+ "browser",
+ "os",
+ "trigger",
+ "referer",
+ "refererUrl",
+ "url",
+ "qr", // deprecated, but keeping for now for backwards compatibility
+ "utm_source",
+ "utm_medium",
+ "utm_campaign",
+ "utm_term",
+ "utm_content",
+];
+
export const TRIGGER_DISPLAY = {
qr: "QR Scan",
link: "Link Click",
diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.ts
index 9a0be148a9..50a8528ca4 100644
--- a/apps/web/lib/analytics/get-analytics.ts
+++ b/apps/web/lib/analytics/get-analytics.ts
@@ -7,7 +7,10 @@ import { conn } from "../planetscale";
import z from "../zod";
import { analyticsFilterTB } from "../zod/schemas/analytics";
import { analyticsResponse } from "../zod/schemas/analytics-response";
-import { SINGULAR_ANALYTICS_ENDPOINTS } from "./constants";
+import {
+ DIMENSIONAL_ANALYTICS_FILTERS,
+ SINGULAR_ANALYTICS_ENDPOINTS,
+} from "./constants";
import { AnalyticsFilters } from "./types";
import { getStartEndDates } from "./utils/get-start-end-dates";
@@ -35,8 +38,16 @@ export const getAnalytics = async (params: AnalyticsFilters) => {
// get all-time clicks count if:
// 1. linkId is defined
// 2. type is count
- // 3. interval is all_unfiltered
- if (linkId && groupBy === "count" && interval === "all_unfiltered") {
+ // 3. interval is all
+ // 4. no other dimensional filters are applied
+ if (
+ linkId &&
+ groupBy === "count" &&
+ interval === "all" &&
+ DIMENSIONAL_ANALYTICS_FILTERS.every(
+ (filter) => !params[filter as keyof AnalyticsFilters],
+ )
+ ) {
const columns =
event === "composite"
? `clicks, leads, sales, saleAmount`
diff --git a/apps/web/ui/links/link-details-column.tsx b/apps/web/ui/links/link-details-column.tsx
index d3bbd9db59..3aa7a60f36 100644
--- a/apps/web/ui/links/link-details-column.tsx
+++ b/apps/web/ui/links/link-details-column.tsx
@@ -201,7 +201,7 @@ function AnalyticsBadge({ link }: { link: ResponseLink }) {
return isMobile ? (
<Link
- href={`/${slug}/analytics?domain=${domain}&key=${key}&interval=${plan === "free" ? "30d" : plan === "pro" ? "1y" : "all"}`}
+ href={`/${slug}/analytics?domain=${domain}&key=${key}`}
className="flex items-center gap-1 rounded-md border border-neutral-200 bg-neutral-50 px-2 py-0.5 text-sm text-neutral-800"
>
<CursorRays className="h-4 w-4 text-neutral-600" />