@@ -167,6 +167,11 @@ export default async function LinkMiddleware(
167167
168168 const url = testUrl || cachedLink . url ;
169169
170+ // we only pass the clickId if:
171+ // - trackConversion is enabled
172+ // - it's a partner link
173+ const shouldPassClickId = trackConversion || isPartnerLink ;
174+
170175 // by default, we only index default dub domain links (e.g. dub.sh)
171176 // everything else is not indexed by default, unless the user has explicitly set it to be indexed
172177 const shouldIndex = isDubDomain ( domain ) || doIndex === true ;
@@ -244,8 +249,8 @@ export default async function LinkMiddleware(
244249 const cookieStore = cookies ( ) ;
245250 let clickId = cookieStore . get ( dubIdCookieName ) ?. value ;
246251 if ( ! clickId ) {
247- // if trackConversion is enabled , check if clickId is cached in Redis
248- if ( trackConversion ) {
252+ // if we need to pass the clickId , check if clickId is cached in Redis
253+ if ( shouldPassClickId ) {
249254 const ip = process . env . VERCEL === "1" ? ipAddress ( req ) : LOCALHOST_IP ;
250255
251256 clickId = ( await clickCache . get ( { domain, key, ip } ) ) || undefined ;
@@ -276,7 +281,7 @@ export default async function LinkMiddleware(
276281 url,
277282 webhookIds,
278283 workspaceId,
279- trackConversion ,
284+ shouldPassClickId ,
280285 } ) ,
281286 ) ;
282287
@@ -297,12 +302,6 @@ export default async function LinkMiddleware(
297302 const { country } =
298303 process . env . VERCEL === "1" && req . geo ? req . geo : LOCALHOST_GEO_DATA ;
299304
300- // we only pass the clickId if:
301- // - trackConversion is enabled
302- // - not a partner link (TODO: add this later) !isPartnerLink
303- // - there is a clickId
304- const shouldPassClickId = trackConversion && clickId ;
305-
306305 // rewrite to proxy page (/proxy/[domain]/[key]) if it's a bot and proxy is enabled
307306 if ( isBot && proxy ) {
308307 return createResponseWithCookies (
@@ -330,7 +329,7 @@ export default async function LinkMiddleware(
330329 url,
331330 webhookIds,
332331 workspaceId,
333- trackConversion ,
332+ shouldPassClickId ,
334333 } ) ,
335334 ) ;
336335
@@ -368,7 +367,7 @@ export default async function LinkMiddleware(
368367 url,
369368 webhookIds,
370369 workspaceId,
371- trackConversion ,
370+ shouldPassClickId ,
372371 } ) ,
373372 ) ;
374373
@@ -408,7 +407,7 @@ export default async function LinkMiddleware(
408407 url : ios ,
409408 webhookIds,
410409 workspaceId,
411- trackConversion ,
410+ shouldPassClickId ,
412411 } ) ,
413412 ) ;
414413
@@ -442,7 +441,7 @@ export default async function LinkMiddleware(
442441 url : android ,
443442 webhookIds,
444443 workspaceId,
445- trackConversion ,
444+ shouldPassClickId ,
446445 } ) ,
447446 ) ;
448447
@@ -476,7 +475,7 @@ export default async function LinkMiddleware(
476475 url : geo [ country ] ,
477476 webhookIds,
478477 workspaceId,
479- trackConversion ,
478+ shouldPassClickId ,
480479 } ) ,
481480 ) ;
482481
@@ -510,7 +509,7 @@ export default async function LinkMiddleware(
510509 url,
511510 webhookIds,
512511 workspaceId,
513- trackConversion ,
512+ shouldPassClickId ,
514513 } ) ,
515514 ) ;
516515
@@ -521,7 +520,7 @@ export default async function LinkMiddleware(
521520 headers : new Headers ( {
522521 destination : getFinalUrl ( url , {
523522 req,
524- clickId : trackConversion ? clickId : undefined ,
523+ clickId : shouldPassClickId ? clickId : undefined ,
525524 } ) ,
526525 } ) ,
527526 } ,
0 commit comments