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.

Add recordLeadSync function

Steven Tey5a7f8e41efb5
diff --git a/apps/web/app/api/track/lead/route.ts b/apps/web/app/api/track/lead/route.ts
index 5f1293810d..19903701cb 100644
--- a/apps/web/app/api/track/lead/route.ts
+++ b/apps/web/app/api/track/lead/route.ts
@@ -3,7 +3,7 @@ import { includeTags } from "@/lib/api/links/include-tags";
import { createId, parseRequestBody } from "@/lib/api/utils";
import { withWorkspaceEdge } from "@/lib/auth/workspace-edge";
import { generateRandomName } from "@/lib/names";
-import { getClickEvent, recordLead } from "@/lib/tinybird";
+import { getClickEvent, recordLeadSync } from "@/lib/tinybird";
import { redis } from "@/lib/upstash";
import { sendWorkspaceWebhookOnEdge } from "@/lib/webhook/publish-edge";
import { transformLeadEventData } from "@/lib/webhook/transform";
@@ -113,7 +113,7 @@ export const POST = withWorkspaceEdge(
metadata: metadata ? JSON.stringify(metadata) : "",
};
- await recordLead(
+ await recordLeadSync(
eventQuantity
? Array(eventQuantity)
.fill(null)
diff --git a/apps/web/lib/tinybird/record-lead.ts b/apps/web/lib/tinybird/record-lead.ts
index 4f476b3119..57f7da76cd 100644
--- a/apps/web/lib/tinybird/record-lead.ts
+++ b/apps/web/lib/tinybird/record-lead.ts
@@ -7,6 +7,12 @@ export const recordLead = tb.buildIngestEndpoint({
event: leadEventSchemaTB,
});
+export const recordLeadSync = tb.buildIngestEndpoint({
+ datasource: "dub_lead_events",
+ event: leadEventSchemaTB,
+ wait: true,
+});
+
export const recordLeadWithTimestamp = tb.buildIngestEndpoint({
datasource: "dub_lead_events",
event: leadEventSchemaTB.extend({
diff --git a/apps/web/tests/tracks/track-lead.test.ts b/apps/web/tests/tracks/track-lead.test.ts
index b9a8ef8c88..af74bb41fc 100644
--- a/apps/web/tests/tracks/track-lead.test.ts
+++ b/apps/web/tests/tracks/track-lead.test.ts
@@ -59,4 +59,37 @@ describe("POST /track/lead", async () => {
},
});
});
+
+ test("track a lead with eventQuantity", async () => {
+ const customer2 = randomCustomer();
+ const response = await http.post<TrackLeadResponse>({
+ path: "/track/lead",
+ body: {
+ clickId: E2E_CLICK_ID,
+ eventName: "Start Trial",
+ customerId: customer2.id,
+ customerName: customer2.name,
+ customerEmail: customer2.email,
+ customerAvatar: customer2.avatar,
+ eventQuantity: 2,
+ },
+ });
+
+ expect(response.status).toEqual(200);
+ expect(response.data).toStrictEqual({
+ clickId: E2E_CLICK_ID,
+ customerName: customer2.name,
+ customerEmail: customer2.email,
+ customerAvatar: customer2.avatar,
+ click: {
+ id: E2E_CLICK_ID,
+ },
+ customer: {
+ name: customer2.name,
+ email: customer2.email,
+ avatar: customer2.avatar,
+ externalId: customer2.id,
+ },
+ });
+ });
});