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 partner link tracking to support multiple links

Kiran K311f933ceb82
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/partners/partner-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/partners/partner-table.tsx
index 66a25700fc..87406d4649 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/partners/partner-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/partners/partner-table.tsx
@@ -148,7 +148,10 @@ export function PartnerTable() {
header: "Clicks",
accessorFn: (d) =>
d.status !== "pending"
- ? nFormatter(d.link?.clicks, { full: true })
+ ? nFormatter(
+ d.links?.reduce((acc, curr) => acc + curr.clicks, 0),
+ { full: true },
+ )
: "-",
},
{
@@ -156,7 +159,10 @@ export function PartnerTable() {
header: "Leads",
accessorFn: (d) =>
d.status !== "pending"
- ? nFormatter(d.link?.leads, { full: true })
+ ? nFormatter(
+ d.links?.reduce((acc, curr) => acc + curr.leads, 0),
+ { full: true },
+ )
: "-",
},
{
@@ -164,7 +170,10 @@ export function PartnerTable() {
header: "Sales",
accessorFn: (d) =>
d.status !== "pending"
- ? nFormatter(d.link?.sales, { full: true })
+ ? nFormatter(
+ d.links?.reduce((acc, curr) => acc + curr.sales, 0),
+ { full: true },
+ )
: "-",
},
{
diff --git a/apps/web/lib/api/links/create-link.ts b/apps/web/lib/api/links/create-link.ts
index 2e838b94b6..7552466bbb 100644
--- a/apps/web/lib/api/links/create-link.ts
+++ b/apps/web/lib/api/links/create-link.ts
@@ -38,7 +38,23 @@ export async function createLink(link: ProcessedLinkProps) {
const { utm_source, utm_medium, utm_campaign, utm_term, utm_content } =
getParamsFromURL(url);
- const { tagId, tagIds, tagNames, webhookIds, ...rest } = link;
+ const { tagId, tagIds, tagNames, webhookIds, programId, tenantId, ...rest } =
+ link;
+
+ const partner =
+ programId && tenantId
+ ? await prisma.programEnrollment.findUnique({
+ where: {
+ tenantId_programId: {
+ tenantId,
+ programId,
+ },
+ },
+ select: {
+ partnerId: true,
+ },
+ })
+ : null;
const response = await prisma.link.create({
data: {
@@ -57,6 +73,8 @@ export async function createLink(link: ProcessedLinkProps) {
utm_content,
expiresAt: expiresAt ? new Date(expiresAt) : null,
geo: geo || Prisma.JsonNull,
+ programId,
+ tenantId,
// Associate tags by tagNames
...(tagNames?.length &&
@@ -111,6 +129,11 @@ export async function createLink(link: ProcessedLinkProps) {
},
},
}),
+
+ // Partner link
+ ...(partner && {
+ partnerId: partner.partnerId,
+ }),
},
include: {
...includeTags,