diff --git a/CHANGELOG.md b/CHANGELOG.md index a7d83e61f..d10878721 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. - 'Last updated X seconds ago' info to 'current visitors' tooltips ### Fixed +- Fix [more pageviews with session prop filter than with no filters](https://github.com/plausible/analytics/issues/1666) - Cascade delete sent_renewal_notifications table when user is deleted plausible/analytics#2549 - Show appropriate top-stat metric labels on the realtime dashboard when filtering by a goal - Fix breakdown API pagination when using event metrics plausible/analytics#2562 diff --git a/lib/plausible/stats/base.ex b/lib/plausible/stats/base.ex index b381a9165..24de1aeb9 100644 --- a/lib/plausible/stats/base.ex +++ b/lib/plausible/stats/base.ex @@ -14,7 +14,9 @@ defmodule Plausible.Stats.Base do sessions_q = from( s in query_sessions(site, query), - select: %{session_id: s.session_id} + select: %{session_id: s.session_id}, + where: s.sign == 1, + group_by: s.session_id ) from( diff --git a/test/plausible_web/controllers/api/external_stats_controller/aggregate_test.exs b/test/plausible_web/controllers/api/external_stats_controller/aggregate_test.exs index d9c6c3c03..76f83201e 100644 --- a/test/plausible_web/controllers/api/external_stats_controller/aggregate_test.exs +++ b/test/plausible_web/controllers/api/external_stats_controller/aggregate_test.exs @@ -798,5 +798,31 @@ defmodule PlausibleWeb.Api.ExternalStatsController.AggregateTest do assert json_response(conn, 200)["results"] == %{"visitors" => %{"value" => 3}} end + + test "joins correctly with the sessions (CollapsingMergeTree) table", %{ + conn: conn, + site: site + } do + create_sessions([ + %{domain: site.domain, session_id: 1000, country_code: "EE", sign: 1, events: 1}, + %{domain: site.domain, session_id: 1000, country_code: "EE", sign: -1, events: 1}, + %{domain: site.domain, session_id: 1000, country_code: "EE", sign: 1, events: 2} + ]) + + create_events([ + %{domain: site.domain, session_id: 1000, country_code: "EE", name: "pageview"}, + %{domain: site.domain, session_id: 1000, country_code: "EE", name: "pageview"}, + %{domain: site.domain, session_id: 1000, country_code: "EE", name: "pageview"} + ]) + + conn = + get(conn, "/api/v1/stats/aggregate", %{ + "site_id" => site.domain, + "metrics" => "pageviews", + "filters" => "visit:country==EE" + }) + + assert json_response(conn, 200)["results"] == %{"pageviews" => %{"value" => 3}} + end end end