|
|
|
|
@ -25,6 +25,37 @@ defmodule PlausibleWeb.Api.StatsController.PagesTest do
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns top pages by visitors by hostname", %{conn: conn1, site: site} do
|
|
|
|
|
populate_stats(site, [
|
|
|
|
|
build(:pageview, pathname: "/", hostname: "a.example.com"),
|
|
|
|
|
build(:pageview, pathname: "/", hostname: "b.example.com"),
|
|
|
|
|
build(:pageview, pathname: "/", hostname: "d.example.com"),
|
|
|
|
|
build(:pageview, pathname: "/landing", hostname: "x.example.com", user_id: 123),
|
|
|
|
|
build(:pageview, pathname: "/register", hostname: "d.example.com", user_id: 123),
|
|
|
|
|
build(:pageview, pathname: "/register", hostname: "d.example.com", user_id: 123),
|
|
|
|
|
build(:pageview, pathname: "/register", hostname: "d.example.com"),
|
|
|
|
|
build(:pageview, pathname: "/contact", hostname: "e.example.com")
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{"hostname" => "*.example.com"})
|
|
|
|
|
conn = get(conn1, "/api/stats/#{site.domain}/pages?period=day&filters=#{filters}")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
|
%{"visitors" => 3, "name" => "/"},
|
|
|
|
|
%{"visitors" => 2, "name" => "/register"},
|
|
|
|
|
%{"visitors" => 1, "name" => "/contact"},
|
|
|
|
|
%{"visitors" => 1, "name" => "/landing"}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{"hostname" => "d.example.com"})
|
|
|
|
|
conn = get(conn1, "/api/stats/#{site.domain}/pages?period=day&filters=#{filters}")
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
|
%{"visitors" => 2, "name" => "/register"},
|
|
|
|
|
%{"visitors" => 1, "name" => "/"}
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns top pages with :is filter on custom pageview props", %{conn: conn, site: site} do
|
|
|
|
|
populate_stats(site, [
|
|
|
|
|
build(:pageview,
|
|
|
|
|
@ -888,6 +919,81 @@ defmodule PlausibleWeb.Api.StatsController.PagesTest do
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "calculates bounce rate and time on page for pages when filtered by hostname", %{
|
|
|
|
|
conn: conn,
|
|
|
|
|
site: site
|
|
|
|
|
} do
|
|
|
|
|
populate_stats(site, [
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/about",
|
|
|
|
|
hostname: "blog.example.com",
|
|
|
|
|
user_id: @user_id + 1,
|
|
|
|
|
timestamp: ~N[2021-01-01 00:01:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/about",
|
|
|
|
|
hostname: "example.com",
|
|
|
|
|
user_id: @user_id,
|
|
|
|
|
timestamp: ~N[2021-01-01 00:01:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/about",
|
|
|
|
|
hostname: "blog.example.com",
|
|
|
|
|
user_id: @user_id,
|
|
|
|
|
timestamp: ~N[2021-01-01 00:10:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/about",
|
|
|
|
|
hostname: "blog.example.com",
|
|
|
|
|
user_id: @user_id,
|
|
|
|
|
timestamp: ~N[2021-01-01 00:15:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/exit-blog",
|
|
|
|
|
hostname: "blog.example.com",
|
|
|
|
|
timestamp: ~N[2021-01-01 00:20:00],
|
|
|
|
|
user_id: @user_id
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/about",
|
|
|
|
|
hostname: "example.com",
|
|
|
|
|
timestamp: ~N[2021-01-01 00:20:00],
|
|
|
|
|
user_id: @user_id
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/exit",
|
|
|
|
|
hostname: "example.com",
|
|
|
|
|
timestamp: ~N[2021-01-01 00:25:00],
|
|
|
|
|
user_id: @user_id
|
|
|
|
|
)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{"hostname" => "blog.example.com"})
|
|
|
|
|
|
|
|
|
|
conn =
|
|
|
|
|
get(
|
|
|
|
|
conn,
|
|
|
|
|
"/api/stats/#{site.domain}/pages?period=day&date=2021-01-01&detailed=true&filters=#{filters}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
|
%{
|
|
|
|
|
"bounce_rate" => 50,
|
|
|
|
|
"name" => "/about",
|
|
|
|
|
"pageviews" => 3,
|
|
|
|
|
"time_on_page" => 600.0,
|
|
|
|
|
"visitors" => 2
|
|
|
|
|
},
|
|
|
|
|
%{
|
|
|
|
|
"bounce_rate" => nil,
|
|
|
|
|
"name" => "/exit-blog",
|
|
|
|
|
"pageviews" => 1,
|
|
|
|
|
"time_on_page" => nil,
|
|
|
|
|
"visitors" => 1
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "doesn't calculate time on page with only single page visits", %{conn: conn, site: site} do
|
|
|
|
|
populate_stats(site, [
|
|
|
|
|
build(:pageview, pathname: "/", user_id: @user_id, timestamp: ~N[2021-01-01 00:00:00]),
|
|
|
|
|
@ -1227,6 +1333,68 @@ defmodule PlausibleWeb.Api.StatsController.PagesTest do
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns top entry pages by visitors filtered by hostname", %{conn: conn, site: site} do
|
|
|
|
|
populate_stats(site, [
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/page1",
|
|
|
|
|
hostname: "en.example.com",
|
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/page1",
|
|
|
|
|
hostname: "es.example.com",
|
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/page2",
|
|
|
|
|
hostname: "en.example.com",
|
|
|
|
|
user_id: @user_id,
|
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/page2",
|
|
|
|
|
hostname: "es.example.com",
|
|
|
|
|
user_id: @user_id,
|
|
|
|
|
timestamp: ~N[2021-01-01 00:15:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/exit",
|
|
|
|
|
hostname: "es.example.com",
|
|
|
|
|
user_id: @user_id,
|
|
|
|
|
timestamp: ~N[2021-01-01 00:16:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/page2",
|
|
|
|
|
hostname: "es.example.com",
|
|
|
|
|
user_id: @user_id,
|
|
|
|
|
timestamp: ~N[2021-01-01 23:15:00]
|
|
|
|
|
)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{"hostname" => "es.example.com"})
|
|
|
|
|
|
|
|
|
|
conn =
|
|
|
|
|
get(
|
|
|
|
|
conn,
|
|
|
|
|
"/api/stats/#{site.domain}/entry-pages?period=day&date=2021-01-01&filters=#{filters}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
|
%{
|
|
|
|
|
"visitors" => 1,
|
|
|
|
|
"visits" => 1,
|
|
|
|
|
"name" => "/page1",
|
|
|
|
|
"visit_duration" => 0
|
|
|
|
|
},
|
|
|
|
|
%{
|
|
|
|
|
"visitors" => 1,
|
|
|
|
|
"visits" => 2,
|
|
|
|
|
"name" => "/page2",
|
|
|
|
|
"visit_duration" => 480
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "bugfix: pagination on /pages filtered by goal", %{conn: conn, site: site} do
|
|
|
|
|
populate_stats(
|
|
|
|
|
site,
|
|
|
|
|
@ -1377,6 +1545,53 @@ defmodule PlausibleWeb.Api.StatsController.PagesTest do
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns top exit pages by visitors filtered by hostname", %{conn: conn, site: site} do
|
|
|
|
|
populate_stats(site, [
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/page1",
|
|
|
|
|
hostname: "en.example.com",
|
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/page1",
|
|
|
|
|
hostname: "es.example.com",
|
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/page1",
|
|
|
|
|
hostname: "en.example.com",
|
|
|
|
|
user_id: @user_id,
|
|
|
|
|
timestamp: ~N[2021-01-01 00:00:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/page2",
|
|
|
|
|
hostname: "es.example.com",
|
|
|
|
|
user_id: @user_id,
|
|
|
|
|
timestamp: ~N[2021-01-01 00:15:00]
|
|
|
|
|
),
|
|
|
|
|
build(:pageview,
|
|
|
|
|
pathname: "/exit",
|
|
|
|
|
hostname: "es.example.com",
|
|
|
|
|
user_id: @user_id,
|
|
|
|
|
timestamp: ~N[2021-01-01 00:16:00]
|
|
|
|
|
)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{hostname: "es.example.com"})
|
|
|
|
|
|
|
|
|
|
conn =
|
|
|
|
|
get(
|
|
|
|
|
conn,
|
|
|
|
|
"/api/stats/#{site.domain}/exit-pages?period=day&date=2021-01-01&filters=#{filters}"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert json_response(conn, 200) ==
|
|
|
|
|
[
|
|
|
|
|
%{"name" => "/exit", "visitors" => 1, "visits" => 1},
|
|
|
|
|
%{"name" => "/page1", "visitors" => 1, "visits" => 1}
|
|
|
|
|
]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns top exit pages filtered by custom pageview props", %{conn: conn, site: site} do
|
|
|
|
|
populate_stats(site, [
|
|
|
|
|
build(:pageview,
|
|
|
|
|
|