Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Aug 12, 2025

Summary by CodeRabbit

  • New Features
    • Automatically populate wpcn and wpcl query parameters during redirects for Singular-linked flows, improving attribution reliability when placeholders are present.
  • Tests
    • Added coverage to verify redirects set wpcn to the expected value and wpcl to a valid alphanumeric click ID, along with correct headers and 302 status.

@vercel
Copy link
Contributor

vercel bot commented Aug 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Project Deployment Preview Updated (UTC)
dub Ready Preview Aug 12, 2025 3:51pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 12, 2025

Walkthrough

Implements 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

Cohort / File(s) Summary
URL finalization: Singular polyfill
apps/web/lib/middleware/utils/get-final-url.ts
Adds logic to substitute wpcn="{via}" with via and wpcl="{dub_id}" with clickId; executed after Singular tracking block and before Google Play Store handling.
Redirect tests
apps/web/tests/redirects/index.test.ts
Adds test “singular polyfill wpcn & wpcl params” verifying wpcn equals the path-derived value and wpcl is alphanumeric on 302 redirect.

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>
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • devkiran

Poem

I hop through params, quick and spry,
Swapping tags as URLs fly.
wpcn, wpcl—clicks aligned,
Via whispers, dub_id signed.
A 302 wink, then off I go—
Carrots cached in the redirect flow. 🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch singular-polyfill

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devkiran devkiran requested a review from steven-tey August 12, 2025 04:20
@devkiran devkiran marked this pull request as ready for review August 12, 2025 04:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 absent

Minor: If via is undefined, setting wpcn to an empty string leaves a dangling param (wpcn=). Consider deleting the param to keep URLs clean. Also, the wpcn && 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 to isSingularTrackingUrl(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/wpcl should override the polyfilled values?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d7291d7 and a71a04a.

📒 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 polyfill

The assertions validate both the wpcn derivation and that wpcl is emitted with a non-empty value. This provides solid coverage for the new behavior.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 configurable

No 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
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a71a04a and 5bde1e0.

📒 Files selected for processing (1)
  • apps/web/tests/utils/resource.ts (1 hunks)

@steven-tey
Copy link
Collaborator

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 12, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 out

Good baseline test for the polyfill. Please add a variant that asserts wpcl is omitted (or empty) when ?dub-no-track=1 is present to prevent identifier leakage and keep behavior consistent with dub_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 wpcl

If users opt out (dub-no-track), we should not populate wpcl with clickId. This mirrors existing handling for dub_id and 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 to wpcn === "{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

📥 Commits

Reviewing files that changed from the base of the PR and between 3193ab2 and db32e98.

📒 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)

@steven-tey steven-tey merged commit f8bf5d9 into main Aug 12, 2025
8 checks passed
@steven-tey steven-tey deleted the singular-polyfill branch August 12, 2025 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants