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.

update stats edge api route

Steven Teyc08ac126fa52
diff --git a/apps/web/app/api/edge/stats/[endpoint]/route.ts b/apps/web/app/api/edge/stats/[endpoint]/route.ts
index 2ab0602710..069c053606 100644
--- a/apps/web/app/api/edge/stats/[endpoint]/route.ts
+++ b/apps/web/app/api/edge/stats/[endpoint]/route.ts
@@ -1,4 +1,4 @@
-import { getSearchParams } from "@dub/utils";
+import { DEMO_LINK_ID, DUB_PROJECT_ID, getSearchParams } from "@dub/utils";
import { isBlacklistedReferrer } from "@/lib/edge-config";
import { getLinkViaEdge } from "@/lib/planetscale";
import { getStats } from "@/lib/stats";
@@ -17,6 +17,8 @@ export const GET = async (
const searchParams = getSearchParams(req.url);
const { domain, key, interval } = searchParams;
+ let link;
+
// demo link (dub.sh/try)
if (domain === "dub.sh" && key === "try") {
// Rate limit in production
@@ -34,10 +36,15 @@ export const GET = async (
return new Response("Don't DDoS me pls 🥺", { status: 429 });
}
}
+
+ link = {
+ id: DEMO_LINK_ID,
+ projectId: DUB_PROJECT_ID,
+ };
} else {
- const data = await getLinkViaEdge(domain, key);
+ link = await getLinkViaEdge(domain, key);
// if the link is explicitly private (publicStats === false)
- if (data?.publicStats === 0) {
+ if (!link?.publicStats) {
return new Response(`Stats for this link are not public`, {
status: 403,
});
@@ -49,8 +56,8 @@ export const GET = async (
}
const response = await getStats({
- domain,
- key,
+ projectId: link.projectId,
+ linkId: link.id,
endpoint,
interval,
...searchParams,
diff --git a/apps/web/ui/stats/index.tsx b/apps/web/ui/stats/index.tsx
index ace1d8a70d..2c877dc9d4 100644
--- a/apps/web/ui/stats/index.tsx
+++ b/apps/web/ui/stats/index.tsx
@@ -73,21 +73,14 @@ export default function Stats({
baseApiPath: `/api/projects/${slug}/stats`,
domain: domainSlug,
};
- // Generic links analytics page, e.g. app.dub.co/analytics?domain=dub.sh&key=github
- } else if (pathname === "/analytics") {
+ } else {
+ // Public stats page, e.g. dub.co/stats/github, stey.me/stats/weathergpt
return {
- basePath: `/analytics`,
- baseApiPath: `/api/stats`,
- domain: domainSlug,
+ basePath: `/stats/${key}`,
+ baseApiPath: `/api/edge/stats`,
+ domain: staticDomain,
};
}
-
- // Public stats page, e.g. dub.co/stats/github, stey.me/stats/weathergpt
- return {
- basePath: `/stats/${key}`,
- baseApiPath: `/api/edge/stats`,
- domain: staticDomain,
- };
}, [slug, pathname, staticDomain, domainSlug, key]);
const queryString = useMemo(() => {
@@ -141,10 +134,9 @@ export default function Stats({
<Clicks />
<div className="grid grid-cols-1 gap-5 md:grid-cols-2">
<Locations />
- {slug && <TopLinks />}
+ <TopLinks />
<Devices />
<Referer />
- {!slug && <Feedback />}
</div>
</div>
</div>
diff --git a/packages/utils/src/constants/index.ts b/packages/utils/src/constants/index.ts
index d858df7674..dae2bc3503 100644
--- a/packages/utils/src/constants/index.ts
+++ b/packages/utils/src/constants/index.ts
@@ -215,6 +215,7 @@ export const DEFAULT_LINK_PROPS = {
proxy: false,
};
+export const DEMO_LINK_ID = "clqo10sum0006js08vutzfxt3";
export const DUB_PROJECT_ID = "cl7pj5kq4006835rbjlt2ofka";
export const LEGAL_USER_ID = "clqei1lgc0000vsnzi01pbf47";