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.

Merge branch 'main' into ab-testing

Steven Tey517dddef8b9d
diff --cc apps/web/lib/middleware/link.ts
index a52523c5b5,c552d867f9..edd6a196a5
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@@ -216,8 -207,10 +216,10 @@@ export default async function LinkMiddl
}
}
- const cookieName = `dub_id_${domain}_${key}`;
++ const dubIdCookieName = `dub_id_${domain}_${key}`;
+
const cookieStore = cookies();
- let clickId = cookieStore.get("dub_id")?.value;
- let clickId = cookieStore.get(cookieName)?.value;
++ let clickId = cookieStore.get(dubIdCookieName)?.value;
if (!clickId) {
// if trackConversion is enabled, check if clickId is cached in Redis
if (trackConversion) {
@@@ -231,6 -225,12 +234,13 @@@
}
}
+ const cookieData = {
- name: cookieName,
- value: clickId,
+ path: `/${originalKey}`,
++ dubIdCookieName,
++ dubIdCookieValue: clickId,
++ dubTestUrlValue: testUrl,
+ };
+
// for root domain links, if there's no destination URL, rewrite to placeholder page
if (!url) {
ev.waitUntil(
@@@ -471,22 -471,19 +481,22 @@@
);
if (hasEmptySearchParams(url)) {
- return NextResponse.rewrite(new URL("/api/patch-redirect", req.url), {
- request: {
- headers: new Headers({
- destination: getFinalUrl(url, {
- req,
- clickId: trackConversion ? clickId : undefined,
+ return createResponseWithCookies(
+ NextResponse.rewrite(new URL("/api/patch-redirect", req.url), {
+ request: {
+ headers: new Headers({
+ destination: getFinalUrl(url, {
+ req,
+ clickId: trackConversion ? clickId : undefined,
+ }),
}),
- }),
- },
- });
+ },
+ }),
- { path: `/${originalKey}`, testUrl },
++ cookieData,
+ );
}
- return createResponseWithCookie(
+ return createResponseWithCookies(
NextResponse.redirect(
getFinalUrl(url, {
req,