2019-11-19 07:30:42 +03:00
|
|
|
defmodule PlausibleWeb.Api.StatsController.PagesTest do
|
|
|
|
use PlausibleWeb.ConnCase
|
|
|
|
import Plausible.TestUtils
|
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/pages" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
2020-07-30 11:18:28 +03:00
|
|
|
test "returns top pages by visitors", %{conn: conn, site: site} do
|
2019-11-19 07:30:42 +03:00
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/pages?period=day&date=2019-01-01")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
Adds entry and exit pages to Top Pages module (#712)
* Initial Pass
* Adds support for page visits counting by referrer
* Includes goal selection in entry and exit computation
* Adds goal-based entry and exit page stats, formatting, code cleanup
* Changelog
* Format
* Exit rate, visit duration, updated tests
* I keep forgetting to format :/
* Tests, last time
* Fixes double counting, exit rate >100%, relevant tests
* Fixes exit pages on filter and goal states
* Adds entry and exit filters, fixes various bugs
* Fixes discussed issues
* Format
* Fixes impossible case in tests
Originally, there were only 2 pageviews for `test-site.com`,`/` on `2019-01-01`, but that doesn't make sense when there were 3 sessions that exited on the same site/date.
* Format
* Removes boolean function parameter in favor of separate function
* Adds support for queries that use `page` filter as `entry-page`
* Format
* Makes loader/title interaction in sources report consistent
2021-02-26 12:02:37 +03:00
|
|
|
%{"count" => 3, "pageviews" => 3, "name" => "/"},
|
2020-07-30 11:18:28 +03:00
|
|
|
%{"count" => 2, "pageviews" => 2, "name" => "/register"},
|
|
|
|
%{"count" => 1, "pageviews" => 1, "name" => "/contact"},
|
|
|
|
%{"count" => 1, "pageviews" => 1, "name" => "/irrelevant"}
|
2020-06-08 10:35:13 +03:00
|
|
|
]
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|
2020-01-06 16:51:43 +03:00
|
|
|
|
2020-07-30 11:18:28 +03:00
|
|
|
test "calculates bounce rate for pages", %{conn: conn, site: site} do
|
2020-06-08 10:35:13 +03:00
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
2020-07-30 11:18:28 +03:00
|
|
|
"/api/stats/#{site.domain}/pages?period=day&date=2019-01-01&include=bounce_rate"
|
2020-06-08 10:35:13 +03:00
|
|
|
)
|
2020-01-06 16:51:43 +03:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-11-03 12:20:11 +03:00
|
|
|
%{
|
|
|
|
"bounce_rate" => 33.0,
|
Adds entry and exit pages to Top Pages module (#712)
* Initial Pass
* Adds support for page visits counting by referrer
* Includes goal selection in entry and exit computation
* Adds goal-based entry and exit page stats, formatting, code cleanup
* Changelog
* Format
* Exit rate, visit duration, updated tests
* I keep forgetting to format :/
* Tests, last time
* Fixes double counting, exit rate >100%, relevant tests
* Fixes exit pages on filter and goal states
* Adds entry and exit filters, fixes various bugs
* Fixes discussed issues
* Format
* Fixes impossible case in tests
Originally, there were only 2 pageviews for `test-site.com`,`/` on `2019-01-01`, but that doesn't make sense when there were 3 sessions that exited on the same site/date.
* Format
* Removes boolean function parameter in favor of separate function
* Adds support for queries that use `page` filter as `entry-page`
* Format
* Makes loader/title interaction in sources report consistent
2021-02-26 12:02:37 +03:00
|
|
|
"count" => 3,
|
|
|
|
"pageviews" => 3,
|
2020-11-03 12:20:11 +03:00
|
|
|
"name" => "/"
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"bounce_rate" => nil,
|
|
|
|
"count" => 2,
|
|
|
|
"pageviews" => 2,
|
|
|
|
"name" => "/register"
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"bounce_rate" => nil,
|
|
|
|
"count" => 1,
|
|
|
|
"pageviews" => 1,
|
|
|
|
"name" => "/contact"
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"bounce_rate" => nil,
|
|
|
|
"count" => 1,
|
|
|
|
"pageviews" => 1,
|
|
|
|
"name" => "/irrelevant"
|
|
|
|
}
|
|
|
|
]
|
2020-01-06 16:51:43 +03:00
|
|
|
end
|
2020-07-14 16:52:26 +03:00
|
|
|
|
|
|
|
test "returns top pages in realtime report", %{conn: conn, site: site} do
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/pages?period=realtime")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-07-30 11:18:28 +03:00
|
|
|
%{"count" => 2, "name" => "/exit"},
|
|
|
|
%{"count" => 1, "name" => "/"}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/entry-pages" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
test "returns top entry pages by visitors", %{conn: conn, site: site} do
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/entry-pages?period=day&date=2019-01-01")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
Adds entry and exit pages to Top Pages module (#712)
* Initial Pass
* Adds support for page visits counting by referrer
* Includes goal selection in entry and exit computation
* Adds goal-based entry and exit page stats, formatting, code cleanup
* Changelog
* Format
* Exit rate, visit duration, updated tests
* I keep forgetting to format :/
* Tests, last time
* Fixes double counting, exit rate >100%, relevant tests
* Fixes exit pages on filter and goal states
* Adds entry and exit filters, fixes various bugs
* Fixes discussed issues
* Format
* Fixes impossible case in tests
Originally, there were only 2 pageviews for `test-site.com`,`/` on `2019-01-01`, but that doesn't make sense when there were 3 sessions that exited on the same site/date.
* Format
* Removes boolean function parameter in favor of separate function
* Adds support for queries that use `page` filter as `entry-page`
* Format
* Makes loader/title interaction in sources report consistent
2021-02-26 12:02:37 +03:00
|
|
|
%{
|
|
|
|
"count" => 3,
|
|
|
|
"entries" => 3,
|
|
|
|
"name" => "/",
|
2021-03-24 12:19:10 +03:00
|
|
|
"visit_duration" => 67
|
Adds entry and exit pages to Top Pages module (#712)
* Initial Pass
* Adds support for page visits counting by referrer
* Includes goal selection in entry and exit computation
* Adds goal-based entry and exit page stats, formatting, code cleanup
* Changelog
* Format
* Exit rate, visit duration, updated tests
* I keep forgetting to format :/
* Tests, last time
* Fixes double counting, exit rate >100%, relevant tests
* Fixes exit pages on filter and goal states
* Adds entry and exit filters, fixes various bugs
* Fixes discussed issues
* Format
* Fixes impossible case in tests
Originally, there were only 2 pageviews for `test-site.com`,`/` on `2019-01-01`, but that doesn't make sense when there were 3 sessions that exited on the same site/date.
* Format
* Removes boolean function parameter in favor of separate function
* Adds support for queries that use `page` filter as `entry-page`
* Format
* Makes loader/title interaction in sources report consistent
2021-02-26 12:02:37 +03:00
|
|
|
}
|
2020-07-14 16:52:26 +03:00
|
|
|
]
|
|
|
|
end
|
2020-07-30 11:18:28 +03:00
|
|
|
|
Adds entry and exit pages to Top Pages module (#712)
* Initial Pass
* Adds support for page visits counting by referrer
* Includes goal selection in entry and exit computation
* Adds goal-based entry and exit page stats, formatting, code cleanup
* Changelog
* Format
* Exit rate, visit duration, updated tests
* I keep forgetting to format :/
* Tests, last time
* Fixes double counting, exit rate >100%, relevant tests
* Fixes exit pages on filter and goal states
* Adds entry and exit filters, fixes various bugs
* Fixes discussed issues
* Format
* Fixes impossible case in tests
Originally, there were only 2 pageviews for `test-site.com`,`/` on `2019-01-01`, but that doesn't make sense when there were 3 sessions that exited on the same site/date.
* Format
* Removes boolean function parameter in favor of separate function
* Adds support for queries that use `page` filter as `entry-page`
* Format
* Makes loader/title interaction in sources report consistent
2021-02-26 12:02:37 +03:00
|
|
|
test "calculates visit duration for entry pages", %{conn: conn, site: site} do
|
2020-07-30 11:18:28 +03:00
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
Adds entry and exit pages to Top Pages module (#712)
* Initial Pass
* Adds support for page visits counting by referrer
* Includes goal selection in entry and exit computation
* Adds goal-based entry and exit page stats, formatting, code cleanup
* Changelog
* Format
* Exit rate, visit duration, updated tests
* I keep forgetting to format :/
* Tests, last time
* Fixes double counting, exit rate >100%, relevant tests
* Fixes exit pages on filter and goal states
* Adds entry and exit filters, fixes various bugs
* Fixes discussed issues
* Format
* Fixes impossible case in tests
Originally, there were only 2 pageviews for `test-site.com`,`/` on `2019-01-01`, but that doesn't make sense when there were 3 sessions that exited on the same site/date.
* Format
* Removes boolean function parameter in favor of separate function
* Adds support for queries that use `page` filter as `entry-page`
* Format
* Makes loader/title interaction in sources report consistent
2021-02-26 12:02:37 +03:00
|
|
|
"/api/stats/#{site.domain}/entry-pages?period=day&date=2019-01-01"
|
2020-07-30 11:18:28 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-11-03 12:20:11 +03:00
|
|
|
%{
|
2021-03-24 12:19:10 +03:00
|
|
|
"visit_duration" => 67,
|
2020-11-03 12:20:11 +03:00
|
|
|
"count" => 3,
|
Adds entry and exit pages to Top Pages module (#712)
* Initial Pass
* Adds support for page visits counting by referrer
* Includes goal selection in entry and exit computation
* Adds goal-based entry and exit page stats, formatting, code cleanup
* Changelog
* Format
* Exit rate, visit duration, updated tests
* I keep forgetting to format :/
* Tests, last time
* Fixes double counting, exit rate >100%, relevant tests
* Fixes exit pages on filter and goal states
* Adds entry and exit filters, fixes various bugs
* Fixes discussed issues
* Format
* Fixes impossible case in tests
Originally, there were only 2 pageviews for `test-site.com`,`/` on `2019-01-01`, but that doesn't make sense when there were 3 sessions that exited on the same site/date.
* Format
* Removes boolean function parameter in favor of separate function
* Adds support for queries that use `page` filter as `entry-page`
* Format
* Makes loader/title interaction in sources report consistent
2021-02-26 12:02:37 +03:00
|
|
|
"entries" => 3,
|
2020-11-03 12:20:11 +03:00
|
|
|
"name" => "/"
|
|
|
|
}
|
|
|
|
]
|
2020-07-30 11:18:28 +03:00
|
|
|
end
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|
Adds entry and exit pages to Top Pages module (#712)
* Initial Pass
* Adds support for page visits counting by referrer
* Includes goal selection in entry and exit computation
* Adds goal-based entry and exit page stats, formatting, code cleanup
* Changelog
* Format
* Exit rate, visit duration, updated tests
* I keep forgetting to format :/
* Tests, last time
* Fixes double counting, exit rate >100%, relevant tests
* Fixes exit pages on filter and goal states
* Adds entry and exit filters, fixes various bugs
* Fixes discussed issues
* Format
* Fixes impossible case in tests
Originally, there were only 2 pageviews for `test-site.com`,`/` on `2019-01-01`, but that doesn't make sense when there were 3 sessions that exited on the same site/date.
* Format
* Removes boolean function parameter in favor of separate function
* Adds support for queries that use `page` filter as `entry-page`
* Format
* Makes loader/title interaction in sources report consistent
2021-02-26 12:02:37 +03:00
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/exit-pages" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
test "returns top exit pages by visitors", %{conn: conn, site: site} do
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/exit-pages?period=day&date=2019-01-01")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{"count" => 3, "exits" => 3, "name" => "/", "exit_rate" => 100.0}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|