+
Skip to content

Conversation

steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Sep 10, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Lead tracking now returns a structured response with null click/customer instead of an error when no click can be inferred, improving resilience.
    • API response fields for lead tracking (click, customer) are now nullable for clearer edge-case handling.
  • Documentation

    • Updated wording to “direct sale tracking” across relevant messages and descriptions for consistency.
  • Tests

    • Renamed a sale tracking test to reflect the new “direct sale tracking” terminology.

Copy link
Contributor

vercel bot commented Sep 10, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Sep 10, 2025 11:45pm

Copy link
Contributor

coderabbitai bot commented Sep 10, 2025

Walkthrough

Introduces an early null-return path in lead tracking when no clickId/customer exists and updates the lead response schema to allow nullable click/customer. Sale tracking files and tests receive terminology changes to “direct sale tracking” without altering behavior.

Changes

Cohort / File(s) Summary
Lead tracking flow & schema
apps/web/lib/api/conversions/track-lead.ts, apps/web/lib/zod/schemas/leads.ts
Lead flow now short-circuits with a structured null response when no clickId and no resolvable customer. trackLeadResponseSchema updated: click and customer are now nullable. No exported signature changes besides schema nullability.
Sale tracking terminology
apps/web/lib/api/conversions/track-sale.ts, apps/web/lib/zod/schemas/sales.ts, apps/web/tests/tracks/track-sale.test.ts
Replaced references to “sale tracking without a pre-existing lead event” with “direct sale tracking” across code, schema field descriptions, and a test title. No functional or type changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant API as TrackLead API
  participant DB as DB

  Client->>API: POST /track-lead (externalId?, clickId?)
  alt No clickId AND no customer with clickId
    API-->>Client: 200 { click: null, customer: null }
  else clickId present or customer has clickId
    API->>DB: Lookup click/customer and process lead
    DB-->>API: Records found/created
    API-->>Client: 200 { click: {id}, customer: {...} }
  end

  note over API: Early-return path replaces previous error in the no-click/no-customer branch.
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • devkiran

Pre-merge checks (3 passed)

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Add noop response to /track/lead (instead of error)" accurately and concisely summarizes the primary change — switching the /track/lead flow to return a noop/null response rather than throwing an error — and aligns with the track-lead.ts and leads schema updates in the changeset. It is specific to the endpoint and behavior and contains no noisy or unrelated information.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Poem

A nibble of nulls in the clovery lead,
I hop past errors—no need to plead.
Sales speak “direct,” crisp as the breeze,
Schemas now shrug with nullable ease.
Thump-thump! The flow is clean and small—
A rabbit approves, ears high for the call. 🐇✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

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

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: 0

🧹 Nitpick comments (2)
apps/web/lib/api/conversions/track-lead.ts (1)

55-60: Add observability for the noop path to match sale endpoint behavior

Log the noop decision (like sale does) to aid debugging and metrics parity.

   if (!clickId) {
     if (!customer || !customer.clickId) {
-      return trackLeadResponseSchema.parse({
+      waitUntil(
+        logConversionEvent({
+          workspace_id: workspace.id,
+          path: "/track/lead",
+          body: JSON.stringify(rawBody),
+          error:
+            `No existing customer with customerExternalId (${customerExternalId}) and no clickId provided. Returning noop.`,
+        }),
+      );
+      return trackLeadResponseSchema.parse({
         click: null,
         customer: null,
       });
     }
apps/web/lib/zod/schemas/sales.ts (1)

60-60: Keep comments consistent with new terminology

Update the inline comment to say “direct sale tracking.”

-  // advanced fields: leadEventName + fields for sale tracking without a  lead event
+  // advanced fields: leadEventName + fields for direct sale tracking
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93ec75d and f727540.

📒 Files selected for processing (5)
  • apps/web/lib/api/conversions/track-lead.ts (1 hunks)
  • apps/web/lib/api/conversions/track-sale.ts (1 hunks)
  • apps/web/lib/zod/schemas/leads.ts (1 hunks)
  • apps/web/lib/zod/schemas/sales.ts (1 hunks)
  • apps/web/tests/tracks/track-sale.test.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/lib/api/conversions/track-lead.ts (1)
apps/web/lib/zod/schemas/leads.ts (1)
  • trackLeadResponseSchema (75-89)
⏰ 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). (2)
  • GitHub Check: Vade Review
  • GitHub Check: build
🔇 Additional comments (4)
apps/web/lib/zod/schemas/leads.ts (1)

76-88: Schema nullability change aligns with noop response — verify downstream null-safety

trackLead response now makes click and customer nullable; search found unguarded reads that may break on noop responses. Verify or guard these call sites:

  • apps/web/app/(ee)/api/events/export/route.ts — column accessors use r.customer.name and r.click.id (no null-checks).
  • apps/web/lib/integrations/slack/transform.ts — templates interpolate customer.name / customer.email directly.
  • apps/web/lib/integrations/segment/transform.ts — uses customer.externalId and click.ip without guards.
  • apps/web/tests/tracks/track-lead-client.test.ts and apps/web/tests/tracks/track-lead.test.ts — some assertions expect a non-null customer; add/null-case coverage.
  • UI components mostly use fallbacks (customer.name || customer.email, avatar fallbacks) — still scan for direct interpolations and string templates.

Verify callers tolerate null (optional chaining, fallbacks, or narrowed types) and update tests/integrations where needed.

apps/web/tests/tracks/track-sale.test.ts (1)

230-230: Terminology rename LGTM

Test name now matches “direct sale tracking.” No behavior change.

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

126-135: Message copy aligns with “direct sale tracking”

Good consistency update; behavior unchanged.

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

66-96: Copy updates for direct sale tracking LGTM

Descriptions for leadEventName, clickId, customerName, customerEmail, and customerAvatar look good.

@steven-tey steven-tey merged commit e15843d into main Sep 10, 2025
8 of 9 checks passed
@steven-tey steven-tey deleted the lead-noop branch September 10, 2025 23:49
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.

1 participant

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载