Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fetch tags in link.clicked webhook

Steven Tey8b3953c85b4d
diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.ts
index 0810b18013..10a856cded 100644
--- a/apps/web/lib/tinybird/record-click.ts
+++ b/apps/web/lib/tinybird/record-click.ts
@@ -213,9 +213,30 @@ async function sendLinkClickWebhooks({
return;
}
- const link = await conn
- .execute("SELECT * FROM Link WHERE id = ?", [linkId])
- .then((res) => res.rows[0]);
+ const [link, tagsResult] = await Promise.all([
+ conn
+ .execute(`SELECT * FROM Link WHERE id = ?`, [linkId])
+ .then((res) => res.rows[0]),
+ conn
+ .execute(
+ `
+ SELECT t.id, t.name, t.color
+ FROM LinkTag lt
+ JOIN Tag t ON lt.tagId = t.id
+ WHERE lt.linkId = ?
+ ORDER BY lt.createdAt ASC
+ `,
+ [linkId],
+ )
+ .then((res) => ({
+ tags: res.rows.map((tag) => ({ tag })),
+ })),
+ ]);
+
+ const finalLink = {
+ ...link,
+ ...tagsResult,
+ };
await sendWebhooks({
trigger: "link.clicked",
@@ -223,7 +244,7 @@ async function sendLinkClickWebhooks({
// @ts-ignore – bot & qr should be boolean
data: transformClickEventData({
...clickData,
- link: transformLink(link as ExpandedLink),
+ link: transformLink(finalLink as ExpandedLink),
}),
});
}