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

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Oct 22, 2025

Summary by CodeRabbit

  • Refactor
    • Click events now include workspace_id, domain, and key for richer attribution and analytics.
    • Tracking payloads and schemas were standardized across integrations for consistent reporting.
    • Workspace identifier handling made more flexible to reduce missing-data issues and improve downstream processing.

@vercel
Copy link
Contributor

vercel bot commented Oct 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Oct 22, 2025 10:42pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 22, 2025

Warning

Rate limit exceeded

@steven-tey has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 53 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 05c003a and 2f1ab73.

📒 Files selected for processing (1)
  • apps/web/lib/zod/schemas/clicks.ts (1 hunks)

Walkthrough

Adds workspace_id, domain, and key to click event payloads across schemas, core Tinybird recording, API routes, middleware, partner importers, and backfill/seed scripts; makes workspaceId optional in the recordClick function signature. No public API endpoints or external signatures were removed.

Changes

Cohort / File(s) Summary
Schema Updates
apps/web/lib/tinybird/record-click-zod.ts, apps/web/lib/zod/schemas/clicks.ts
Added workspace_id, domain, and key fields to Tinybird/Zod schemas (defaults in record-click-zod; required in clicks schema).
Core Tinybird Recording
apps/web/lib/tinybird/record-click.ts, apps/web/lib/tinybird/record-fake-click.ts, apps/web/lib/tinybird/record-click-zod.ts
Made workspaceId optional in recordClick signature; emit workspace_id, domain, and key in click payloads; adjusted payload construction and ordering.
API Track Routes
apps/web/app/(ee)/api/track/click/route.ts, apps/web/app/(ee)/api/track/open/route.ts, apps/web/app/(ee)/api/track/visit/route.ts
Reordered/updated recordClick argument objects to include workspaceId where applicable; no control-flow changes.
Cron / Backfill Routes
apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts
Add workspace_id, domain, and key to click payloads constructed during backfill processing.
Middleware / Link Processing
apps/web/lib/middleware/link.ts
Include workspaceId in recordClick payloads across redirect/route handling; removed duplicate workspaceId entries.
Partner Integrations
apps/web/lib/firstpromoter/import-customers.ts, apps/web/lib/partnerstack/import-customers.ts, apps/web/lib/rewardful/import-customers.ts, apps/web/lib/tolt/import-customers.ts
Add workspaceId, domain, and key to click payloads in customer import/referral flows; reorder fields passed to recordClick.
Backfill & Seed Scripts
apps/web/scripts/fillout/backfill-customer-leads.ts, apps/web/scripts/framer/3-backfill-tb-events.ts, apps/web/scripts/perplexity/backfill-leads.ts, apps/web/scripts/seed-data.ts
Augment generated click events with workspace_id, domain, and key for historical/seed data; seed-data.ts uses a fixed workspace_id value.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • Improve track click #2562 — Modifies the same track click route (apps/web/app/(ee)/api/track/click/route.ts) and touches recordClick, likely overlapping on call sites and payload shape.
  • Add trigger enums #2661 — Alters the recordClick payload/schema (adds/removes fields) and therefore directly relates to schema and payload changes here.
  • Leverage clickIdCache to reduce load on Tinybird #2981 — Updates recordClick internals (caching/behaviour) in the same module changed by this PR; could conflict with payload/signature adjustments.

Suggested reviewers

  • devkiran

Poem

🐰
I nibble at payloads, neat and spry,
Adding workspace, domain, and key so they fly.
From routes to seeds, each click gets more light,
Hops of data dancing through the night. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Add workspace_id, domain, and key to dub_clicks_metadata" directly and accurately describes the primary change across all modified files. The changeset consistently adds these three fields to click event payloads and updates the Tinybird schemas to include them. The title is specific, naming the exact fields being added, and avoids vague terminology. A teammate reviewing the PR history would immediately understand that this change enhances click metadata with additional tracking fields.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/scripts/seed-data.ts (1)

88-125: Missing workspace_id, domain, and key fields in seedClicks function.

The seedClicks function generates click events for dub_click_events but doesn't include the newly required workspace_id, domain, and key fields. This will cause validation failures since the clickEventSchemaTB schema now requires these fields.

Add the missing fields to the click event data:

     return {
       timestamp: new Date(
         Date.now() - Math.floor(Math.random() * 30 * 24 * 60 * 60 * 1000),
       ).toISOString(),
       click_id: nanoid(16),
+      workspace_id: "ws_cl7pj5kq4006835rbjlt2ofka",
       link_id: link.id,
+      domain: link.domain,
+      key: link.shortLink.split("/")[1],
       url: link.url,
       country,
🧹 Nitpick comments (2)
apps/web/lib/zod/schemas/clicks.ts (1)

38-58: Consider adding workspace_id, domain, and key to clickEventSchemaTBEndpoint.

The clickEventSchemaTBEndpoint schema (used for the endpoint response) doesn't include the newly added workspace_id, domain, and key fields, while clickEventSchemaTB does. This inconsistency may cause issues if the endpoint schema is used to validate or transform click events.

If these fields should be exposed in endpoint responses, update the schema:

 export const clickEventSchemaTBEndpoint = z.object({
   event: z.literal("click"),
   timestamp: z.string(),
   click_id: z.string(),
+  workspace_id: z.string(),
   link_id: z.string(),
+  domain: z.string(),
+  key: z.string(),
   url: z.string(),
apps/web/lib/tinybird/record-click.ts (1)

140-143: Consider requiring workspaceId for data quality.

The code falls back to an empty string when workspaceId is not provided (workspaceId || ""). This could lead to click events being stored without workspace context, potentially complicating analytics and billing calculations.

Consider one of these approaches:

  1. Make workspaceId required if workspace context is critical:
-  workspaceId?: string;
+  workspaceId: string;
  1. Add validation to warn about missing workspaceId:
   const clickData = {
     timestamp: timestamp || new Date(Date.now()).toISOString(),
     identity_hash: identityHash,
     click_id: clickId,
-    workspace_id: workspaceId || "",
+    workspace_id: workspaceId || "",
     link_id: linkId,
     domain,
     key,
+  if (!workspaceId) {
+    console.warn(`[Record click] Click recorded without workspace context: ${linkId}`);
+  }
  1. Document when it's acceptable to record clicks without workspaceId.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b1089f and 05c003a.

📒 Files selected for processing (17)
  • apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts (1 hunks)
  • apps/web/app/(ee)/api/track/click/route.ts (1 hunks)
  • apps/web/app/(ee)/api/track/open/route.ts (1 hunks)
  • apps/web/app/(ee)/api/track/visit/route.ts (1 hunks)
  • apps/web/lib/firstpromoter/import-customers.ts (1 hunks)
  • apps/web/lib/middleware/link.ts (7 hunks)
  • apps/web/lib/partnerstack/import-customers.ts (1 hunks)
  • apps/web/lib/rewardful/import-customers.ts (1 hunks)
  • apps/web/lib/tinybird/record-click-zod.ts (1 hunks)
  • apps/web/lib/tinybird/record-click.ts (3 hunks)
  • apps/web/lib/tinybird/record-fake-click.ts (1 hunks)
  • apps/web/lib/tolt/import-customers.ts (1 hunks)
  • apps/web/lib/zod/schemas/clicks.ts (1 hunks)
  • apps/web/scripts/fillout/backfill-customer-leads.ts (1 hunks)
  • apps/web/scripts/framer/3-backfill-tb-events.ts (1 hunks)
  • apps/web/scripts/perplexity/backfill-leads.ts (1 hunks)
  • apps/web/scripts/seed-data.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (22)
apps/web/lib/tolt/import-customers.ts (1)

203-213: LGTM! Click metadata enrichment is correctly implemented.

The recordClick invocation now properly includes workspaceId, domain, and key fields, aligning with the PR objective to enrich click event tracking. All data sources are validated earlier in the function flow, and the parameter ordering is consistent with the updated signature.

apps/web/lib/firstpromoter/import-customers.ts (1)

225-235: LGTM! Workspace context properly added to click tracking.

The addition of workspaceId: workspace.id enriches the click event with workspace context, which aligns with the PR objective. The workspace is guaranteed to be non-null due to the findUniqueOrThrow call on line 17.

apps/web/app/(ee)/api/track/open/route.ts (1)

110-124: LGTM! WorkspaceId parameter correctly positioned.

The reordering of the workspaceId parameter is consistent with the broader payload standardization across the codebase. The null check on lines 101-106 ensures cachedLink.projectId is valid before being used.

apps/web/scripts/fillout/backfill-customer-leads.ts (1)

76-110: LGTM! Click event payload correctly enriched with workspace context.

The addition of workspace_id, domain, and key fields enriches the backfill click events with proper workspace and link context. All data sources are guaranteed to be valid:

  • workspace.id from findUniqueOrThrow on line 41
  • link.domain and link.key from filtered partner links
apps/web/app/(ee)/api/track/click/route.ts (1)

132-146: LGTM! WorkspaceId parameter correctly positioned.

The reordering of the workspaceId parameter improves consistency across the codebase. The null check on lines 88-93 ensures cachedLink.projectId is valid before the recordClick call.

apps/web/lib/middleware/link.ts (8)

154-154: Good extraction of workspaceId for reuse across all click paths.

Extracting workspaceId from cachedLink.projectId at line 154 enables consistent workspace context tracking across all redirect paths (root domain, custom URI, cloaking, iOS/Android redirects, geo-targeting, and regular redirects).


272-285: LGTM! Root domain click tracking includes workspace context.


324-338: LGTM! Custom URI scheme click tracking includes workspace context.


364-378: LGTM! Cloaking/rewrite click tracking includes workspace context.


406-420: LGTM! iOS redirect click tracking includes workspace context.


477-491: LGTM! Android redirect click tracking includes workspace context.


513-527: LGTM! Geo-targeting click tracking includes workspace context.


549-563: LGTM! Regular redirect click tracking includes workspace context.

apps/web/scripts/perplexity/backfill-leads.ts (1)

131-165: LGTM! Backfill click data properly enriched with workspace context.

The addition of workspace_id, domain, and key fields ensures historical click data has consistent metadata with current tracking. All data sources are guaranteed to be valid:

  • workspace.id from findUniqueOrThrow on line 46
  • link.domain and link.key from the filtered partner links
apps/web/lib/rewardful/import-customers.ts (1)

190-200: LGTM! Workspace context properly added to Rewardful click tracking.

The addition of workspaceId: workspace.id enriches the Rewardful import click events with workspace context. The workspace is guaranteed to be non-null due to the findUniqueOrThrow call on line 18.

apps/web/app/(ee)/api/track/visit/route.ts (1)

86-99: Null safety for workspaceId is properly handled — no changes required.

The verification confirms that workspaceId is optional in the recordClick function signature (workspaceId?: string), and the projectId field in RedisLinkProps is also optional (projectId?: string). Downstream handling in recordClick converts undefined values to an empty string (workspace_id: workspaceId || "" at line 140), and any conditional operations that depend on a non-empty workspace ID are properly guarded with null/undefined checks (e.g., workspaceId && url && at line 206, and if (workspaceId && hasWebhooks) at line 282). The code change is safe and correct as written.

apps/web/scripts/framer/3-backfill-tb-events.ts (1)

159-162: LGTM!

The addition of workspace_id, domain, and key fields to the click data payload aligns correctly with the updated Tinybird schema. All values are properly sourced from the workspace and link objects.

apps/web/lib/partnerstack/import-customers.ts (1)

230-240: LGTM!

The recordClick call now correctly includes workspaceId from workspace.id, and the field ordering aligns with the updated function signature.

apps/web/app/(ee)/api/cron/framer/backfill-leads-batch/route.ts (1)

215-218: LGTM!

The backfill logic correctly adds workspace_id, domain, and key to the click data payload, ensuring compliance with the updated Tinybird schema.

apps/web/scripts/seed-data.ts (1)

161-164: LGTM!

The seedLeads function correctly includes workspace_id, domain, and key fields in the lead event payload.

apps/web/lib/tinybird/record-click.ts (1)

36-36: LGTM! workspaceId is now optional in the function signature.

The parameter change from workspaceId: string | undefined to workspaceId?: string improves the API ergonomics while maintaining backward compatibility.

Also applies to: 53-53

apps/web/lib/zod/schemas/clicks.ts (1)

8-11: No validation issues found — all recordClick invocations provide the required fields.

All 16 recordClick calls across the codebase include the four required fields: workspaceId, linkId, domain, and key. No code paths are missing these fields, so validation failures from incomplete data are not a concern.

@steven-tey
Copy link
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 22, 2025

✅ Actions performed

Full review triggered.

@steven-tey steven-tey merged commit 16f24b4 into main Oct 22, 2025
7 checks passed
@steven-tey steven-tey deleted the workspace-id-domain-key branch October 22, 2025 22:51
dbryson pushed a commit to beyond-the-checkout/btc that referenced this pull request Nov 27, 2025
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.

2 participants