The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Return early if detectBot in track/open
Steven Tey9aba1186c833
diff --git a/apps/web/app/(ee)/api/track/open/route.ts b/apps/web/app/(ee)/api/track/open/route.tsindex dbb654b369..73734e3a65 100644--- a/apps/web/app/(ee)/api/track/open/route.ts+++ b/apps/web/app/(ee)/api/track/open/route.ts@@ -5,6 +5,7 @@ import { recordClickCache } from "@/lib/api/links/record-click-cache";import { parseRequestBody } from "@/lib/api/utils";import { withAxiom } from "@/lib/axiom/server";import { DeepLinkClickData } from "@/lib/middleware/utils/cache-deeplink-click-data";+import { detectBot } from "@/lib/middleware/utils/detect-bot";import { getIdentityHash } from "@/lib/middleware/utils/get-identity-hash";import { getLinkViaEdge } from "@/lib/planetscale";import { recordClick } from "@/lib/tinybird";@@ -25,10 +26,25 @@ export const POST = withAxiom(async (req) => {await parseRequestBody(req),);+ const isBot = detectBot(req);+ if (isBot) {+ console.log(`Open tracking not recorded ❌ – Bot detected.`, {+ isBot,+ });+ return NextResponse.json(+ trackOpenResponseSchema.parse({+ clickId: null,+ link: null,+ }),+ { headers: COMMON_CORS_HEADERS },+ );+ }+const ip = process.env.VERCEL === "1" ? ipAddress(req) : LOCALHOST_IP;const identityHash = await getIdentityHash(req);if (!deepLinkUrl) {+ // Probabilistic IP-based trackingif (ip) {// if ip address is present, check if there's a cached clickconsole.log(`Checking cache for ${ip}:${dubDomain}:*`);