The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Rename shouldPassClickId to shouldCacheClickId
Steven Teycade68f97d7d
diff --git a/apps/web/app/(ee)/api/track/click/route.ts b/apps/web/app/(ee)/api/track/click/route.tsindex 3375fb0885..a9eca60b35 100644--- a/apps/web/app/(ee)/api/track/click/route.ts+++ b/apps/web/app/(ee)/api/track/click/route.ts@@ -141,7 +141,7 @@ export const POST = withAxiom(async (req: AxiomRequest) => {workspaceId: cachedLink.projectId,skipRatelimit: true,...(referrer && { referrer }),- shouldPassClickId: true,+ shouldCacheClickId: true,});}diff --git a/apps/web/app/(ee)/api/track/visit/route.ts b/apps/web/app/(ee)/api/track/visit/route.tsindex 3b91555d84..1aa5ce07b9 100644--- a/apps/web/app/(ee)/api/track/visit/route.ts+++ b/apps/web/app/(ee)/api/track/visit/route.ts@@ -98,7 +98,7 @@ export const POST = withAxiom(async (req: AxiomRequest) => {workspaceId: cachedLink.projectId,skipRatelimit: true,...(referrer && { referrer }),- shouldPassClickId: true,+ shouldCacheClickId: true,});}})(),diff --git a/apps/web/lib/middleware/link.ts b/apps/web/lib/middleware/link.tsindex 68acddbd8b..0f7aa2bfe4 100644--- a/apps/web/lib/middleware/link.ts+++ b/apps/web/lib/middleware/link.ts@@ -167,7 +167,7 @@ export default async function LinkMiddleware(// we only pass the clickId if:// - trackConversion is enabled// - it's a partner link- const shouldPassClickId = trackConversion || isPartnerLink;+ const shouldCacheClickId = trackConversion || isPartnerLink;// by default, we only index default dub domain links (e.g. dub.sh)// everything else is not indexed by default, unless the user has explicitly set it to be indexed@@ -247,7 +247,7 @@ export default async function LinkMiddleware(let clickId = cookieStore.get(dubIdCookieName)?.value;if (!clickId) {// if we need to pass the clickId, check if clickId is cached in Redis- if (shouldPassClickId) {+ if (shouldCacheClickId) {const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP;clickId = (await recordClickCache.get({ domain, key, ip })) || undefined;@@ -278,7 +278,7 @@ export default async function LinkMiddleware(url,webhookIds,workspaceId,- shouldPassClickId,+ shouldCacheClickId,}),);@@ -326,7 +326,7 @@ export default async function LinkMiddleware(url,webhookIds,workspaceId,- shouldPassClickId,+ shouldCacheClickId,}),);@@ -336,7 +336,7 @@ export default async function LinkMiddleware(`/deeplink/${encodeURIComponent(getFinalUrl(url, {req,- ...(shouldPassClickId && { clickId }),+ ...(shouldCacheClickId && { clickId }),...(isPartnerLink && { via: key }),}),)}`,@@ -364,7 +364,7 @@ export default async function LinkMiddleware(url,webhookIds,workspaceId,- shouldPassClickId,+ shouldCacheClickId,}),);@@ -374,7 +374,7 @@ export default async function LinkMiddleware(`/cloaked/${encodeURIComponent(getFinalUrl(url, {req,- ...(shouldPassClickId && { clickId }),+ ...(shouldCacheClickId && { clickId }),...(isPartnerLink && { via: key }),}),)}`,@@ -404,7 +404,7 @@ export default async function LinkMiddleware(url: ios,webhookIds,workspaceId,- shouldPassClickId,+ shouldCacheClickId,}),);@@ -412,7 +412,7 @@ export default async function LinkMiddleware(NextResponse.redirect(getFinalUrl(ios, {req,- ...(shouldPassClickId && { clickId }),+ ...(shouldCacheClickId && { clickId }),...(isPartnerLink && { via: key }),}),{@@ -438,7 +438,7 @@ export default async function LinkMiddleware(url: android,webhookIds,workspaceId,- shouldPassClickId,+ shouldCacheClickId,}),);@@ -446,7 +446,7 @@ export default async function LinkMiddleware(NextResponse.redirect(getFinalUrl(android, {req,- ...(shouldPassClickId && { clickId }),+ ...(shouldCacheClickId && { clickId }),...(isPartnerLink && { via: key }),}),{@@ -472,7 +472,7 @@ export default async function LinkMiddleware(url: geo[country],webhookIds,workspaceId,- shouldPassClickId,+ shouldCacheClickId,}),);@@ -480,7 +480,7 @@ export default async function LinkMiddleware(NextResponse.redirect(getFinalUrl(geo[country], {req,- ...(shouldPassClickId && { clickId }),+ ...(shouldCacheClickId && { clickId }),...(isPartnerLink && { via: key }),}),{@@ -506,7 +506,7 @@ export default async function LinkMiddleware(url,webhookIds,workspaceId,- shouldPassClickId,+ shouldCacheClickId,}),);@@ -514,7 +514,7 @@ export default async function LinkMiddleware(NextResponse.redirect(getFinalUrl(url, {req,- ...(shouldPassClickId && { clickId }),+ ...(shouldCacheClickId && { clickId }),...(isPartnerLink && { via: key }),}),{diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.tsindex 8255326c69..6849f7aac4 100644--- a/apps/web/lib/tinybird/record-click.ts+++ b/apps/web/lib/tinybird/record-click.ts@@ -38,7 +38,7 @@ export async function recordClick({skipRatelimit,timestamp,referrer,- shouldPassClickId,+ shouldCacheClickId,}: {req: Request;clickId?: string;@@ -51,7 +51,7 @@ export async function recordClick({skipRatelimit?: boolean;timestamp?: string;referrer?: string;- shouldPassClickId?: boolean;+ shouldCacheClickId?: boolean;}) {if (!clickId) {return null;@@ -170,7 +170,7 @@ export async function recordClick({// cache the click ID and its corresponding click data in Redis for 5 mins// we're doing this because ingested click events are not available immediately in Tinybird- shouldPassClickId &&+ shouldCacheClickId &&redis.set(`clickIdCache:${clickId}`, clickData, {ex: 60 * 5,}),