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.

Merge branch 'main' into partner-data

Steven Tey70acee922ec2
diff --cc apps/web/lib/middleware/link.ts
index 82cb124289,edd6a196a5..6e1b4ffbf4
--- a/apps/web/lib/middleware/link.ts
+++ b/apps/web/lib/middleware/link.ts
@@@ -30,8 -30,8 +30,9 @@@ import { isCaseSensitiveDomain } from "
import { clickCache } from "../api/links/click-cache";
import { getLinkViaEdge } from "../planetscale";
import { getDomainViaEdge } from "../planetscale/get-domain-via-edge";
+import { getPartnerAndDiscount } from "../planetscale/get-partner-discount";
import { hasEmptySearchParams } from "./utils/has-empty-search-params";
+ import { resolveABTestURL } from "./utils/resolve-ab-test-url";
export default async function LinkMiddleware(
req: NextRequest,
@@@ -287,15 -274,9 +297,15 @@@
const { country } =
process.env.VERCEL === "1" && req.geo ? req.geo : LOCALHOST_GEO_DATA;
+ // we only pass the clickId if:
+ // - trackConversion is enabled
+ // - not a partner link (TODO: add this later) !isPartnerLink
+ // - there is a clickId
+ const shouldPassClickId = trackConversion && clickId;
+
// rewrite to proxy page (/proxy/[domain]/[key]) if it's a bot and proxy is enabled
if (isBot && proxy) {
- return createResponseWithCookie(
+ return createResponseWithCookies(
NextResponse.rewrite(
new URL(`/proxy/${domain}/${encodeURIComponent(key)}`, req.url),
{
diff --cc apps/web/lib/types.ts
index 7886f836ac,b72b8e7493..e62c4d4620
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@@ -114,10 -117,8 +117,12 @@@ export interface RedisLinkProps
doIndex?: boolean;
projectId?: string;
webhookIds?: string[];
+ programId?: string;
+ partnerId?: string;
+ partner?: Pick<PartnerProps, "id" | "name" | "image">;
+ discount?: Pick<DiscountProps, "id" | "amount" | "type" | "maxDuration">;
+ testVariants?: z.infer<typeof ABTestVariantsSchema>;
+ testCompletedAt?: Date;
}
export interface TagProps {
diff --cc apps/web/lib/upstash/format-redis-link.ts
index e6b82ef166,1beb964e5f..a968fcf637
--- a/apps/web/lib/upstash/format-redis-link.ts
+++ b/apps/web/lib/upstash/format-redis-link.ts
@@@ -17,10 -19,8 +19,12 @@@ export function formatRedisLink(link: E
doIndex,
projectId,
webhooks,
+ programId,
+ partnerId,
+ partner,
+ discount,
+ testVariants,
+ testCompletedAt,
} = link;
const webhookIds = webhooks?.map(({ webhookId }) => webhookId) ?? [];
@@@ -43,22 -43,11 +47,28 @@@
...(projectId && { projectId }), // projectId can be undefined for anonymous links
...(doIndex && { doIndex: true }),
...(webhookIds.length > 0 && { webhookIds }),
+ ...(programId && { programId }),
+ ...(partnerId && { partnerId }),
+ ...(partner && {
+ partner: {
+ id: partner.id,
+ name: partner.name,
+ image: partner.image,
+ },
+ }),
+ ...(discount && {
+ discount: {
+ id: discount.id,
+ amount: discount.amount,
+ type: discount.type,
+ maxDuration: discount.maxDuration,
+ },
+ }),
+ ...(Boolean(
+ testVariants && testCompletedAt && new Date(testCompletedAt) > new Date(),
+ ) && {
+ testVariants: testVariants as z.infer<typeof ABTestVariantsSchema>,
+ testCompletedAt: new Date(testCompletedAt!),
+ }),
};
}