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.

Support `dub_client_reference_id` param

Steven Teye216474e46a6
diff --git a/apps/web/lib/middleware/utils/get-final-url.ts b/apps/web/lib/middleware/utils/get-final-url.ts
index 307778cc28..62427c3bb4 100644
--- a/apps/web/lib/middleware/utils/get-final-url.ts
+++ b/apps/web/lib/middleware/utils/get-final-url.ts
@@ -40,6 +40,18 @@ export const getFinalUrl = (
urlObj.searchParams.delete("qr");
}
+ /*
+ custom query param for stripe payment links + Dub Conversions
+ - if there is a clickId and dub_client_reference_id is 1
+ - then set client_reference_id to dub_id_${clickId} and drop the dub_client_reference_id param
+ - our Stripe integration will then detect `dub_id_${clickId}` as the dubClickId in the `checkout.session.completed` webhook
+ - @see: https://github.com/dubinc/dub/blob/main/apps/web/app/api/stripe/integration/webhook/checkout-session-completed.ts
+ */
+ if (clickId && urlObj.searchParams.get("dub_client_reference_id") === "1") {
+ urlObj.searchParams.set("client_reference_id", `dub_id_${clickId}`);
+ urlObj.searchParams.delete("dub_client_reference_id");
+ }
+
return urlObj.toString();
};