The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Merge branch 'main' into tb-migration
Steven Tey894fd79e99d1
diff --cc apps/web/lib/tinybird/record-click.tsindex 6b27a52ae6,bb2f0e7292..945a86aaf4--- a/apps/web/lib/tinybird/record-click.ts+++ b/apps/web/lib/tinybird/record-click.ts@@@ -187,25 -188,21 +188,33 @@@ export async function recordClick("UPDATE Link SET clicks = clicks + 1, lastClicked = NOW() WHERE id = ?",[linkId],),- // if the link has a destination URL, increment the usage count for the workspace- // and then we have a cron that will reset it at the start of new billing cycle- url &&- conn.execute(- "UPDATE Project p JOIN Link l ON p.id = l.projectId SET p.usage = p.usage + 1, p.totalClicks = p.totalClicks + 1 WHERE l.id = ?",- [linkId],- ),+ // if the link is associated with a workspace + has a destination URL+ // increment the usage count for the workspace+ workspaceId &&+ url &&+ publishClickEvent({+ linkId,+ workspaceId,+ timestamp: clickData.timestamp,+ }).catch(() => {+ // Fallback on writing directly to the database+ return conn.execute(+ "UPDATE Project p JOIN Link l ON p.id = l.projectId SET p.usage = p.usage + 1, p.totalClicks = p.totalClicks + 1 WHERE l.id = ?",+ [linkId],+ );+ }),++ // TODO: Remove after Tinybird migration+ fetchWithRetry(+ `${process.env.TINYBIRD_API_URL}/v0/events?name=dub_click_events&wait=true`,+ {+ method: "POST",+ headers: {+ Authorization: `Bearer ${process.env.TINYBIRD_API_KEY_NEW}`,+ },+ body: JSON.stringify(clickData),+ },+ ).then((res) => res.json()),]);// Find the rejected promises and log them