Skip to content

Get rid of old /top-stats endpoint#6176

Open
RobertJoonas wants to merge 4 commits intomasterfrom
get-rid-of-top-stats
Open

Get rid of old /top-stats endpoint#6176
RobertJoonas wants to merge 4 commits intomasterfrom
get-rid-of-top-stats

Conversation

@RobertJoonas
Copy link
Contributor

@RobertJoonas RobertJoonas commented Mar 19, 2026

Changes

Could have been done sooner (with the actual endpoint switch) but I mistakenly thought it's needed for Dashboard CSV export. Which it's not.

The top_stats_test.exs probably gives the query API v2 a good amount of extra coverage. This PR modernizes that file to keep that coverage:

  • Query the new endpoint instead, where applicable.
  • Tests such as those asserting on the metric selection based on query state, or a returned graph_metric key were removed
  • Instead of asserting on with_imported_switch_info, we now assert on query.skip_imports_reason and query.imports_included in all the same scenarios.
  • Some more basic tests, such as "counts unique visitors" or "counts pageviews" were also removed.

Rewriting the tests uncovered two issues:

  1. [unrelated to top stats migration] - when scroll depth is queried alone, and with imported data included, the native query aggregation doesn't work (out of scope here, added a ticket on basecamp)
  2. time on page is returned as nil (instead of 0 as before) when it cannot be calculated. For users it means that Top Stats will simply hide the metric. I've updated the test to assert on nil.

Tests

  • Automated tests have been added

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

With the switch to the /query endpoint, the aggregate query with a page
filter started returning `time_on_page` as `nil` without any engagement
data, instead of 0 as before. When this happens, Time on Page is simply
hidden in Top Stats.
@RobertJoonas RobertJoonas requested a review from a team March 19, 2026 09:55
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