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.

Return clickId when event already backfilled

Steven Teyaa0fa0d9d748
diff --git a/apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts b/apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts
index 4d3eb6884f..4ceaa343bd 100644
--- a/apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts
+++ b/apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts
@@ -6,6 +6,7 @@ import { generateRandomName } from "@/lib/names";
import {
recordLeadWithTimestamp,
recordSaleWithTimestamp,
+ tb,
} from "@/lib/tinybird";
import { redis } from "@/lib/upstash";
import z from "@/lib/zod";
@@ -38,6 +39,16 @@ const FRAMER_WORKSPACE_ID = "clsvopiw0000ejy0grp821me0";
const CACHE_KEY = "framerMigratedExternalIdEventNames";
const DOMAIN = "framer.link";
+const getFramerLeadEvents = tb.buildPipe({
+ pipe: "get_framer_lead_events",
+ parameters: z.object({
+ linkIds: z
+ .union([z.string(), z.array(z.string())])
+ .transform((v) => (Array.isArray(v) ? v : v.split(","))),
+ }),
+ data: z.any(),
+});
+
// POST /api/cron/framer/backfill-leads-batch
export const POST = withWorkspace(async ({ req, workspace }) => {
try {
@@ -80,22 +91,34 @@ export const POST = withWorkspace(async ({ req, workspace }) => {
}),
]);
+ const { data: leadEventsForLinks } = await getFramerLeadEvents({
+ linkIds: links.map((l) => l.id),
+ });
+
let validEntries: PayloadItem[] = [];
- let invalidEntries: (PayloadItem & { error: string })[] = [];
+ let invalidEntries: (PayloadItem & { error: string; clickId?: string })[] =
+ [];
originalPayload.map((p, index) => {
- if (existsResults[index]) {
+ const linkData = links.find((l) => l.key === p.via);
+
+ if (!linkData) {
invalidEntries.push({
...p,
- error: "Already backfilled.",
+ error: `Link for via tag ${p.via} not found.`,
});
return;
}
- if (!links.some((l) => l.key === p.via)) {
+ if (existsResults[index]) {
+ const clickId = leadEventsForLinks.find(
+ (e) => e.link_id === linkData.id && e.event_name === p.eventName,
+ )?.click_id;
+
invalidEntries.push({
...p,
- error: `Link for via tag ${p.via} not found.`,
+ error: "Already backfilled.",
+ clickId,
});
return;
}
diff --git a/apps/web/scripts/framer/backfill-remainder.ts b/apps/web/scripts/framer/backfill-remainder.ts
index 54090f3d7f..fb281542a3 100644
--- a/apps/web/scripts/framer/backfill-remainder.ts
+++ b/apps/web/scripts/framer/backfill-remainder.ts
@@ -14,7 +14,9 @@ import z from "../../lib/zod";
const getFramerLeadEvents = tb.buildPipe({
pipe: "get_framer_lead_events",
parameters: z.object({
- linkId: z.string(),
+ linkIds: z
+ .union([z.string(), z.array(z.string())])
+ .transform((v) => (Array.isArray(v) ? v : v.split(","))),
}),
data: z.any(),
});
@@ -69,7 +71,7 @@ async function processFramerData(linkToBackfill: {
);
const { data: leadEvents } = await getFramerLeadEvents({
- linkId: linkToBackfill.linkId,
+ linkIds: linkToBackfill.linkId,
});
const customerIdsSet = new Set(