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.

Expose couponId and couponTestId

Kiran Kf817ef3bcc81
diff --git a/apps/web/app/(ee)/api/track/click/route.ts b/apps/web/app/(ee)/api/track/click/route.ts
index 3c20131f0b..14acd8edf8 100644
--- a/apps/web/app/(ee)/api/track/click/route.ts
+++ b/apps/web/app/(ee)/api/track/click/route.ts
@@ -43,6 +43,8 @@ const trackClickResponseSchema = z.object({
amount: true,
type: true,
maxDuration: true,
+ couponId: true,
+ couponTestId: true,
}).nullish(),
});
@@ -134,7 +136,13 @@ export const POST = withAxiom(async (req: AxiomRequest) => {
clickId,
...(isPartnerLink && {
partner,
- discount,
+ discount: {
+ ...discount,
+ // Support backwards compatibility with old cache format
+ // We could potentially remove after 24 hours
+ couponId: discount?.couponId ?? null,
+ couponTestId: discount?.couponTestId ?? null,
+ },
}),
});
diff --git a/apps/web/lib/api/links/utils/transform-link.ts b/apps/web/lib/api/links/utils/transform-link.ts
index a00db863c3..1690e9bcbf 100644
--- a/apps/web/lib/api/links/utils/transform-link.ts
+++ b/apps/web/lib/api/links/utils/transform-link.ts
@@ -12,7 +12,7 @@ export type ExpandedLink = Link & {
partner?: Pick<PartnerProps, "id" | "name" | "image"> | null;
discount?: Pick<
DiscountProps,
- "id" | "amount" | "type" | "maxDuration"
+ "id" | "amount" | "type" | "maxDuration" | "couponId" | "couponTestId"
> | null;
};
diff --git a/apps/web/lib/planetscale/get-link-with-partner.ts b/apps/web/lib/planetscale/get-link-with-partner.ts
index 6882b146d9..e817479135 100644
--- a/apps/web/lib/planetscale/get-link-with-partner.ts
+++ b/apps/web/lib/planetscale/get-link-with-partner.ts
@@ -44,7 +44,9 @@ export const getLinkWithPartner = async ({
COALESCE(PartnerDiscount.id, ProgramDiscount.id) as discountId,
COALESCE(PartnerDiscount.amount, ProgramDiscount.amount) as discountAmount,
COALESCE(PartnerDiscount.type, ProgramDiscount.type) as discountType,
- COALESCE(PartnerDiscount.maxDuration, ProgramDiscount.maxDuration) as discountMaxDuration
+ COALESCE(PartnerDiscount.maxDuration, ProgramDiscount.maxDuration) as discountMaxDuration,
+ COALESCE(PartnerDiscount.couponId, ProgramDiscount.couponId) as discountCouponId,
+ COALESCE(PartnerDiscount.couponTestId, ProgramDiscount.couponTestId) as discountCouponTestId
FROM Link
LEFT JOIN ProgramEnrollment ON ProgramEnrollment.programId = Link.programId AND ProgramEnrollment.partnerId = Link.partnerId
LEFT JOIN Partner ON Partner.id = ProgramEnrollment.partnerId
@@ -72,6 +74,8 @@ export const getLinkWithPartner = async ({
discountAmount,
discountType,
discountMaxDuration,
+ discountCouponId,
+ discountCouponTestId,
...rest
} = link;
@@ -93,6 +97,8 @@ export const getLinkWithPartner = async ({
amount: discountAmount,
type: discountType,
maxDuration: discountMaxDuration,
+ couponId: discountCouponId,
+ couponTestId: discountCouponTestId,
}
: null,
};
diff --git a/apps/web/lib/planetscale/get-partner-discount.ts b/apps/web/lib/planetscale/get-partner-discount.ts
index 1504f839b0..ceb480a60a 100644
--- a/apps/web/lib/planetscale/get-partner-discount.ts
+++ b/apps/web/lib/planetscale/get-partner-discount.ts
@@ -8,6 +8,8 @@ interface QueryResult {
amount: number;
type: "percentage" | "flat";
maxDuration: number | null;
+ couponId: string | null;
+ couponTestId: string | null;
}
// Get partner and discount info for a partner link
@@ -35,7 +37,9 @@ export const getPartnerAndDiscount = async ({
COALESCE(Discount.id, ProgramDiscount.id) as discountId,
COALESCE(Discount.amount, ProgramDiscount.amount) as amount,
COALESCE(Discount.type, ProgramDiscount.type) as type,
- COALESCE(Discount.maxDuration, ProgramDiscount.maxDuration) as maxDuration
+ COALESCE(Discount.maxDuration, ProgramDiscount.maxDuration) as maxDuration,
+ COALESCE(Discount.couponId, ProgramDiscount.couponId) as couponId,
+ COALESCE(Discount.couponTestId, ProgramDiscount.couponTestId) as couponTestId
FROM ProgramEnrollment
LEFT JOIN Partner ON Partner.id = ProgramEnrollment.partnerId
LEFT JOIN Discount ON Discount.id = ProgramEnrollment.discountId
@@ -70,6 +74,8 @@ export const getPartnerAndDiscount = async ({
amount: result.amount,
type: result.type,
maxDuration: result.maxDuration,
+ couponId: result.couponId,
+ couponTestId: result.couponTestId,
}
: null,
};
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 2746d16e91..5b56de6dbf 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -119,7 +119,10 @@ export interface RedisLinkProps {
programId?: string;
partnerId?: string;
partner?: Pick<PartnerProps, "id" | "name" | "image">;
- discount?: Pick<DiscountProps, "id" | "amount" | "type" | "maxDuration">;
+ discount?: Pick<
+ DiscountProps,
+ "id" | "amount" | "type" | "maxDuration" | "couponId" | "couponTestId"
+ >;
testVariants?: z.infer<typeof ABTestVariantsSchema>;
testCompletedAt?: Date;
}
diff --git a/apps/web/lib/upstash/format-redis-link.ts b/apps/web/lib/upstash/format-redis-link.ts
index a968fcf637..8e82372611 100644
--- a/apps/web/lib/upstash/format-redis-link.ts
+++ b/apps/web/lib/upstash/format-redis-link.ts
@@ -62,6 +62,8 @@ export function formatRedisLink(link: ExpandedLink): RedisLinkProps {
amount: discount.amount,
type: discount.type,
maxDuration: discount.maxDuration,
+ couponId: discount.couponId,
+ couponTestId: discount.couponTestId,
},
}),
...(Boolean(