The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add back skipRatelimit
Steven Teyd2b8214c360a
diff --git a/apps/web/app/api/track/click/route.ts b/apps/web/app/api/track/click/route.tsindex e1d3b08147..2f09158d9b 100644--- a/apps/web/app/api/track/click/route.ts+++ b/apps/web/app/api/track/click/route.ts@@ -58,8 +58,11 @@ export const POST = withAxiom(req,clickId,linkId: link.id,+ domain,+ key,url: finalUrl,workspaceId: link.projectId,+ skipRatelimit: true,...(referrer && { referrer }),}),);diff --git a/apps/web/app/api/track/visit/route.ts b/apps/web/app/api/track/visit/route.tsindex 0b64075adc..4d751d06ef 100644--- a/apps/web/app/api/track/visit/route.ts+++ b/apps/web/app/api/track/visit/route.ts@@ -32,13 +32,13 @@ export const POST = withAxiom(const urlObj = new URL(url);- let linkKey = urlObj.pathname.slice(1);- if (linkKey === "") {- linkKey = "_root";+ let key = urlObj.pathname.slice(1);+ if (key === "") {+ key = "_root";}const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP;- const cacheKey = `recordClick:${domain}:${linkKey}:${ip}`;+ const cacheKey = `recordClick:${domain}:${key}:${ip}`;let clickId = await redis.get<string>(cacheKey);@@ -46,7 +46,7 @@ export const POST = withAxiom(if (!clickId) {clickId = nanoid(16);- let link = await getLinkWithAllowedHostnames(domain, linkKey);+ let link = await getLinkWithAllowedHostnames(domain, key);if (!link) {return NextResponse.json(@@ -69,8 +69,11 @@ export const POST = withAxiom(req,clickId,linkId: link.id,+ domain,+ key,url: finalUrl,workspaceId: link.projectId,+ skipRatelimit: true,...(referrer && { referrer }),}),);diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.tsindex d0ed96c4ac..b6cc34e726 100644--- a/apps/web/lib/tinybird/record-click.ts+++ b/apps/web/lib/tinybird/record-click.ts@@ -33,6 +33,7 @@ export async function recordClick({url,webhookIds,workspaceId,+ skipRatelimit,timestamp,referrer,}: {@@ -44,6 +45,7 @@ export async function recordClick({url?: string;webhookIds?: string[];workspaceId: string | undefined;+ skipRatelimit?: boolean;timestamp?: string;referrer?: string;}) {@@ -66,8 +68,8 @@ export async function recordClick({const cacheKey = `recordClick:${domain}:${key}:${ip}`;// by default, we deduplicate clicks for a domain + key pair from the same IP address – only record 1 click per hour- // we only need to do these if domain + key are defined (only in middleware/link and not /api/track/:path endpoints)- if (domain && key) {+ // we only need to do these if skipRatelimit is not true (we skip it in /api/track/:path endpoints)+ if (!skipRatelimit) {// here, we check if the clickId is cached in Redis within the last hourconst cachedClickId = await redis.get<string>(cacheKey);if (cachedClickId) {