The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add Singular polyfill for wpcn & wpcl URL params
Kiran Kc38c8364dcf3
diff --git a/apps/web/lib/middleware/utils/get-final-url.ts b/apps/web/lib/middleware/utils/get-final-url.tsindex 1724af5694..d62a52c761 100644--- a/apps/web/lib/middleware/utils/get-final-url.ts+++ b/apps/web/lib/middleware/utils/get-final-url.ts@@ -64,6 +64,18 @@ export const getFinalUrl = (urlObj.searchParams.set("ip", ip ?? "");}+ // Polyfill wpcn & wpcl params for Singular integration+ const wpcn = urlObj.searchParams.get("wpcn");+ const wpcl = urlObj.searchParams.get("wpcl");++ if (wpcn && wpcn === "{via}") {+ urlObj.searchParams.set("wpcn", via ?? "");+ }++ if (wpcl && wpcl === "{dub_id}") {+ urlObj.searchParams.set("wpcl", clickId ?? "");+ }+// for Google Play Store linksif (isGooglePlayStoreUrl(url)) {const { shortLink } = parse(req);diff --git a/apps/web/package.json b/apps/web/package.jsonindex 71efcff3fc..8f361f1c39 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -7,7 +7,7 @@"build": "pnpm prisma:generate && next build","lint": "next lint","start": "next start",- "script": "tsx ./scripts/run.ts",+ "script": "tsx ./scripts/run.ts tests/redirects/index.test.ts","test": "pnpm prisma:generate && vitest -no-file-parallelism --bail=1","generate-openapi": "tsx ./scripts/generate-openapi.ts","prisma:generate": "dotenv-flow -e .env -- pnpm --filter=@dub/prisma generate",diff --git a/apps/web/tests/redirects/index.test.ts b/apps/web/tests/redirects/index.test.tsindex 0ffc4866be..ddaae848c3 100644--- a/apps/web/tests/redirects/index.test.ts+++ b/apps/web/tests/redirects/index.test.ts@@ -114,6 +114,27 @@ describe.runIf(env.CI)("Link Redirects", async () => {expect(response.status).toBe(302);});+ test("singular polyfill wpcn & wpcl params", async () => {+ const response = await fetch(+ `${h.baseUrl}/singular-polyfill`,+ fetchOptions,+ );++ const location = response.headers.get("location");+ expect(location).toBeTruthy();++ const url = new URL(location!);++ // wpcn should be replaced from {via} template to actual via value+ expect(url.searchParams.get("wpcn")).toBe("singular-polyfill");++ // wpcl should be replaced from {dub_id} template to actual dub_id value+ expect(url.searchParams.get("wpcl")).toMatch(/^[a-zA-Z0-9]+$/);++ expect(response.headers.get("x-powered-by")).toBe(poweredBy);+ expect(response.status).toBe(302);+ });+test("google play store url", async () => {const response = await fetch(`${h.baseUrl}/gps`, fetchOptions);const location = response.headers.get("location");