-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Singular integration #2637
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
Singular integration #2637
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughA new Singular integration was implemented, including webhook endpoints, event tracking, and URL handling. Core lead and sale tracking logic was refactored into reusable functions, simplifying API route handlers. Type definitions were standardized and decoupled from Zod schemas. Middleware and utility functions were updated to support Singular-specific tracking and URL patterns. Minor improvements and adjustments were made to page caching, error logging, and integration scripts. Changes
Sequence Diagram(s)Singular Webhook Event FlowsequenceDiagram
participant Singular
participant API as /api/singular/webhook
participant DB as Database
participant Lead as trackLead
participant Sale as trackSale
Singular->>API: GET /api/singular/webhook?...
API->>API: Validate SINGULAR_WEBHOOK_TOKEN and query params
API->>DB: Lookup workspace by dub_workspace_id
API->>API: Map event_name to internal type
alt event_name == "lead"
API->>Lead: trackLead(params, workspace)
Lead-->>API: Lead tracking result
else event_name == "sale"
API->>Sale: trackSale(params, workspace)
Sale-->>API: Sale tracking result
end
API-->>Singular: JSON { "OK": true }
Lead/Sale Tracking DelegationsequenceDiagram
participant Route as /api/track/lead or /api/track/sale
participant Logic as trackLead/trackSale
participant DB as Database
participant Redis as Redis
participant Webhook as Workspace Webhook
Route->>Logic: Call with parsed params and workspace
Logic->>Redis: Deduplication (lead/sale)
Logic->>DB: Lookup or upsert customer/lead/sale
Logic->>Webhook: Send event notification
Logic-->>Route: Tracking result
Route-->>Client: JSON response
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
💤 Files with no reviewable changes (2)
🧰 Additional context used🧠 Learnings (2)📓 Common learnings
apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx (1)
🧬 Code Graph Analysis (1)apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx (3)
⏰ 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)
🔇 Additional comments (1)
✨ Finishing Touches
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. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
…ic, remove deprecated functions, and enhance error handling. Introduce new trackLead and trackSale functions for improved event processing.
…nt trackSale function for sale event processing. Refactor sale tracking logic in Singular integration to enhance clarity and maintainability.
…ransformation, add metadata parameter to trackLead and trackSale functions for improved data handling.
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/lib/api/conversions/track-lead.ts (1)
74-76
: Simplify nested property access with optional chaining.The current nested property access can be simplified using optional chaining for better readability and safety.
- if (clickEvent && clickEvent.data && clickEvent.data.length > 0) { + if (clickEvent?.data?.length > 0) { clickData = clickEvent.data[0]; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/web/app/(ee)/api/track/lead/route.ts
(2 hunks)apps/web/lib/api/conversions/track-lead.ts
(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: devkiran
PR: dubinc/dub#2637
File: apps/web/app/(ee)/api/singular/webhook/route.ts:0-0
Timestamp: 2025-07-17T06:41:45.598Z
Learning: In the Singular integration (apps/web/app/(ee)/api/singular/webhook/route.ts), the event names in the singularToDubEvent object have intentionally different casing: "Copy GAID" and "copy IDFA". This casing difference is valid and should not be changed, as these are the correct event names expected from Singular.
apps/web/lib/api/conversions/track-lead.ts (1)
Learnt from: devkiran
PR: dubinc/dub#2637
File: apps/web/app/(ee)/api/singular/webhook/route.ts:0-0
Timestamp: 2025-07-17T06:41:45.598Z
Learning: In the Singular integration (apps/web/app/(ee)/api/singular/webhook/route.ts), the event names in the singularToDubEvent object have intentionally different casing: "Copy GAID" and "copy IDFA". This casing difference is valid and should not be changed, as these are the correct event names expected from Singular.
🧬 Code Graph Analysis (1)
apps/web/app/(ee)/api/track/lead/route.ts (1)
apps/web/lib/api/conversions/track-lead.ts (1)
trackLead
(28-288)
🪛 Biome (1.9.4)
apps/web/lib/api/conversions/track-lead.ts
[error] 74-74: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🔇 Additional comments (8)
apps/web/app/(ee)/api/track/lead/route.ts (2)
1-1
: Excellent refactoring approach!The centralization of lead tracking logic into a dedicated module improves maintainability and follows good separation of concerns.
44-58
: Clean delegation to centralized tracking function!The refactored implementation correctly passes all necessary parameters to the centralized
trackLead
function and maintains the same API contract. This approach improves code maintainability while preserving all original functionality.apps/web/lib/api/conversions/track-lead.ts (6)
23-26
: Well-structured type definitions!The
TrackLeadParams
type properly extends the Zod schema input while adding the necessaryrawBody
andworkspace
properties for the internal function. This ensures type safety throughout the tracking workflow.
41-59
: Robust deduplication implementation!The Redis-based deduplication logic is well-designed with:
- Proper cache key structure including workspace, customer, and event name
- Appropriate 1-week expiration to prevent indefinite storage
- NX flag to ensure atomic duplicate prevention
- String normalization correctly uses
replaceAll
for multiple spaces
104-148
: Well-structured database operations!The helper functions are excellently designed:
upsertCustomer
properly handles both creation and update scenarioscreateLeadEventPayload
efficiently supports multiple event quantities with unique IDs- Clean separation of concerns improves maintainability
152-189
: Excellent async/sync mode handling!The implementation properly differentiates between synchronous and asynchronous modes:
- "wait" mode executes customer creation and lead recording synchronously for immediate consistency
- "async" mode defers operations to background processing for better performance
- Proper use of
waitUntil
for serverless environments
191-264
: Comprehensive background processing workflow!The background processing efficiently handles all necessary operations:
- Proper parallelization of link updates, workspace usage, and conversion logging
- Conditional partner commission creation with appropriate checks
- Avatar persistence to R2 storage with proper dimensions
- Webhook dispatch with transformed event data
268-288
: Well-structured response with backwards compatibility!The response formatting properly:
- Validates response structure with Zod schema
- Maintains API consistency for existing clients
- Includes backwards compatibility fields with clear deprecation comments
- Provides clean migration path for future API updates
Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Chores