2019-11-19 07:30:42 +03:00
|
|
|
defmodule PlausibleWeb.Api.StatsController.CountriesTest do
|
|
|
|
use PlausibleWeb.ConnCase
|
|
|
|
import Plausible.TestUtils
|
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/countries" 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
|
|
|
|
|
|
|
test "returns top countries by new visitors", %{conn: conn, site: site} do
|
2021-07-23 13:44:05 +03:00
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview,
|
|
|
|
country_code: "EE"
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
country_code: "EE"
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
country_code: "GB"
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/countries?period=day")
|
2019-11-19 07:30:42 +03:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-06-08 10:35:13 +03:00
|
|
|
%{
|
|
|
|
"name" => "EST",
|
|
|
|
"count" => 2,
|
2021-07-23 13:44:05 +03:00
|
|
|
"percentage" => 67
|
2020-06-08 10:35:13 +03:00
|
|
|
},
|
|
|
|
%{
|
|
|
|
"name" => "GBR",
|
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" => 1,
|
2021-07-23 13:44:05 +03:00
|
|
|
"percentage" => 33
|
2020-06-08 10:35:13 +03:00
|
|
|
}
|
|
|
|
]
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|
2021-09-20 17:17:11 +03:00
|
|
|
|
|
|
|
test "calculates conversion_rate when filtering for goal", %{conn: conn, site: site} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 1,
|
|
|
|
country_code: "EE"
|
|
|
|
),
|
|
|
|
build(:event, user_id: 1, name: "Signup"),
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 2,
|
|
|
|
country_code: "EE"
|
|
|
|
),
|
|
|
|
build(:pageview,
|
|
|
|
user_id: 3,
|
|
|
|
country_code: "GB"
|
|
|
|
),
|
|
|
|
build(:event, user_id: 3, name: "Signup")
|
|
|
|
])
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{"goal" => "Signup"})
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/countries?period=day&filters=#{filters}")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{
|
|
|
|
"name" => "GBR",
|
2021-09-29 14:28:29 +03:00
|
|
|
"total_visitors" => 1,
|
2021-09-20 17:17:11 +03:00
|
|
|
"count" => 1,
|
|
|
|
"percentage" => 50,
|
|
|
|
"conversion_rate" => 100.0
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"name" => "EST",
|
2021-09-29 14:28:29 +03:00
|
|
|
"total_visitors" => 2,
|
2021-09-20 17:17:11 +03:00
|
|
|
"count" => 1,
|
|
|
|
"percentage" => 50,
|
|
|
|
"conversion_rate" => 50.0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|
|
|
|
end
|