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.

fix issue with root

Steven Tey46b1c0f7aef4
diff --git a/apps/web/lib/middleware/root.ts b/apps/web/lib/middleware/root.ts
index 0713886f14..9923f6b038 100644
--- a/apps/web/lib/middleware/root.ts
+++ b/apps/web/lib/middleware/root.ts
@@ -36,10 +36,10 @@ export default async function RootMiddleware(
);
}
- const { id, url, rewrite, iframeable } = link;
+ const { id: linkId, url, rewrite, iframeable } = link;
// record clicks on root page
- ev.waitUntil(recordClick({ req, id, ...(url && { url }), root: true }));
+ ev.waitUntil(recordClick({ req, linkId, ...(url && { url }), root: true }));
if (!url) {
// rewrite to placeholder page unless the user defines a site to redirect to
diff --git a/apps/web/lib/tinybird.ts b/apps/web/lib/tinybird.ts
index ddcb3001da..c691382312 100644
--- a/apps/web/lib/tinybird.ts
+++ b/apps/web/lib/tinybird.ts
@@ -6,6 +6,7 @@ import {
getDomainWithoutWWW,
} from "@dub/utils";
import { ipAddress } from "@vercel/edge";
+import { nanoid } from "ai";
import { NextRequest, userAgent } from "next/server";
import { detectBot, detectQr, getIdentityHash } from "./middleware/utils";
import { conn } from "./planetscale";
@@ -24,7 +25,7 @@ export async function recordClick({
}: {
req: NextRequest;
linkId: string;
- clickId: string;
+ clickId?: string;
url?: string;
root?: boolean;
}) {
@@ -59,7 +60,7 @@ export async function recordClick({
body: JSON.stringify({
timestamp: new Date(Date.now()).toISOString(),
identity_hash,
- click_id: clickId,
+ click_id: clickId || nanoid(16),
link_id: linkId,
alias_link_id: "",
url: url || "",