Skip to content

✨ server: add source to segment events#759

Open
aguxez wants to merge 1 commit intomainfrom
source-events
Open

✨ server: add source to segment events#759
aguxez wants to merge 1 commit intomainfrom
source-events

Conversation

@aguxez
Copy link
Contributor

@aguxez aguxez commented Feb 11, 2026

Summary by CodeRabbit

  • New Features
    • Event tracking and analytics now include a standardized credential "source" across card actions (issued, frozen/unfrozen, deleted), account events, and transaction flows (authorized, refunded, rejected).
    • Telemetry and tracing payloads consistently carry the source property for improved event context and reporting.

Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2026

🦋 Changeset detected

Latest commit: 727ec7d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@exactly/server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link

Summary of Changes

Hello @aguxez, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enriching the event data sent to Segment by adding a 'source' property to key user actions. This enhancement allows for a more comprehensive understanding of where user interactions originate, which is crucial for improved analytics and decision-making regarding user acquisition and engagement strategies.

Highlights

  • Enhanced Event Tracking: The pull request introduces a source property to various Segment events, providing more detailed context about the origin of user actions.
  • Database Query Updates: Database queries for credentials have been modified across several files to explicitly fetch the source column, ensuring this data is available for tracking.
  • Segment track Call Modifications: Numerous track function calls for events such as CardIssued, CardUnfrozen, CardDeleted, CardFrozen, AccountFunded, TransactionAuthorized, AuthorizationRejected, TransactionRejected, and TransactionRefund now include the source property.
  • Type Definition Updates: The track function's type definition in server/utils/segment.ts has been updated to correctly reflect the inclusion of the new SourceProperty for relevant events.
Changelog
  • .changeset/lemon-mice-look.md
    • Added a new changeset file for the patch.
  • server/api/card.ts
    • Modified database queries to include the source column for credentials.
    • Updated track calls to pass the source property for card-related events like CardIssued, CardUnfrozen, CardDeleted, and CardFrozen.
  • server/hooks/activity.ts
    • Updated credential queries to fetch the source property.
    • Modified the pokes map and track calls to include the source for AccountFunded events.
  • server/hooks/panda.ts
    • Extended credential queries to retrieve the source property.
    • Updated multiple track calls for transaction-related events (TransactionAuthorized, AuthorizationRejected, TransactionRejected, TransactionRefund) to pass the source property.
  • server/utils/segment.ts
    • Defined a new SourceProperty type.
    • Updated the track function's type definitions to incorporate the source property for various Segment events.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

Walkthrough

Threads the credential source field through server flows: DB selects include source; hooks and the card API propagate it; analytics event types and tracking calls are extended to attach source to emitted Segment events.

Changes

Cohort / File(s) Summary
Changeset
/.changeset/lemon-mice-look.md
Adds a patch changeset for @exactly/server with note "✨ add source to segment events".
Event type & tracking
server/utils/segment.ts
Adds exported `SourceProperty = { source: null
Card API
server/api/card.ts
Includes credential.source in DB selects and attaches credential.source to CardIssued and card-status tracking events.
Activity hook
server/hooks/activity.ts
Extends account query/destructuring to include source; updates pokes map value type to carry source; propagates source into tracing and Promise.allSettled consumers.
Panda hook
server/hooks/panda.ts
Fetches credential source; adds optional source parameter to tracking helpers and threads card.credential.source into all transaction/authorization tracking calls; minor typing tweaks (e.g., explicit onHash handler type).

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API as Server API
    participant DB as Database
    participant Hook as Hook (panda/activity)
    participant Segment as Analytics

    Client->>API: issue/transaction/update request
    API->>DB: fetch credential (include source)
    DB-->>API: credential { ..., source }
    API->>Hook: invoke flow (pass card, credential.source)
    Hook->>Segment: track(event { ..., source })
    Hook-->>API: flow result
    API-->>Client: response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • nfmelendez
  • cruzdanilo
🚥 Pre-merge checks | ✅ 3
✅ 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 source to segment events' clearly and concisely summarizes the main objective of the changeset, which adds a source field across multiple segment event tracking functions and types.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 source-events

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.

@sentry
Copy link

sentry bot commented Feb 11, 2026

✅ All tests passed.

Copy link

@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: 1

Caution

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

⚠️ Outside diff range comments (1)
server/utils/segment.ts (1)

42-52: 🧹 Nitpick | 🔵 Trivial

Onramp and RampAccount still use inline source instead of SourceProperty.

For consistency with the other events, these two could also use SourceProperty & to keep DRY.

♻️ Suggested refactor
     | {
         event: "Onramp";
-        properties: {
+        properties: SourceProperty & {
           currency: string;
           fiatAmount: number;
           provider: "bridge" | "manteca";
-          source: null | string;
           usdcAmount: number;
         };
       }
-    | { event: "RampAccount"; properties: { provider: "bridge" | "manteca"; source: null | string } }
+    | { event: "RampAccount"; properties: SourceProperty & { provider: "bridge" | "manteca" } }
🤖 Fix all issues with AI agents
In `@server/api/card.ts`:
- Line 233: The GET handler is selecting credential.source (columns: { account,
pandaId, source }) but never uses it; remove source from the selected columns to
avoid unnecessary data retrieval. Update the query that builds the projection
(the object with columns: { account: true, pandaId: true, source: true }) to
only include account and pandaId, ensuring no other code in the GET handler
(e.g., response construction or tracking/event emission) expects source.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a source property to various Segment events, enhancing analytics by tracking user origin. The changes are consistently applied across multiple files, fetching the source from the database and propagating it to the tracking events. The type definitions for these events have been updated accordingly. The implementation is clean, correct, and follows existing patterns. I also appreciate the minor unrelated type additions, which improve code clarity. Overall, this is a solid contribution.

Copy link

@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.

Caution

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

⚠️ Outside diff range comments (1)
server/utils/segment.ts (1)

42-52: 🧹 Nitpick | 🔵 Trivial

Onramp and RampAccount still use inline source: null | string instead of SourceProperty.

These two events define source inline rather than using the new SourceProperty type. If the semantic meaning of source is the same (credential origin), consider unifying them with SourceProperty for consistency. If source has a different meaning for ramp events (e.g., referral/provider context), the current split is fine — just worth confirming.

Copy link

@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.

Caution

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

⚠️ Outside diff range comments (1)
server/utils/segment.ts (1)

42-52: 🛠️ Refactor suggestion | 🟠 Major

Inconsistency: Onramp and RampAccount still inline source instead of using SourceProperty.

These two events define source: null | string directly rather than using the new SourceProperty type. This was presumably the pre-existing pattern, but now that SourceProperty exists, aligning them would be consistent.

♻️ Suggested fix
     | {
         event: "Onramp";
-        properties: {
+        properties: SourceProperty & {
           currency: string;
           fiatAmount: number;
           provider: "bridge" | "manteca";
-          source: null | string;
           usdcAmount: number;
         };
       }
-    | { event: "RampAccount"; properties: { provider: "bridge" | "manteca"; source: null | string } }
+    | { event: "RampAccount"; properties: SourceProperty & { provider: "bridge" | "manteca" } }

Copy link

@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: 1

Caution

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

⚠️ Outside diff range comments (1)
server/utils/segment.ts (1)

42-52: 🧹 Nitpick | 🔵 Trivial

Onramp and RampAccount still duplicate source: null | string inline instead of using SourceProperty.

For consistency with all the other events now using SourceProperty, these two should be refactored to use it as well.

♻️ Proposed fix
     | {
         event: "Onramp";
-        properties: {
+        properties: SourceProperty & {
           currency: string;
           fiatAmount: number;
           provider: "bridge" | "manteca";
-          source: null | string;
           usdcAmount: number;
         };
       }
-    | { event: "RampAccount"; properties: { provider: "bridge" | "manteca"; source: null | string } }
+    | { event: "RampAccount"; properties: SourceProperty & { provider: "bridge" | "manteca" } }

@aguxez aguxez marked this pull request as ready for review February 13, 2026 16:37
Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

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