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.

match /analytics/export to /analytics

Steven Tey082caec0a8f7
diff --git a/apps/web/app/api/analytics/export/route.ts b/apps/web/app/api/analytics/export/route.ts
index 23945da714..2a378abf21 100644
--- a/apps/web/app/api/analytics/export/route.ts
+++ b/apps/web/app/api/analytics/export/route.ts
@@ -6,6 +6,7 @@ import { getLinkOrThrow } from "@/lib/api/links/get-link-or-throw";
import { throwIfClicksUsageExceeded } from "@/lib/api/links/usage-checks";
import { withWorkspace } from "@/lib/auth";
import { analyticsQuerySchema } from "@/lib/zod/schemas/analytics";
+import { Link } from "@prisma/client";
import JSZip from "jszip";
// GET /api/analytics/export – get export data for analytics
@@ -15,14 +16,24 @@ export const GET = withWorkspace(
const parsedParams = analyticsQuerySchema.parse(searchParams);
- const { interval, start, end, linkId, domain, key } = parsedParams;
+ const { interval, start, end, linkId, externalId, domain, key } =
+ parsedParams;
+
+ let link: Link | null = null;
if (domain) {
await getDomainOrThrow({ workspace, domain });
}
- const link =
- domain && key ? await getLinkOrThrow({ workspace, domain, key }) : null;
+ if (linkId || externalId || (domain && key)) {
+ link = await getLinkOrThrow({
+ workspace: workspace,
+ linkId,
+ externalId,
+ domain,
+ key,
+ });
+ }
validDateRangeForPlan({
plan: workspace.plan,
@@ -36,11 +47,11 @@ export const GET = withWorkspace(
await Promise.all(
VALID_ANALYTICS_ENDPOINTS.map(async (endpoint) => {
- // no need to fetch top links data if linkId is defined
+ // no need to fetch top links data if there's a link specified
// since this is just a single link
- if (endpoint === "top_links" && linkId) return;
- // we're not fetching top URLs data if linkId is not defined
- if (endpoint === "top_urls" && !linkId) return;
+ if (endpoint === "top_links" && link) return;
+ // we're not fetching top URLs data if there's no link specified
+ if (endpoint === "top_urls" && !link) return;
// skip clicks count
if (endpoint === "count") return;