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.

record link

Kiran K51a804669a57
diff --git a/apps/web/app/api/cron/domains/transfer/route.ts b/apps/web/app/api/cron/domains/transfer/route.ts
index 88c8ee01b4..4c68793a3c 100644
--- a/apps/web/app/api/cron/domains/transfer/route.ts
+++ b/apps/web/app/api/cron/domains/transfer/route.ts
@@ -5,8 +5,9 @@ import { APP_DOMAIN_WITH_NGROK, log } from "@dub/utils";
import { NextResponse } from "next/server";
import {
domainTransferredEmail,
+ recordLinks,
updateLinksInRedis,
- updateUsage,
+ updateLinksUsage,
} from "./utils";
const schema = z.object({
@@ -62,7 +63,8 @@ export async function POST(req: Request) {
where: { linkId: { in: linkIds } },
}),
updateLinksInRedis({ links, newWorkspaceId, domain }),
- updateUsage({ links, newWorkspaceId, currentWorkspaceId }),
+ updateLinksUsage({ links, newWorkspaceId, currentWorkspaceId }),
+ recordLinks({ links, newWorkspaceId }),
]);
// wait 500 ms before making another request
diff --git a/apps/web/app/api/cron/domains/transfer/utils.ts b/apps/web/app/api/cron/domains/transfer/utils.ts
index 34e7d72a72..ac712d79ae 100644
--- a/apps/web/app/api/cron/domains/transfer/utils.ts
+++ b/apps/web/app/api/cron/domains/transfer/utils.ts
@@ -1,5 +1,6 @@
import { getAnalytics } from "@/lib/analytics";
import prisma from "@/lib/prisma";
+import { recordLink } from "@/lib/tinybird";
import { formatRedisLink, redis } from "@/lib/upstash";
import { Link } from "@prisma/client";
import { sendEmail } from "emails";
@@ -39,7 +40,7 @@ export const updateLinksInRedis = async ({
};
// Update links & click usage
-export const updateUsage = async ({
+export const updateLinksUsage = async ({
currentWorkspaceId,
newWorkspaceId,
links,
@@ -143,3 +144,20 @@ export const domainTransferredEmail = async ({
}),
});
};
+
+// Record link in Tinybird
+export const recordLinks = async ({
+ newWorkspaceId,
+ links,
+}: {
+ newWorkspaceId: string;
+ links: Link[];
+}) => {
+ await Promise.all(
+ links.map((link) =>
+ recordLink({ link: { ...link, projectId: newWorkspaceId } }),
+ ),
+ );
+
+ return;
+};