The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add `all_unfiltered` support for API
Kiran K32e2bd912818
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.tsindex 861ac4c7c3..4a6968591b 100644--- a/apps/web/lib/analytics/constants.ts+++ b/apps/web/lib/analytics/constants.ts@@ -7,6 +7,7 @@ export const intervals = ["ytd","1y","all",+ "all_unfiltered",] as const;export const INTERVAL_DISPLAYS = [diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.tsindex 25dc5ada5d..8e6f3516a4 100644--- a/apps/web/lib/analytics/get-analytics.ts+++ b/apps/web/lib/analytics/get-analytics.ts@@ -1,7 +1,6 @@import { tb } from "@/lib/tinybird";import z from "@/lib/zod";import { getDaysDifference } from "@dub/utils";-import { headers } from "next/headers";import { conn } from "../planetscale";import { tbDemo } from "../tinybird/demo-client";import {@@ -47,27 +46,21 @@ export const getAnalytics = async (params: AnalyticsFilters) => {// 2. linkId is defined// 3. interval is all time// 4. call is made from dashboard- if (- groupBy === "count" &&- linkId &&- interval === "all" &&- headers()?.get("Request-Source") === "app.dub.co"- ) {+ if (linkId && groupBy === "count" && interval === "all_unfiltered") {+ const columns = event === "composite" ? `clicks, leads, sales` : `${event}`;+let response = await conn.execute(- "SELECT clicks FROM Link WHERE `id` = ?",+ `SELECT ${columns} FROM Link WHERE id = ?`,[linkId],);- if (response.rows.length === 0) {- response = await conn.execute(- "SELECT clicks FROM Domain WHERE `id` = ?",- [linkId],- );- if (response.rows.length === 0) {- return 0;- }+ if (response.rows.length === 0 && event === "clicks") {+ response = await conn.execute(`SELECT clicks FROM Domain WHERE id = ?`, [+ linkId,+ ]);}- return response.rows[0]["clicks"];++ return response.rows[0];}let granularity: "minute" | "hour" | "day" | "month" = "day";