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: only persist UTM params in bulk link updates

Cursor Agentdaf2eb97a2a5
diff --git a/apps/web/lib/api/links/bulk-update-links.ts b/apps/web/lib/api/links/bulk-update-links.ts
index 61fa319058..c60208617f 100644
--- a/apps/web/lib/api/links/bulk-update-links.ts
+++ b/apps/web/lib/api/links/bulk-update-links.ts
@@ -40,6 +40,10 @@ export async function bulkUpdateLinks(
const imageUrlNonce = nanoid(7);
+ const { utm_source, utm_medium, utm_campaign, utm_term, utm_content } = url
+ ? getParamsFromURL(url)
+ : {};
+
// The bulk payload omits link key but not `partnerId`, so an
// update can move links between partners. The former owners are unrecoverable
// after the write, so read them first, and only when the payload can move one.
@@ -71,7 +75,14 @@ export async function bulkUpdateLinks(
geo: geo === null ? Prisma.DbNull : geo,
testVariants: testVariants === null ? Prisma.DbNull : testVariants,
- ...(url && getParamsFromURL(url)),
+ // Only persist known UTM Link columns — ignore other query params
+ ...(url && {
+ utm_source: utm_source || null,
+ utm_medium: utm_medium || null,
+ utm_campaign: utm_campaign || null,
+ utm_term: utm_term || null,
+ utm_content: utm_content || null,
+ }),
// Associate tags by tagNames
...(tagNames &&
workspaceId && {
diff --git a/apps/web/playwright/api/links/links-bulk.spec.ts b/apps/web/playwright/api/links/links-bulk.spec.ts
index 23eac56089..825294856b 100644
--- a/apps/web/playwright/api/links/links-bulk.spec.ts
+++ b/apps/web/playwright/api/links/links-bulk.spec.ts
@@ -11,6 +11,11 @@ type BulkLink = {
domain: string;
programId: string | null;
partnerId: string | null;
+ utm_source: string | null;
+ utm_medium: string | null;
+ utm_campaign: string | null;
+ utm_term: string | null;
+ utm_content: string | null;
};
type BulkLinkError = {
@@ -275,3 +280,43 @@ test("PATCH /links/bulk – rejects invalid partnerId", async ({
await deleteLinks(api, createdIds);
}
});
+
+test("PATCH /links/bulk – ignores non-UTM URL query params", async ({
+ api,
+}) => {
+ const createdIds: string[] = [];
+ const destinationUrl =
+ "https://example.com/landing?follow=%40737agxqn&lp=UeueIg&liff_id=xx-1ftVOtwe&utm_source=landing&utm_medium=social";
+
+ try {
+ const { data: created } = await createBulkLinks(api, [bulkLinkBody()]);
+ const links = created.filter(isBulkLink);
+ createdIds.push(...links.map((link) => link.id));
+
+ expect(links).toHaveLength(1);
+
+ const { status, data } = await api.patch<BulkLink[]>("/api/links/bulk", {
+ linkIds: links.map((link) => link.id),
+ data: {
+ url: destinationUrl,
+ },
+ });
+
+ expect(status).toEqual(200);
+ expect(data).toHaveLength(1);
+ expect(data[0]).toMatchObject({
+ id: links[0].id,
+ url: destinationUrl,
+ utm_source: "landing",
+ utm_medium: "social",
+ utm_campaign: null,
+ utm_term: null,
+ utm_content: null,
+ });
+ expect(data[0]).not.toHaveProperty("follow");
+ expect(data[0]).not.toHaveProperty("lp");
+ expect(data[0]).not.toHaveProperty("liff_id");
+ } finally {
+ await deleteLinks(api, createdIds);
+ }
+});