The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update record clicks on root page
Kiran K00238271e180
diff --git a/apps/web/lib/middleware/root.ts b/apps/web/lib/middleware/root.tsindex 7802b09188..ee002dcdff 100644--- a/apps/web/lib/middleware/root.ts+++ b/apps/web/lib/middleware/root.ts@@ -43,7 +43,7 @@ export default async function RootMiddleware(const { id: linkId, url, rewrite, iframeable, noindex } = link;// record clicks on root page- ev.waitUntil(recordClick({ req, linkId, ...(url && { url }), root: true }));+ ev.waitUntil(recordClick({ req, linkId, ...(url && { url }) }));if (!url) {// rewrite to placeholder page unless the user defines a site to redirect todiff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.tsindex ce07f7a70b..127d9ad06f 100644--- a/apps/web/lib/tinybird/record-click.ts+++ b/apps/web/lib/tinybird/record-click.ts@@ -20,13 +20,11 @@ export async function recordClick({linkId,clickId,url,- root,}: {req: NextRequest;linkId: string;clickId?: string;url?: string;- root?: boolean;}) {const isBot = detectBot(req);if (isBot) {@@ -98,20 +96,8 @@ export async function recordClick({// increment the click count for the link or domain (based on their ID)// also increment the usage count for the workspace// and then we have a cron that will reset it at the start of new billing cycle- root+ url? [- conn.execute(- "UPDATE Domain SET clicks = clicks + 1, lastClicked = NOW() WHERE id = ?",- [linkId],- ),- // only increment workspace clicks if there is a destination URL configured (not placeholder landing page)- url &&- conn.execute(- "UPDATE Project p JOIN Domain d ON p.id = d.projectId SET p.usage = p.usage + 1 WHERE d.id = ?",- [linkId],- ),- ]- : [conn.execute("UPDATE Link SET clicks = clicks + 1, lastClicked = NOW() WHERE id = ?",[linkId],@@ -120,6 +106,7 @@ export async function recordClick({"UPDATE Project p JOIN Link l ON p.id = l.projectId SET p.usage = p.usage + 1 WHERE l.id = ?",[linkId],),- ],+ ]+ : undefined,]);}