Repository navigation
feat(react-native): support session replay v2 trigger groups - #5239
Open
marc-merino wants to merge 1 commit into
Open
marc-merino wants to merge 1 commit into
marc-merino wants to merge 1 commit into
Conversation
Evaluate the v2 trigger groups from the sessionRecording remote config in the JS layer, which owns the event and screen conditions on React Native: per-group event, screen and flag conditions combined with any/all, per-group sampling with the same hash as posthog-js, and recording when any activated group is sampled in. The $sdk_debug_replay_* properties report the matched groups. Configs without version 2 keep the v1 behaviour. Assisted-by: OpenCode/glm-5.3 Assisted-by: Claude Code/claude-opus-5-5
This was referenced Oct 7, 2026
Open
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Knit Bundle
View bundle
This PR is part of Knit bundle
session-replay-v2-trigger-groups-on-mobile.See the other review objects in this bundle:
posthog-ios: feat(replay): support session replay v2 trigger groups posthog-ios#921posthog-android: feat(replay): support session replay v2 trigger groups posthog-android#850posthog-flutter: feat(replay): raise native floors for session replay v2 trigger groups posthog-flutter#648posthog-js: feat(react-native): support session replay v2 trigger groups #5239 (this PR)Bundle id:
session-replay-v2-trigger-groups-on-mobileBundle title: Session replay v2 trigger groups on mobile
Problem
Closes #4595.
The server and posthog-js already support session replay v2 trigger groups (
sessionRecording.version: 2with atriggerGroupsarray). posthog-react-native only reads the v1linkedFlag/eventTriggersfields, so with a v2 config it started recording without applying the per-group conditions or sampling.Changes
On React Native, events and screens are captured in JS and never reach the native SDK, so the JS layer owns the trigger-group decision (
src/session-replay/triggerGroups.ts), mirroring posthog-jsV2TriggerGroupStrategy:any/all. Screen names ($screen_name) take the place of URLs. A group with no conditions activates immediately.sessionId + groupId), so web and mobile reach the same decision for a session.sampleRateisn't forwarded to the native plugin, since per-group sampling replaces it.$sdk_debug_replay_remote_trigger_matching_config,$sdk_debug_replay_trigger_groups_countand$sdk_debug_replay_matched_recording_trigger_groupsmatch posthog-js.versionis missing or 1.minDurationMs. JS computes it (it's in the debug log), but the native plugin can't receive it yet. Passing it needs an addition to the plugin API, so I'd rather agree that with you first.Companion PRs (linked in the Knit block above) teach posthog-android and posthog-ios the same groups, and make them skip the event and screen conditions under React Native, so the native layer doesn't evaluate what it can't see. I'd especially like a sanity check on that split. The sdk-specs hybrid section currently describes v2 as web-only; happy to add the mobile behaviour there in a follow-up.
node .agents/skills/replay-incident-risk/check.mjsreports no incident-pattern matches.How did you test it?
pnpm test:unitinpackages/react-native: 1284 pass; types check.examples/example-expo-57on an Android 15 emulator, pointed at a local mock PostHog server:button_clickedwithsampleRate: 0andopen_replay_screen_tappedwithsampleRate: 1. Afterbutton_clicked:record=false, the group reportsmatched: true, sampled: false. After the "Fire 'open_replay_screen_tapped'" button:record=true, the native recorder resumes andisSessionReplayActive()returnstrue.explore:record=falseon the home tab,record=trueand recording resumes after opening the Explore tab ((tabs)/explore).$snapshotuploads reached the mock, for v2 and equally for the existing v1 event trigger, so I verified the JS decision and nativeisEnabled()rather than uploaded snapshots. The plugin still bundles posthog-android 3.71.6.Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)