2019-11-19 07:30:42 +03:00
|
|
|
defmodule PlausibleWeb.Api.StatsController.PagesTest do
|
|
|
|
use PlausibleWeb.ConnCase
|
|
|
|
import Plausible.TestUtils
|
2021-07-23 13:44:05 +03:00
|
|
|
@user_id 123
|
2019-11-19 07:30:42 +03:00
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/pages" do
|
2021-07-23 13:44:05 +03:00
|
|
|
setup [:create_user, :log_in, :create_new_site]
|
2019-11-19 07:30:42 +03:00
|
|
|
|
2020-07-30 11:18:28 +03:00
|
|
|
test "returns top pages by visitors", %{conn: conn, site: site} do
|
2021-07-23 13:44:05 +03:00
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview, pathname: "/"),
|
|
|
|
build(:pageview, pathname: "/"),
|
|
|
|
build(:pageview, pathname: "/"),
|
|
|
|
build(:pageview, pathname: "/register"),
|
|
|
|
build(:pageview, pathname: "/register"),
|
|
|
|
build(:pageview, pathname: "/contact")
|
|
|
|
])
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/pages?period=day")
|
2019-11-19 07:30:42 +03:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2021-07-23 13:44:05 +03:00
|
|
|
%{"count" => 3, "name" => "/"},
|
|
|
|
%{"count" => 2, "name" => "/register"},
|
|
|
|
%{"count" => 1, "name" => "/contact"}
|
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
|
|
|
|
2021-05-18 15:14:33 +03:00
|
|
|
test "calculates bounce rate and time on page for pages", %{conn: conn, site: site} do
|
2021-07-23 13:44:05 +03:00
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/",
|
|
|
|
user_id: @user_id,
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/some-other-page",
|
|
|
|
user_id: @user_id,
|
|
|
|
timestamp: ~N[2021-01-01 00:15:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/",
|
|
|
|
timestamp: ~N[2021-01-01 00:15:00]
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
2020-06-08 10:35:13 +03:00
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
2021-07-23 13:44:05 +03:00
|
|
|
"/api/stats/#{site.domain}/pages?period=day&date=2021-01-01&detailed=true"
|
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
|
|
|
%{
|
2021-07-23 13:44:05 +03:00
|
|
|
"bounce_rate" => 50.0,
|
|
|
|
"time_on_page" => 900.0,
|
2020-11-03 12:20:11 +03:00
|
|
|
"count" => 2,
|
|
|
|
"pageviews" => 2,
|
2021-07-23 13:44:05 +03:00
|
|
|
"name" => "/"
|
2020-11-03 12:20:11 +03:00
|
|
|
},
|
|
|
|
%{
|
|
|
|
"bounce_rate" => nil,
|
2021-05-18 15:14:33 +03:00
|
|
|
"time_on_page" => nil,
|
2020-11-03 12:20:11 +03:00
|
|
|
"count" => 1,
|
|
|
|
"pageviews" => 1,
|
2021-07-23 13:44:05 +03:00
|
|
|
"name" => "/some-other-page"
|
2020-11-03 12:20:11 +03:00
|
|
|
}
|
|
|
|
]
|
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
|
2021-07-23 13:44:05 +03:00
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview, pathname: "/page1"),
|
|
|
|
build(:pageview, pathname: "/page2"),
|
|
|
|
build(:pageview, pathname: "/page1")
|
|
|
|
])
|
|
|
|
|
2020-07-14 16:52:26 +03:00
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/pages?period=realtime")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2021-07-23 13:44:05 +03:00
|
|
|
%{"count" => 2, "name" => "/page1"},
|
|
|
|
%{"count" => 1, "name" => "/page2"}
|
2020-07-30 11:18:28 +03:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/entry-pages" do
|
2021-07-23 13:44:05 +03:00
|
|
|
setup [:create_user, :log_in, :create_new_site]
|
2020-07-30 11:18:28 +03:00
|
|
|
|
|
|
|
test "returns top entry pages by visitors", %{conn: conn, site: site} do
|
2021-07-23 13:44:05 +03:00
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/page1",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/page1",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/page2",
|
|
|
|
user_id: @user_id,
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/page2",
|
|
|
|
user_id: @user_id,
|
|
|
|
timestamp: ~N[2021-01-01 00:15:00]
|
|
|
|
)
|
|
|
|
])
|
2020-07-30 11:18:28 +03:00
|
|
|
|
2021-07-23 13:44:05 +03:00
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/page2",
|
|
|
|
user_id: @user_id,
|
|
|
|
timestamp: ~N[2021-01-01 23:15:00]
|
2020-07-30 11:18:28 +03:00
|
|
|
)
|
2021-07-23 13:44:05 +03:00
|
|
|
])
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/entry-pages?period=day&date=2021-01-01")
|
2020-07-30 11:18:28 +03:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-11-03 12:20:11 +03:00
|
|
|
%{
|
2021-07-23 13:44:05 +03:00
|
|
|
"count" => 2,
|
|
|
|
"entries" => 2,
|
|
|
|
"name" => "/page1",
|
|
|
|
"visit_duration" => 0
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"count" => 1,
|
|
|
|
"entries" => 2,
|
|
|
|
"name" => "/page2",
|
|
|
|
"visit_duration" => 450
|
2020-11-03 12:20:11 +03:00
|
|
|
}
|
|
|
|
]
|
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
|
2021-07-23 13:44:05 +03:00
|
|
|
setup [:create_user, :log_in, :create_new_site]
|
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 "returns top exit pages by visitors", %{conn: conn, site: site} do
|
2021-07-23 13:44:05 +03:00
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/page1",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/page1",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/page1",
|
|
|
|
user_id: @user_id,
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
pathname: "/page2",
|
|
|
|
user_id: @user_id,
|
|
|
|
timestamp: ~N[2021-01-01 00:15:00]
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/exit-pages?period=day&date=2021-01-01")
|
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
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2021-08-18 14:49:39 +03:00
|
|
|
%{"name" => "/page1", "count" => 2, "exits" => 2, "exit_rate" => 66},
|
2021-07-23 13:44:05 +03:00
|
|
|
%{"name" => "/page2", "count" => 1, "exits" => 1, "exit_rate" => 100}
|
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
|
|
|
]
|
|
|
|
end
|
2021-08-19 10:32:03 +03:00
|
|
|
|
|
|
|
test "calculates correct exit rate when filtering for goal", %{conn: conn, site: site} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:event,
|
|
|
|
name: "Signup",
|
|
|
|
user_id: 1,
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 1,
|
|
|
|
pathname: "/exit1",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
name: "Signup",
|
|
|
|
user_id: 2,
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 2,
|
|
|
|
pathname: "/exit1",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 2,
|
|
|
|
pathname: "/exit2",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{"goal" => "Signup"})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/stats/#{site.domain}/exit-pages?period=day&date=2021-01-01&filters=#{filters}"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{"name" => "/exit1", "count" => 1, "exits" => 1, "exit_rate" => 50},
|
|
|
|
%{"name" => "/exit2", "count" => 1, "exits" => 1, "exit_rate" => 100}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "calculates correct exit rate when filtering for page", %{conn: conn, site: site} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 1,
|
|
|
|
pathname: "/exit1",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 2,
|
|
|
|
pathname: "/exit1",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 2,
|
|
|
|
pathname: "/exit2",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 3,
|
|
|
|
pathname: "/exit2",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 3,
|
|
|
|
pathname: "/should-not-appear",
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{"page" => "/exit1"})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/stats/#{site.domain}/exit-pages?period=day&date=2021-01-01&filters=#{filters}"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{"name" => "/exit1", "count" => 1, "exits" => 1, "exit_rate" => 50},
|
|
|
|
%{"name" => "/exit2", "count" => 1, "exits" => 1, "exit_rate" => 100}
|
|
|
|
]
|
|
|
|
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
|
|
|
end
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|