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 clickId

Steven Tey80c813f20aa5
diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.ts
index 763d7ce2f3..3c5f02179b 100644
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@ -207,19 +207,19 @@ export default async function LinkMiddleware(
}
}
- const cookieStore = cookies();
- let clickId = cookieStore.get("dub_id")?.value;
- if (!clickId) {
- // if trackConversion is enabled, check if clickId is cached in Redis
- if (trackConversion) {
- const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP;
+ let clickId;
+ // for links with trackConversion enabled, always check
+ if (trackConversion) {
+ const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP;
+ clickId = (await clickCache.get({ domain, key, ip })) || undefined;
+ } else {
+ const cookieStore = cookies();
+ clickId = cookieStore.get("dub_id")?.value;
+ }
- clickId = (await clickCache.get({ domain, key, ip })) || undefined;
- }
- // if there's still no clickId, generate a new one
- if (!clickId) {
- clickId = nanoid(16);
- }
+ // if there's still no clickId, generate a new one
+ if (!clickId) {
+ clickId = nanoid(16);
}
// for root domain links, if there's no destination URL, rewrite to placeholder page