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.

handle special tabs, fix export

Steven Tey654088b3ce68
diff --git a/apps/web/app/api/analytics/export/route.ts b/apps/web/app/api/analytics/export/route.ts
index 326bcdb5f4..8aa7a9e789 100644
--- a/apps/web/app/api/analytics/export/route.ts
+++ b/apps/web/app/api/analytics/export/route.ts
@@ -1,4 +1,9 @@
-import { VALID_ANALYTICS_ENDPOINTS, getClicks } from "@/lib/analytics";
+import {
+ AnalyticsEndpoints,
+ DEPRECATED_ANALYTICS_ENDPOINTS,
+ VALID_ANALYTICS_ENDPOINTS,
+ getClicks,
+} from "@/lib/analytics";
import { DubApiError } from "@/lib/api/errors";
import { withWorkspace } from "@/lib/auth";
import { getDomainViaEdge } from "@/lib/planetscale";
@@ -121,11 +126,15 @@ export const GET = withWorkspace(
} else {
// we're not fetching top URLs data if linkId is not defined
if (endpoint === "top_urls" && !linkId) return;
+ // skip clicks count
+ if (endpoint === "count") return;
+ // skip deprecated endpoints
+ if (DEPRECATED_ANALYTICS_ENDPOINTS.includes(endpoint)) return;
const response = await getClicks({
workspaceId: workspace.id,
...(linkId && { linkId }),
- endpoint,
+ endpoint: endpoint as AnalyticsEndpoints,
...parsedParams,
});
if (!response || response.length === 0) return;
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.ts
index 03ebee9f7c..8b8f8d22e2 100644
--- a/apps/web/lib/analytics/constants.ts
+++ b/apps/web/lib/analytics/constants.ts
@@ -104,6 +104,14 @@ export const VALID_ANALYTICS_ENDPOINTS = [
"top_urls",
] as const;
+export const DEPRECATED_ANALYTICS_ENDPOINTS = [
+ "country",
+ "city",
+ "device",
+ "browser",
+ "referer",
+];
+
export const VALID_ANALYTICS_FILTERS = [
"country",
"city",
diff --git a/apps/web/ui/analytics/export-button.tsx b/apps/web/ui/analytics/export-button.tsx
index c57b8cf942..563aa016b0 100644
--- a/apps/web/ui/analytics/export-button.tsx
+++ b/apps/web/ui/analytics/export-button.tsx
@@ -7,12 +7,12 @@ import { AnalyticsContext } from ".";
export default function ExportButton() {
const [loading, setLoading] = useState(false);
const { totalClicks } = useContext(AnalyticsContext);
- const { baseApiPath, queryString } = useContext(AnalyticsContext);
+ const { queryString } = useContext(AnalyticsContext);
async function exportData() {
setLoading(true);
try {
- const response = await fetch(`${baseApiPath}/export?${queryString}`, {
+ const response = await fetch(`/api/analytics/export?${queryString}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
@@ -20,6 +20,7 @@ export default function ExportButton() {
});
if (!response.ok) {
+ setLoading(false);
throw new Error(response.statusText);
}
diff --git a/packages/ui/src/tab-select.tsx b/packages/ui/src/tab-select.tsx
index ccdf241ddc..4b435319de 100644
--- a/packages/ui/src/tab-select.tsx
+++ b/packages/ui/src/tab-select.tsx
@@ -23,7 +23,9 @@ export function TabSelect({
)}
onClick={() => selectAction(option)}
>
- <p>{option}</p>
+ <p>
+ {option === "devices" ? "Type" : option === "os" ? "OS" : option}
+ </p>
{option === selected && (
<motion.div
layoutId={options.join("-")}