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 26, 2025

Summary by CodeRabbit

  • Improvements
    • Enhanced workspace context tracking by standardizing workspace identification across all lead and sale event payloads. Workspace context is now consistently maintained throughout Stripe webhook processing, lead tracking, and Shopify integration flows. Fallback mechanisms ensure workspace information is always present, improving data consistency and attribution tracking accuracy across all integration points.

@vercel
Copy link
Contributor

vercel bot commented Oct 26, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Oct 26, 2025 0:05am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 26, 2025

Walkthrough

This pull request adds workspace_id fields to lead and sale event payloads across Stripe webhook handlers, conversion tracking functions, and Shopify integrations. The field is derived from click event data or defaults to customer project ID and workspace ID respectively, ensuring workspace context propagates consistently through the event pipeline.

Changes

Cohort / File(s) Change Summary
Stripe Webhook Payload Enrichment
apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts, apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts, apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts
Adds workspace_id to leadEvent and saleData payloads across three webhook paths, sourcing from clickEvent.workspace_id or falling back to customer.projectId
Conversion Tracking Pipeline
apps/web/lib/api/conversions/track-lead.ts, apps/web/lib/api/conversions/track-sale.ts
Adds workspace_id to lead event base payloads and saleData with fallbacks to clickData.workspace_id or workspace.id; ensures workspace context persists throughout conversion pipeline
Shopify Integration
apps/web/lib/integrations/shopify/create-lead.ts, apps/web/lib/integrations/shopify/create-sale.ts
Adds workspace_id to Shopify lead and sale data payloads, sourcing from clickData or leadData with fallback to customer.projectId or provided workspaceId

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

  • Homogeneous pattern: All changes follow the same field-addition pattern with consistent fallback logic across files
  • Areas for attention:
    • Verify fallback logic consistency (e.g., clickEvent.workspace_id vs customer.projectId vs workspace.id) across different integration paths
    • Confirm that workspace_id propagation doesn't inadvertently expose or leak workspace context in unexpected scenarios

Possibly related PRs

  • #2996 — Main workspace_id propagation PR adding the field to clickEvent payloads and recordClick, foundational to these changes
  • #2818 — Modifies track-sale.ts to extend trackSale inputs and lead-creation paths, overlapping conversion pipeline changes
  • #2815 — Modifies track-lead.ts to add workspace parameter and rewrite lead construction flow, touching the same conversion tracking function

Suggested reviewers

  • devkiran

Poem

🐰 Through webhooks and tracks, a workspace_id flows,
From clicks to conversions, the context now glows,
With fallbacks so graceful, through Stripe and through Shopify too,
Each lead finds its home—a workspace shines through! 🎯

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 "Polyfill workspace_id in case it's not defined" accurately and concisely describes the main objective of the changeset. The changes across seven files consistently add workspace_id fields to various event payloads (lead events, sale data) with fallback mechanisms to handle cases where workspace_id may not be present, which directly matches what the title conveys through the term "polyfill." The title is specific and clear enough that a reviewer scanning the history would immediately understand this PR adds resilience and default handling for the workspace_id field.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch polyfill-workspaceid

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8fd46f and 2a20d3c.

📒 Files selected for processing (7)
  • apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts (3 hunks)
  • apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts (1 hunks)
  • apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts (1 hunks)
  • apps/web/lib/api/conversions/track-lead.ts (1 hunks)
  • apps/web/lib/api/conversions/track-sale.ts (3 hunks)
  • apps/web/lib/integrations/shopify/create-lead.ts (1 hunks)
  • apps/web/lib/integrations/shopify/create-sale.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-02T22:46:22.739Z
Learnt from: steven-tey
PR: dubinc/dub#2924
File: apps/web/lib/api/conversions/track-lead.ts:7-7
Timestamp: 2025-10-02T22:46:22.739Z
Learning: In apps/web/lib/api/conversions/track-lead.ts, lead events are cached in Redis for 5 minutes (keys: `leadCache:${customer.id}` and `leadCache:${customer.id}:${stringifiedEventName}`) to provide immediate data availability while Tinybird ingestion happens asynchronously. This caching pattern allows for async-only recording without breaking "wait" mode semantics.

Applied to files:

  • apps/web/lib/api/conversions/track-sale.ts
🧬 Code graph analysis (1)
apps/web/lib/api/conversions/track-sale.ts (1)
apps/web/lib/tinybird/record-lead.ts (1)
  • recordLead (17-20)
⏰ 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 (12)
apps/web/lib/api/conversions/track-lead.ts (1)

144-144: LGTM! Solid defensive programming.

The workspace_id fallback ensures lead events always have workspace context, even if the click event data is incomplete.

apps/web/lib/integrations/shopify/create-lead.ts (1)

68-68: LGTM!

The fallback to customer.projectId ensures workspace_id is always present in Shopify lead events.

apps/web/app/(ee)/api/stripe/integration/webhook/invoice-paid.ts (1)

129-129: LGTM!

The workspace_id fallback ensures sale data maintains correct workspace context when processing Stripe invoice paid events.

apps/web/app/(ee)/api/stripe/integration/webhook/utils/create-new-customer.ts (1)

67-67: LGTM!

The workspace_id fallback ensures new customer lead events always include workspace context.

apps/web/lib/integrations/shopify/create-sale.ts (1)

58-58: LGTM!

The workspace_id fallback ensures Shopify sale events maintain correct workspace association.

apps/web/app/(ee)/api/stripe/integration/webhook/checkout-session-completed.ts (3)

139-146: LGTM!

The workspace_id fallback in the dub_id checkout flow ensures lead events have correct workspace context.


323-337: LGTM!

The workspace_id fallback ensures sale data maintains workspace context across all checkout session scenarios.


626-633: LGTM!

The workspace_id fallback in the promotion code attribution flow ensures lead events have correct workspace context.

apps/web/lib/api/conversions/track-sale.ts (4)

128-131: LGTM!

Adding the workspace_id fallback for cached lead events ensures consistency when Tinybird data isn't immediately available.


133-136: LGTM!

The workspace_id fallback for Tinybird lead events ensures workspace context is always present.


309-312: LGTM!

The workspace_id fallback when recording lead events adds an extra layer of defense for data integrity.


429-441: LGTM!

The workspace_id fallback in saleData construction ensures sale events maintain correct workspace context.


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.

@steven-tey steven-tey merged commit 7b448f7 into main Oct 26, 2025
8 checks passed
@steven-tey steven-tey deleted the polyfill-workspaceid branch October 26, 2025 00:19
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