Skip to content

Fix realtime top stats in limited to segment shared link#6341

Closed
RobertJoonas wants to merge 1 commit into
masterfrom
fix-current-visitors-limited-to-segment
Closed

Fix realtime top stats in limited to segment shared link#6341
RobertJoonas wants to merge 1 commit into
masterfrom
fix-current-visitors-limited-to-segment

Conversation

@RobertJoonas
Copy link
Copy Markdown
Contributor

Changes

Currently the realtime Top Stats are broken in shared links that are limited to a segment. Precisely, the "current visitors" query is what the backend rejects -- StatsController enforces a segment filter via a plug, but the FE simply strips all filters from this query (including the enforced segment one).

Previous behaviour was to skip the plug and allow the current visitors query without the "limited to segment" filter, therefore returning data that is completely out of scope for the given dashboard. Instead of sticking to that behaviour and building an additional flag and ignore it in the new /query endpoint too, I've made the new current visitors metric respect the segment filter. It now removes all other filters except the limited segment one.

Note: This is a quick and dirty fix. I've made some good progress with improving the API v2 interface on the frontend. Planning to have currentVisitors apiState available via a new context (so that the response could be used wherever necessary, i.e. in top stats or the top-bar). That allows us to keep top-stats itself to a single query, with a solid Tanstack QueryKey, etc...

The tests will therefore change too.

Tests

  • In upcoming PR...

Changelog

  • This PR does not make a user-facing change

Documentation

  • This change does not need a documentation update

Dark mode

  • This PR does not change the UI

@RobertJoonas RobertJoonas requested a review from a team May 11, 2026 09:57
})

currentVisitorsQuery.filters = []
const filters = limitedToSegmentId
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue, blocking: This changes the meaning of "Current visitors" top stats block depending on whether the user accesses the dashboard using shared link limited to segment or normally, with the same segment applied.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the decision was to keep the current behaviour where current visitors ignore all filters (including enforced segment). That's now done in #6351, where I've switched current visitors back to the dedicated /current-visitors endpoint. Closing this PR in favour of 6351.

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.

2 participants