Skip to content

feat(segment-session-replay-plugin): integrate TRC targeting evaluation#1536

Draft
lewgordon-amplitude wants to merge 4 commits intomainfrom
SR-2535
Draft

feat(segment-session-replay-plugin): integrate TRC targeting evaluation#1536
lewgordon-amplitude wants to merge 4 commits intomainfrom
SR-2535

Conversation

@lewgordon-amplitude
Copy link
Collaborator

@lewgordon-amplitude lewgordon-amplitude commented Feb 11, 2026

Summary

Added evaluateTargetingAndCapture calls to enable TRC (Targeted Replay Capture) capabilities in the Segment session replay plugin. This brings feature parity with the browser plugin by evaluating targeting conditions before capturing session replays.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

Note

Medium Risk
Changes when session replay capture may start by adding TRC evaluation to the event pipeline; incorrect session-id gating or event mapping could cause replays to be over/under-captured, but the logic is scoped and covered by new unit tests.

Overview
Adds Targeted Replay Capture support to the Segment session replay plugin by calling sessionReplay.evaluateTargetingAndCapture for track/page (via updateSessionIdAndAddProperties) and identify events, converting Segment payloads into Amplitude event format and passing Segment traits as user properties.

Targeting evaluation is skipped for delayed/offline events from older sessions by comparing the event’s integrations['Actions Amplitude'].session_id to the current session, and tests/docs are expanded to cover TRC behavior, timestamp fallbacks, and session gating.

Written by Cursor Bugbot for commit c1cec70. This will update automatically on new commits. Configure here.

Added evaluateTargetingAndCapture calls to enable TRC (Targeted Replay
Capture) capabilities in the Segment session replay plugin. This brings
feature parity with the browser plugin by evaluating targeting conditions
before capturing session replays.

Changes:
- Convert Segment events to Amplitude event format for targeting evaluation
- Call evaluateTargetingAndCapture in track/page methods via updateSessionIdAndAddProperties
- Call evaluateTargetingAndCapture in identify method with user properties
- Added comprehensive test coverage for all edge cases
- Updated README with TRC documentation and important usage notes

SR-2535

Co-authored-by: Cursor <cursoragent@cursor.com>
@lewgordon-amplitude
Copy link
Collaborator Author

bugbot run

…or TRC evaluation

Segment track events contain both `type` ('track') and `event` (actual event name).
TRC event-name rules require the actual event name to match targeting conditions.
Changed priority from `ctx.event.type || ctx.event.event` to `ctx.event.event || ctx.event.type`
so track events like 'Button Clicked' are evaluated correctly instead of generic 'track'.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lewgordon-amplitude
Copy link
Collaborator Author

bugbot run

…le events

Prevents delayed/offline events from older sessions from incorrectly
triggering replay capture for the current session.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lewgordon-amplitude
Copy link
Collaborator Author

bugbot run

…rties

Pass userProperties argument for TRC evaluation and validate session for
identify events to prevent stale data from affecting targeting decisions.

Co-authored-by: Cursor <cursoragent@cursor.com>
@lewgordon-amplitude
Copy link
Collaborator Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

let nextSessionId: number | undefined;
if (ctx.event.integrations && (ctx.event.integrations['Actions Amplitude'] as AmplitudeIntegrationData)) {
nextSessionId = (ctx.event.integrations['Actions Amplitude'] as AmplitudeIntegrationData).session_id;
}
Copy link

Choose a reason for hiding this comment

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

Redundant session ID extraction in identify handler

Low Severity

The nextSessionId extraction from ctx.event.integrations['Actions Amplitude'] duplicates the existing sessionId extraction already performed earlier in the same identify handler (visible at line 70 and above). Both variables end up holding the same value. Reusing the existing sessionId variable would reduce duplication and risk of the two extractions drifting apart.

Fix in Cursor Fix in Web

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