-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add Singular polyfill for wpcn & wpcl URL params
#2745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughImplements polyfill logic in getFinalUrl to replace wpcn and wpcl placeholders from query params using via and clickId, positioned after Singular tracking and before Google Play handling. Adds a test validating the polyfill by asserting transformed wpcn/wpcl on redirect. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Middleware
participant getFinalUrl
participant Singular
participant PlayStore
Client->>Middleware: HTTP GET /singular-polyfill
Middleware->>getFinalUrl: Build final URL
getFinalUrl->>Singular: Perform tracking logic
getFinalUrl->>getFinalUrl: Polyfill wpcn/wpcl from via/clickId
getFinalUrl->>PlayStore: Apply Google Play handling (if applicable)
getFinalUrl-->>Middleware: Final redirect URL
Middleware-->>Client: 302 Location: <final URL>
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
apps/web/lib/middleware/utils/get-final-url.ts (2)
71-73: Prefer deleting wpcn placeholder when via is absentMinor: If
viais undefined, settingwpcnto an empty string leaves a dangling param (wpcn=). Consider deleting the param to keep URLs clean. Also, thewpcn &&check is redundant.- if (wpcn && wpcn === "{via}") { - urlObj.searchParams.set("wpcn", via ?? ""); - } + if (wpcn === "{via}") { + if (via) { + urlObj.searchParams.set("wpcn", via); + } else { + urlObj.searchParams.delete("wpcn"); + } + }
67-78: Scope the polyfill to Singular links (defensive hardening)This block runs for any URL with
{via}/{dub_id}placeholders. If those placeholders appear in non-Singular destinations, we’ll still rewrite them. Consider scoping this toisSingularTrackingUrl(url)to avoid surprising rewrites.- // 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 ?? ""); - } + // Polyfill wpcn & wpcl params for Singular integration + if (isSingularTrackingUrl(url)) { + const wpcn = urlObj.searchParams.get("wpcn"); + const wpcl = urlObj.searchParams.get("wpcl"); + if (wpcn === "{via}") { + urlObj.searchParams.set("wpcn", via ?? ""); + } + if (wpcl === "{dub_id}") { + if (searchParams.has("dub-no-track")) { + urlObj.searchParams.delete("wpcl"); + } else { + urlObj.searchParams.set("wpcl", clickId ?? ""); + } + } + }Follow-up: Confirm desired precedence with the later passthrough (Lines 95–100) where incoming request query params overwrite the final URL. Is it intentional that incoming
wpcn/wpclshould override the polyfilled values?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/web/lib/middleware/utils/get-final-url.ts(1 hunks)apps/web/tests/redirects/index.test.ts(1 hunks)
🔇 Additional comments (1)
apps/web/tests/redirects/index.test.ts (1)
117-136: Great targeted test for the Singular polyfillThe assertions validate both the
wpcnderivation and thatwpclis emitted with a non-empty value. This provides solid coverage for the new behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/web/tests/utils/resource.ts (1)
69-77: Confirm new E2E discount ID exists in seed data; consider making it configurableNo stale references to the old ID were found, and the new ID (
disc_1K2E253814K7TA6YRKA86XMX5) only appears here:
- apps/web/tests/utils/resource.ts (line 69)
Please verify:
- The new discount ID is present in the seed/fixture data used by your E2E environment.
- Your E2E setup has been updated accordingly to avoid test failures.
Optional enhancement: allow overriding the ID in CI to prevent churn when rotating seeds:
- id: "disc_1K2E253814K7TA6YRKA86XMX5", + id: process.env.E2E_DISCOUNT_ID ?? "disc_1K2E253814K7TA6YRKA86XMX5", // safe fallback
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (2)
apps/web/tests/redirects/index.test.ts (1)
117-136: Add no-track coverage: ensure wpcl is not emitted when opted outGood baseline test for the polyfill. Please add a variant that asserts
wpclis omitted (or empty) when?dub-no-track=1is present to prevent identifier leakage and keep behavior consistent withdub_id.Example test to add:
test("singular polyfill respects dub-no-track for wpcl", async () => { const response = await fetch( `${h.baseUrl}/singular-polyfill?dub-no-track=1`, fetchOptions, ); const location = response.headers.get("location"); expect(location).toBeTruthy(); const url = new URL(location!); // Choose one of the following assertions based on desired semantics: // 1) Remove the param entirely when no-track is set: expect(url.searchParams.has("wpcl")).toBe(false); // 2) Or, keep it present but empty: // expect(url.searchParams.get("wpcl")).toBe(""); expect(response.headers.get("x-powered-by")).toBe(poweredBy); expect(response.status).toBe(302); });apps/web/lib/middleware/utils/get-final-url.ts (1)
75-77: Honor dub-no-track: avoid leaking clickId via wpclIf users opt out (
dub-no-track), we should not populatewpclwithclickId. This mirrors existing handling fordub_idand prevents unintended identifier propagation.Apply this diff:
- if (wpcl && wpcl === "{dub_id}") { - urlObj.searchParams.set("wpcl", clickId ?? ""); - } + if (wpcl === "{dub_id}") { + if (searchParams.has("dub-no-track")) { + // Respect opt-out by removing the placeholder entirely + urlObj.searchParams.delete("wpcl"); + } else { + urlObj.searchParams.set("wpcl", clickId ?? ""); + } + }
🧹 Nitpick comments (1)
apps/web/lib/middleware/utils/get-final-url.ts (1)
71-73: Simplify condition: drop redundant truthy check for wpcn
wpcn && wpcn === "{via}"can be simplified towpcn === "{via}"without behavior change.- if (wpcn && wpcn === "{via}") { + if (wpcn === "{via}") { urlObj.searchParams.set("wpcn", via ?? ""); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/web/lib/middleware/utils/get-final-url.ts(1 hunks)apps/web/tests/redirects/index.test.ts(1 hunks)
Summary by CodeRabbit