|
|
|
|
@ -6,7 +6,7 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
|
|
|
|
|
describe "GET /api/stats/main-graph - plot" do
|
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
|
|
test "displays pageviews for a day", %{conn: conn, site: site} do
|
|
|
|
|
test "displays visitors for a day", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 00:00:00])
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 23:59:00])
|
|
|
|
|
|
|
|
|
|
@ -33,7 +33,7 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
|
|
|
|
|
assert plot == [0, 1] ++ zeroes # Expecting pageview to show at 1am CET
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "displays pageviews for a month", %{conn: conn, site: site} do
|
|
|
|
|
test "displays visitors for a month", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 12:00:00])
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-31 12:00:00])
|
|
|
|
|
|
|
|
|
|
@ -46,7 +46,7 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
|
|
|
|
|
assert List.last(plot) == 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "displays pageviews for 3 months", %{conn: conn, site: site} do
|
|
|
|
|
test "displays visitors for 3 months", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain)
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: months_ago(2))
|
|
|
|
|
|
|
|
|
|
@ -84,7 +84,7 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "GET /api/stats/main-graph - unique visitors" do
|
|
|
|
|
describe "GET /api/stats/main-graph - top stats" do
|
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
|
|
test "counts distinct user ids", %{conn: conn, site: site} do
|
|
|
|
|
@ -93,21 +93,19 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
|
|
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=day&date=2019-01-01")
|
|
|
|
|
|
|
|
|
|
assert %{"unique_visitors" => 1} = json_response(conn, 200)
|
|
|
|
|
res = json_response(conn, 200)
|
|
|
|
|
assert %{"name" => "Unique visitors", "count" => 1, "change" => 100} in res["top_stats"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "does not count custom events", %{conn: conn, site: site} do
|
|
|
|
|
test "does not count custom events in custom user ids", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 00:00:00])
|
|
|
|
|
insert(:event, name: "Custom", hostname: site.domain, timestamp: ~N[2019-01-01 00:00:00])
|
|
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=day&date=2019-01-01")
|
|
|
|
|
|
|
|
|
|
assert %{"unique_visitors" => 1} = json_response(conn, 200)
|
|
|
|
|
res = json_response(conn, 200)
|
|
|
|
|
assert %{"name" => "Unique visitors", "count" => 1, "change" => 100} in res["top_stats"]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "GET /api/stats/main-graph - pageviews" do
|
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
|
|
test "counts total pageviews even from same user ids", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain, user_id: @user_id, timestamp: ~N[2019-01-01 00:00:00])
|
|
|
|
|
@ -115,43 +113,61 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
|
|
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=day&date=2019-01-01")
|
|
|
|
|
|
|
|
|
|
assert %{"pageviews" => 2} = json_response(conn, 200)
|
|
|
|
|
res = json_response(conn, 200)
|
|
|
|
|
assert %{"name" => "Total pageviews", "count" => 2, "change" => 100} in res["top_stats"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "does not count custom events", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 00:00:00])
|
|
|
|
|
insert(:event, name: "Custom", hostname: site.domain, timestamp: ~N[2019-01-01 00:00:00])
|
|
|
|
|
test "compares pageviews with previous time period", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 01:00:00])
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 02:00:00])
|
|
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=day&date=2019-01-01")
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-02 02:00:00])
|
|
|
|
|
|
|
|
|
|
assert %{"unique_visitors" => 1} = json_response(conn, 200)
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=day&date=2019-01-02")
|
|
|
|
|
|
|
|
|
|
res = json_response(conn, 200)
|
|
|
|
|
assert %{"name" => "Total pageviews", "count" => 1, "change" => -50} in res["top_stats"]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "GET /api/stats/main-graph - comparisons" do
|
|
|
|
|
|
|
|
|
|
describe "GET /api/stats/main-graph - filtered for goal" do
|
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
|
|
test "compares unique users with previous time period", %{conn: conn, site: site} do
|
|
|
|
|
test "returns total unique visitors", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 02:00:00])
|
|
|
|
|
insert(:pageview, hostname: site.domain, user_id: @user_id, timestamp: ~N[2019-01-01 01:00:00])
|
|
|
|
|
insert(:pageview, hostname: site.domain, user_id: @user_id, timestamp: ~N[2019-01-01 02:00:00])
|
|
|
|
|
insert(:event, name: "Signup", hostname: site.domain, user_id: @user_id, timestamp: ~N[2019-01-01 02:00:00])
|
|
|
|
|
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-02 01:00:00])
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-02 02:00:00])
|
|
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=day&date=2019-01-02")
|
|
|
|
|
filters = Jason.encode!(%{goal: "Signup"})
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=day&date=2019-01-01&filters=#{filters}")
|
|
|
|
|
|
|
|
|
|
assert %{"change_visitors" => 100} = json_response(conn, 200)
|
|
|
|
|
res = json_response(conn, 200)
|
|
|
|
|
assert %{"name" => "Total visitors", "count" => 2, "change" => 100} in res["top_stats"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "compares pageviews with previous time period", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 01:00:00])
|
|
|
|
|
test "returns converted visitors", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 02:00:00])
|
|
|
|
|
insert(:pageview, hostname: site.domain, user_id: @user_id, timestamp: ~N[2019-01-01 01:00:00])
|
|
|
|
|
insert(:event, name: "Signup", hostname: site.domain, user_id: @user_id, timestamp: ~N[2019-01-01 02:00:00])
|
|
|
|
|
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-02 02:00:00])
|
|
|
|
|
filters = Jason.encode!(%{goal: "Signup"})
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=month&date=2019-01-01&filters=#{filters}")
|
|
|
|
|
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=day&date=2019-01-02")
|
|
|
|
|
res = json_response(conn, 200)
|
|
|
|
|
assert %{"name" => "Converted visitors", "count" => 1, "change" => 100} in res["top_stats"]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
test "returns conversion rate", %{conn: conn, site: site} do
|
|
|
|
|
insert(:pageview, hostname: site.domain, timestamp: ~N[2019-01-01 02:00:00])
|
|
|
|
|
insert(:pageview, hostname: site.domain, user_id: @user_id, timestamp: ~N[2019-01-01 01:00:00])
|
|
|
|
|
insert(:event, name: "Signup", hostname: site.domain, user_id: @user_id, timestamp: ~N[2019-01-01 02:00:00])
|
|
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{goal: "Signup"})
|
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/main-graph?period=day&date=2019-01-01&filters=#{filters}")
|
|
|
|
|
|
|
|
|
|
assert %{"change_pageviews" => -50} = json_response(conn, 200)
|
|
|
|
|
res = json_response(conn, 200)
|
|
|
|
|
assert %{"name" => "Conversion rate", "percentage" => 50.0, "change" => 100} in res["top_stats"]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|