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.

fix clicks

Steven Tey4ab61a4e674b
diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.ts
index c27bc81bc3..d5ebf3a418 100644
--- a/apps/web/lib/tinybird/record-click.ts
+++ b/apps/web/lib/tinybird/record-click.ts
@@ -19,10 +19,7 @@ import { conn } from "../planetscale";
import { ratelimit } from "../upstash";
import { webhookCache } from "../webhook/cache";
import { sendWebhooks } from "../webhook/qstash";
-import {
- transformClickEventData,
- transformLinkEventData,
-} from "../webhook/transform";
+import { transformClickEventData } from "../webhook/transform";
/**
* Recording clicks with geo, ua, referer and timestamp data
@@ -164,14 +161,11 @@ export async function recordClick({
await sendWebhooks({
trigger: "link.clicked",
webhooks: linkWebhooks,
- data: {
- ...transformClickEventData({
- ...clickData,
- bot: clickData.bot ? 1 : 0,
- qr: clickData.qr ? 1 : 0,
- }),
- link: transformLinkEventData(link),
- },
+ // @ts-ignore – bot & qr should be boolean
+ data: transformClickEventData({
+ ...clickData,
+ link,
+ }),
});
}
}
diff --git a/apps/web/lib/webhook/transform.ts b/apps/web/lib/webhook/transform.ts
index 2e8d7558f8..d7b7294f9f 100644
--- a/apps/web/lib/webhook/transform.ts
+++ b/apps/web/lib/webhook/transform.ts
@@ -38,13 +38,30 @@ export const transformLinkEventData = (data: Link) => {
};
export const transformClickEventData = (
- data: z.infer<typeof clickEventSchemaTB>,
+ data: z.infer<typeof clickEventSchemaTB> & {
+ link: any;
+ },
) => {
const click = Object.fromEntries(
Object.entries(data).map(([key, value]) => [toCamelCase(key), value]),
);
- return clickEventSchema.parse(click);
+ // TODO: This is a bit flaky – e.g. if we add another boolean field to link schema
+ // this will still break. We should make it more robust.
+ const link = {
+ ...transformLink(data.link),
+ archived: data.link.archived === 1,
+ doIndex: data.link.doIndex === 1,
+ proxy: data.link.proxy === 1,
+ publicStats: data.link.publicStats === 1,
+ rewrite: data.link.rewrite === 1,
+ trackConversion: data.link.trackConversion === 1,
+ };
+
+ return clickEventSchema.parse({
+ ...click,
+ link,
+ });
};
export const transformLeadEventData = (data: any) => {