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.

update response messages

Steven Teyfcbbbd67662c
diff --git a/apps/web/lib/api/conversions/track-lead.ts b/apps/web/lib/api/conversions/track-lead.ts
index ef99a48719..5627b53e86 100644
--- a/apps/web/lib/api/conversions/track-lead.ts
+++ b/apps/web/lib/api/conversions/track-lead.ts
@@ -53,7 +53,7 @@ export const trackLead = async ({
throw new DubApiError({
code: "bad_request",
message:
- "The `clickId` attribute was not provided in the request, and no existing customer with the provided `customerExternalId` was found.",
+ "The `clickId` property was not provided in the request, and no existing customer with the provided `customerExternalId` was found.",
});
}
@@ -140,7 +140,7 @@ export const trackLead = async ({
if (link.projectId !== workspace.id) {
throw new DubApiError({
code: "not_found",
- message: `Link does not belong to the workspace`,
+ message: `Link for clickId ${clickId} does not belong to the workspace`,
});
}
@@ -225,15 +225,19 @@ export const trackLead = async ({
waitUntil(
(async () => {
// for async and deferred mode, create the customer in the background
- if (mode == "async" || mode == "deferred") {
+ if (mode === "async" || mode === "deferred") {
customer = await upsertCustomer();
+ console.log(`customer created: ${JSON.stringify(customer, null, 2)}`);
// for async mode, record the lead event right away
+ // for deferred mode, we defer the lead event creation to a subsequent request
if (mode === "async") {
- await recordLead(createLeadEventPayload(customer.id));
+ const res = await recordLead(createLeadEventPayload(customer.id));
+ console.log("lead event recorded:", res);
}
}
+ // track the conversion event
await logConversionEvent({
workspace_id: workspace.id,
link_id: clickData.link_id,
diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.ts
index a6ffc0a791..7eeb73be3d 100644
--- a/apps/web/lib/zod/schemas/leads.ts
+++ b/apps/web/lib/zod/schemas/leads.ts
@@ -10,7 +10,7 @@ export const trackLeadRequestSchema = z.object({
.trim()
.nullish()
.describe(
- "The unique ID of the click that the lead conversion event is attributed to. You can read this value from `dub_id` cookie.",
+ "The unique ID of the click that the lead conversion event is attributed to. You can read this value from `dub_id` cookie. If not provided, Dub will try to find an existing customer with the provided `customerExternalId` and use the `clickId` from the customer if found.",
),
eventName: z
.string()
@@ -49,18 +49,18 @@ export const trackLeadRequestSchema = z.object({
.nullish()
.default(null)
.describe("The avatar URL of the customer."),
- eventQuantity: z
- .number()
- .nullish()
- .describe(
- "The numerical value associated with this lead event (e.g., number of provisioned seats in a free trial). If defined as N, the lead event will be tracked N times.",
- ),
mode: z
.enum(["async", "wait", "deferred"])
.default("async")
.describe(
"The mode to use for tracking the lead event. `async` will not block the request; `wait` will block the request until the lead event is fully recorded in Dub; `deferred` will defer the lead event creation to a subsequent request.",
),
+ eventQuantity: z
+ .number()
+ .nullish()
+ .describe(
+ "The numerical value associated with this lead event (e.g., number of provisioned seats in a free trial). If defined as N, the lead event will be tracked N times.",
+ ),
metadata: z
.record(z.unknown())
.nullish()