Ignore sessions without entry/exit pages when breaking down entry/exit pages (#3933)

* Ignore sessions without entry/exit pages when breaking down entry/exit pages

* Update stats controller tests to have more realistic test data (pageview followed by event)
dependabot/npm_and_yarn/tracker/express-4.19.2 r2024.03.26-414
Karl-Aksel Puulmann 3 years ago committed by GitHub
parent 2fae0146a4
commit 4af7019011
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -57,6 +57,7 @@ All notable changes to this project will be documented in this file.
- Validate metric isn't queried multiple times
### Fixed
- Ignore sessions without pageviews for `entry_page` and `exit_page` breakdowns
- Using `VersionedCollapsingMergeTree` to store visit data to avoid rare race conditions that led to wrong visit data being shown
- Fix `conversion_rate` metric in a `browser_versions` breakdown
- Calculate `conversion_rate` percentage change in the same way like `bounce_rate` (subtraction instead of division)

@ -529,6 +529,8 @@ defmodule Plausible.Stats.Breakdown do
defp do_group_by(q, "visit:entry_page") do
from(
s in q,
# Sessions without pageviews don't get entry_page assigned, hence they should get ignored
where: s.entry_page != "",
group_by: s.entry_page,
select_merge: %{entry_page: s.entry_page},
order_by: {:asc, s.entry_page}
@ -538,6 +540,8 @@ defmodule Plausible.Stats.Breakdown do
defp do_group_by(q, "visit:exit_page") do
from(
s in q,
# Sessions without pageviews don't get entry_page assigned, hence they should get ignored
where: s.entry_page != "",
group_by: s.exit_page,
select_merge: %{exit_page: s.exit_page},
order_by: {:asc, s.exit_page}

@ -1,2 +1,2 @@
name,conversions,conversion_rate
,1,100.0
/signup,1,100.0

1 name conversions conversion_rate
2 /signup 1 100.0

@ -1,2 +1,2 @@
name,conversions,conversion_rate
,1,100.0
/signup,1,100.0

1 name conversions conversion_rate
2 /signup 1 100.0

@ -1,3 +1,3 @@
property,value,visitors,events,percentage
variant,(none),3,4,75.0
variant,A,1,1,25.0
variant,A,1,2,25.0

1 property value visitors events percentage
2 variant (none) 3 4 75.0
3 variant A 1 1 2 25.0

@ -1,3 +1,3 @@
name,unique_entrances,total_entrances,visit_duration
/,3,3,20
,1,1,0
/signup,1,1,60

1 name unique_entrances total_entrances visit_duration
2 / 3 3 20
3 /signup 1 1 0 60

@ -1,4 +1,4 @@
name,unique_exits,total_exits,exit_rate
/,2,2,66.0
,1,1,
/signup,1,1,100.0
/some-other-page,1,1,100.0

1 name unique_exits total_exits exit_rate
2 / 2 2 66.0
3 /signup 1 1 100.0
4 /some-other-page 1 1 100.0

@ -1,3 +1,4 @@
name,visitors,pageviews,bounce_rate,time_on_page
/,4,3,67,
/signup,1,1,0,60.0
/some-other-page,1,1,,60.0

1 name visitors pageviews bounce_rate time_on_page
2 / 4 3 67
3 /signup 1 1 0 60.0
4 /some-other-page 1 1 60.0

@ -1,2 +1,2 @@
name,visitors,bounce_rate,visit_duration
Direct / None,4,75,15
Direct / None,4,50,30

1 name visitors bounce_rate visit_duration
2 Direct / None 4 75 50 15 30

@ -1,3 +1,3 @@
name,visitors,bounce_rate,visit_duration
Direct / None,3,100,0
Direct / None,3,67,20
Google,1,0,60

1 name visitors bounce_rate visit_duration
2 Direct / None 3 100 67 0 20
3 Google 1 0 60

@ -28,5 +28,5 @@ date,visitors,pageviews,visits,views_per_visit,bounce_rate,visit_duration
2021-10-16,0,0,0,0.0,,
2021-10-17,0,0,0,0.0,,
2021-10-18,0,0,0,0.0,,
2021-10-19,2,1,2,0.5,100,0
2021-10-19,2,2,2,1.0,50,30
2021-10-20,1,2,1,2.0,0,60

1 date visitors pageviews visits views_per_visit bounce_rate visit_duration
28 2021-10-16 0 0 0 0.0
29 2021-10-17 0 0 0 0.0
30 2021-10-18 0 0 0 0.0
31 2021-10-19 2 1 2 2 0.5 1.0 100 50 0 30
32 2021-10-20 1 2 1 2.0 0 60

@ -1,3 +1,3 @@
property,value,visitors,events,percentage
variant,(none),4,5,80.0
variant,A,1,1,20.0
variant,A,1,2,20.0

1 property value visitors events percentage
2 variant (none) 4 5 80.0
3 variant A 1 1 2 20.0

@ -1,3 +1,3 @@
name,unique_entrances,total_entrances,visit_duration
/,4,4,15
,1,1,0
/signup,1,1,60

1 name unique_entrances total_entrances visit_duration
2 / 4 4 15
3 /signup 1 1 0 60

@ -1,4 +1,4 @@
name,unique_exits,total_exits,exit_rate
/,3,3,75.0
,1,1,
/signup,1,1,100.0
/some-other-page,1,1,100.0

1 name unique_exits total_exits exit_rate
2 / 3 3 75.0
3 /signup 1 1 100.0
4 /some-other-page 1 1 100.0

@ -1,3 +1,4 @@
name,visitors,pageviews,bounce_rate,time_on_page
/,5,4,75,
/signup,1,1,0,60.0
/some-other-page,1,1,,60.0

1 name visitors pageviews bounce_rate time_on_page
2 / 5 4 75
3 /signup 1 1 0 60.0
4 /some-other-page 1 1 60.0

@ -1,2 +1,2 @@
name,visitors,bounce_rate,visit_duration
Direct / None,5,80,12
Direct / None,5,60,24

1 name visitors bounce_rate visit_duration
2 Direct / None 5 80 60 12 24

@ -1,3 +1,3 @@
name,visitors,bounce_rate,visit_duration
Direct / None,3,100,0
Direct / None,3,67,20
Google,2,50,30

1 name visitors bounce_rate visit_duration
2 Direct / None 3 100 67 0 20
3 Google 2 50 30

@ -4,4 +4,4 @@ date,visitors,pageviews,visits,views_per_visit,bounce_rate,visit_duration
2021-07-01,0,0,0,0.0,,
2021-08-01,0,0,0,0.0,,
2021-09-01,1,1,1,1.0,100,0
2021-10-01,3,3,3,1.0,67,20
2021-10-01,3,4,3,1.33,33,40

1 date visitors pageviews visits views_per_visit bounce_rate visit_duration
4 2021-07-01 0 0 0 0.0
5 2021-08-01 0 0 0 0.0
6 2021-09-01 1 1 1 1.0 100 0
7 2021-10-01 3 3 4 3 1.0 1.33 67 33 20 40

@ -1324,6 +1324,24 @@ defmodule PlausibleWeb.Api.StatsController.PagesTest do
}
]
end
test "ignores entry pages from sessions with only custom events", %{conn: conn, site: site} do
populate_stats(site, [
build(:event,
name: "Signup",
timestamp: ~N[2021-01-01 00:15:00],
pathname: "/"
)
])
conn =
get(
conn,
"/api/stats/#{site.domain}/entry-pages?period=day&date=2021-01-01"
)
assert json_response(conn, 200) == []
end
end
describe "GET /api/stats/:domain/exit-pages" do
@ -1557,5 +1575,23 @@ defmodule PlausibleWeb.Api.StatsController.PagesTest do
%{"name" => "/exit2", "visitors" => 1, "visits" => 1}
]
end
test "ignores exit pages from sessions with only custom events", %{conn: conn, site: site} do
populate_stats(site, [
build(:event,
name: "Signup",
timestamp: ~N[2021-01-01 00:15:00],
pathname: "/"
)
])
conn =
get(
conn,
"/api/stats/#{site.domain}/exit-pages?period=day&date=2021-01-01"
)
assert json_response(conn, 200) == []
end
end
end

@ -285,7 +285,7 @@ defmodule PlausibleWeb.StatsControllerTest do
["2021-09-27", "0", "0", "0", "0.0", "", ""],
["2021-10-04", "0", "0", "0", "0.0", "", ""],
["2021-10-11", "0", "0", "0", "0.0", "", ""],
["2021-10-18", "3", "3", "3", "1.0", "67", "20"],
["2021-10-18", "3", "4", "3", "1.33", "33", "40"],
[""]
]
end
@ -469,7 +469,17 @@ defmodule PlausibleWeb.StatsControllerTest do
browser: "FirefoxNoVersion",
operating_system: "MacNoVersion"
),
build(:pageview,
user_id: 456,
timestamp:
Timex.shift(~N[2021-10-20 12:00:00], days: -1, minutes: -1)
|> NaiveDateTime.truncate(:second),
pathname: "/signup",
"meta.key": ["variant"],
"meta.value": ["A"]
),
build(:event,
user_id: 456,
timestamp:
Timex.shift(~N[2021-10-20 12:00:00], days: -1) |> NaiveDateTime.truncate(:second),
name: "Signup",

Loading…
Cancel
Save