2019-11-19 07:30:42 +03:00
|
|
|
defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
|
|
|
|
use PlausibleWeb.ConnCase
|
2022-10-24 10:34:02 +03:00
|
|
|
|
2021-07-23 13:44:05 +03:00
|
|
|
@user_id 123
|
2019-11-19 07:30:42 +03:00
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/conversions" 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 mixed conversions in ordered by count", %{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: "/register"),
|
|
|
|
build(:pageview, pathname: "/register"),
|
|
|
|
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["A"]),
|
|
|
|
build(:event,
|
|
|
|
user_id: @user_id,
|
|
|
|
name: "Signup",
|
|
|
|
"meta.key": ["variant"],
|
|
|
|
"meta.value": ["A"]
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
user_id: @user_id,
|
|
|
|
name: "Signup",
|
|
|
|
"meta.key": ["variant"],
|
|
|
|
"meta.value": ["B"]
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
2020-05-18 12:44:52 +03:00
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/register"})
|
2019-11-19 07:30:42 +03:00
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Signup"})
|
|
|
|
|
2021-07-23 13:44:05 +03:00
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/conversions?period=day")
|
2019-11-19 07:30:42 +03:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-11-03 12:20:11 +03:00
|
|
|
%{
|
|
|
|
"name" => "Signup",
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 2,
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 3,
|
2021-09-24 12:03:20 +03:00
|
|
|
"prop_names" => nil,
|
2021-11-22 11:42:51 +03:00
|
|
|
"conversion_rate" => 33.3
|
2020-11-03 12:20:11 +03:00
|
|
|
},
|
|
|
|
%{
|
|
|
|
"name" => "Visit /register",
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 2,
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 2,
|
2020-11-03 12:20:11 +03:00
|
|
|
"prop_names" => nil,
|
2021-11-22 11:42:51 +03:00
|
|
|
"conversion_rate" => 33.3
|
2020-11-03 12:20:11 +03:00
|
|
|
}
|
2020-06-08 10:35:13 +03:00
|
|
|
]
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|
2022-04-21 11:47:15 +03:00
|
|
|
|
|
|
|
test "returns conversions when a direct :is filter on event prop", %{conn: conn, site: site} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:event,
|
|
|
|
user_id: @user_id,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount", "logged_in"],
|
|
|
|
"meta.value": ["100", "true"]
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
user_id: @user_id,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount", "logged_in"],
|
|
|
|
"meta.value": ["500", "true"]
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount", "logged_in"],
|
|
|
|
"meta.value": ["100", "false"]
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount"],
|
|
|
|
"meta.value": ["200"]
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Payment"})
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{props: %{"logged_in" => "true"}})
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/conversions?period=day&filters=#{filters}")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{
|
|
|
|
"name" => "Payment",
|
|
|
|
"unique_conversions" => 1,
|
|
|
|
"total_conversions" => 2,
|
|
|
|
"prop_names" => nil,
|
|
|
|
"conversion_rate" => 33.3
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns conversions when a direct :is_not filter on event prop", %{
|
|
|
|
conn: conn,
|
|
|
|
site: site
|
|
|
|
} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:event,
|
|
|
|
user_id: @user_id,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount", "logged_in"],
|
|
|
|
"meta.value": ["100", "true"]
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
user_id: @user_id,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount", "logged_in"],
|
|
|
|
"meta.value": ["500", "true"]
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount", "logged_in"],
|
|
|
|
"meta.value": ["100", "false"]
|
|
|
|
),
|
|
|
|
build(:event, name: "Payment")
|
|
|
|
])
|
|
|
|
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Payment"})
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{props: %{"logged_in" => "!true"}})
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/conversions?period=day&filters=#{filters}")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{
|
|
|
|
"name" => "Payment",
|
|
|
|
"unique_conversions" => 2,
|
|
|
|
"total_conversions" => 2,
|
|
|
|
"prop_names" => nil,
|
|
|
|
"conversion_rate" => 66.7
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns conversions when a direct :is (none) filter on event prop", %{
|
|
|
|
conn: conn,
|
|
|
|
site: site
|
|
|
|
} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:event,
|
|
|
|
user_id: @user_id,
|
|
|
|
name: "Payment"
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
user_id: @user_id,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount"],
|
|
|
|
"meta.value": ["500"]
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount", "logged_in"],
|
|
|
|
"meta.value": ["100", "false"]
|
|
|
|
),
|
|
|
|
build(:event, name: "Payment")
|
|
|
|
])
|
|
|
|
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Payment"})
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{props: %{"logged_in" => "(none)"}})
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/conversions?period=day&filters=#{filters}")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{
|
|
|
|
"name" => "Payment",
|
|
|
|
"unique_conversions" => 2,
|
|
|
|
"total_conversions" => 3,
|
|
|
|
"prop_names" => nil,
|
|
|
|
"conversion_rate" => 66.7
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns conversions when a direct :is_not (none) filter on event prop", %{
|
|
|
|
conn: conn,
|
|
|
|
site: site
|
|
|
|
} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:event,
|
|
|
|
user_id: @user_id,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount", "logged_in"],
|
|
|
|
"meta.value": ["500", "false"]
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
user_id: @user_id,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount", "logged_in"],
|
|
|
|
"meta.value": ["500", "true"]
|
|
|
|
),
|
|
|
|
build(:event,
|
|
|
|
name: "Payment",
|
|
|
|
"meta.key": ["amount", "logged_in"],
|
|
|
|
"meta.value": ["100", "false"]
|
|
|
|
),
|
|
|
|
build(:event, name: "Payment")
|
|
|
|
])
|
|
|
|
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Payment"})
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{props: %{"logged_in" => "!(none)"}})
|
|
|
|
conn = get(conn, "/api/stats/#{site.domain}/conversions?period=day&filters=#{filters}")
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{
|
|
|
|
"name" => "Payment",
|
|
|
|
"unique_conversions" => 2,
|
|
|
|
"total_conversions" => 3,
|
|
|
|
"prop_names" => nil,
|
|
|
|
"conversion_rate" => 66.7
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|
2019-11-20 11:49:22 +03:00
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/conversions - with goal filter" do
|
2021-07-23 13:44:05 +03:00
|
|
|
setup [:create_user, :log_in, :create_new_site]
|
2019-11-20 11:49:22 +03:00
|
|
|
|
2022-04-11 20:42:40 +03:00
|
|
|
test "returns only the conversion that is filtered for", %{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: "/register"),
|
2021-09-24 11:57:28 +03:00
|
|
|
build(:pageview, pathname: "/register"),
|
2021-07-23 13:44:05 +03:00
|
|
|
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["A"]),
|
|
|
|
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["B"])
|
|
|
|
])
|
|
|
|
|
2020-05-18 12:44:52 +03:00
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/register"})
|
2019-11-20 11:49:22 +03:00
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Signup"})
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{goal: "Signup"})
|
2020-06-08 10:35:13 +03:00
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
2021-07-23 13:44:05 +03:00
|
|
|
"/api/stats/#{site.domain}/conversions?period=day&filters=#{filters}"
|
2020-06-08 10:35:13 +03:00
|
|
|
)
|
2019-11-20 11:49:22 +03:00
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2020-11-03 12:20:11 +03:00
|
|
|
%{
|
|
|
|
"name" => "Signup",
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 2,
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 2,
|
2020-11-03 12:20:11 +03:00
|
|
|
"prop_names" => ["variant"],
|
2021-11-22 11:42:51 +03:00
|
|
|
"conversion_rate" => 33.3
|
2020-11-03 12:20:11 +03:00
|
|
|
}
|
|
|
|
]
|
2019-11-20 11:49:22 +03:00
|
|
|
end
|
|
|
|
end
|
2020-10-28 12:09:04 +03:00
|
|
|
|
2023-02-09 16:56:21 +03:00
|
|
|
describe "GET /api/stats/:domain/conversions - with goal and prop=(none) filter" do
|
|
|
|
setup [:create_user, :log_in, :create_new_site]
|
|
|
|
|
|
|
|
test "returns only the conversion that is filtered for", %{conn: conn, site: site} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview, pathname: "/", user_id: 1),
|
|
|
|
build(:pageview, pathname: "/", user_id: 2),
|
|
|
|
build(:event, name: "Signup", user_id: 1, "meta.key": ["variant"], "meta.value": ["A"]),
|
|
|
|
build(:event, name: "Signup", user_id: 2)
|
|
|
|
])
|
|
|
|
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Signup"})
|
|
|
|
|
|
|
|
filters = Jason.encode!(%{goal: "Signup", props: %{variant: "(none)"}})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/stats/#{site.domain}/conversions?period=day&filters=#{filters}"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{
|
|
|
|
"name" => "Signup",
|
|
|
|
"unique_conversions" => 1,
|
|
|
|
"total_conversions" => 1,
|
|
|
|
"prop_names" => ["variant"],
|
|
|
|
"conversion_rate" => 50
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-30 12:05:19 +03:00
|
|
|
describe "GET /api/stats/:domain/property/:key" do
|
2021-07-23 13:44:05 +03:00
|
|
|
setup [:create_user, :log_in, :create_new_site]
|
|
|
|
|
|
|
|
test "returns property breakdown for goal", %{conn: conn, site: site} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview, pathname: "/"),
|
|
|
|
build(:pageview, pathname: "/"),
|
|
|
|
build(:pageview, pathname: "/register"),
|
|
|
|
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["A"]),
|
|
|
|
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["B"]),
|
|
|
|
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["B"])
|
|
|
|
])
|
2020-10-28 12:09:04 +03:00
|
|
|
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Signup"})
|
|
|
|
filters = Jason.encode!(%{goal: "Signup"})
|
2020-10-30 12:05:19 +03:00
|
|
|
prop_key = "variant"
|
2020-10-28 12:09:04 +03:00
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
2021-07-23 13:44:05 +03:00
|
|
|
"/api/stats/#{site.domain}/property/#{prop_key}?period=day&filters=#{filters}"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2021-11-04 15:20:39 +03:00
|
|
|
%{
|
2021-11-10 17:53:38 +03:00
|
|
|
"unique_conversions" => 2,
|
2021-11-04 15:20:39 +03:00
|
|
|
"name" => "B",
|
|
|
|
"total_conversions" => 2,
|
2021-11-22 11:42:51 +03:00
|
|
|
"conversion_rate" => 33.3
|
2021-11-04 15:20:39 +03:00
|
|
|
},
|
|
|
|
%{
|
2021-11-10 17:53:38 +03:00
|
|
|
"unique_conversions" => 1,
|
2021-11-04 15:20:39 +03:00
|
|
|
"name" => "A",
|
|
|
|
"total_conversions" => 1,
|
2021-11-22 11:42:51 +03:00
|
|
|
"conversion_rate" => 16.7
|
2021-11-04 15:20:39 +03:00
|
|
|
}
|
2021-07-23 13:44:05 +03:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "returns (none) values in property breakdown for goal", %{conn: conn, site: site} do
|
|
|
|
populate_stats(site, [
|
2021-09-24 11:57:28 +03:00
|
|
|
build(:pageview, pathname: "/"),
|
|
|
|
build(:pageview, pathname: "/"),
|
|
|
|
build(:pageview, pathname: "/register"),
|
2021-07-23 13:44:05 +03:00
|
|
|
build(:event, name: "Signup"),
|
|
|
|
build(:event, name: "Signup"),
|
2021-09-24 11:57:28 +03:00
|
|
|
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["A"])
|
2021-07-23 13:44:05 +03:00
|
|
|
])
|
|
|
|
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Signup"})
|
|
|
|
filters = Jason.encode!(%{goal: "Signup"})
|
|
|
|
prop_key = "variant"
|
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/stats/#{site.domain}/property/#{prop_key}?period=day&filters=#{filters}"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2021-11-04 15:20:39 +03:00
|
|
|
%{
|
2021-11-10 17:53:38 +03:00
|
|
|
"unique_conversions" => 2,
|
2021-11-04 15:20:39 +03:00
|
|
|
"name" => "(none)",
|
|
|
|
"total_conversions" => 2,
|
2021-11-22 11:42:51 +03:00
|
|
|
"conversion_rate" => 33.3
|
2021-11-04 15:20:39 +03:00
|
|
|
},
|
|
|
|
%{
|
2021-11-10 17:53:38 +03:00
|
|
|
"unique_conversions" => 1,
|
2021-11-04 15:20:39 +03:00
|
|
|
"name" => "A",
|
|
|
|
"total_conversions" => 1,
|
2021-11-22 11:42:51 +03:00
|
|
|
"conversion_rate" => 16.7
|
2021-11-04 15:20:39 +03:00
|
|
|
}
|
2021-07-23 13:44:05 +03:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "property breakdown with prop filter", %{conn: conn, site: site} do
|
|
|
|
populate_stats(site, [
|
2021-08-19 11:18:15 +03:00
|
|
|
build(:pageview, user_id: 1),
|
|
|
|
build(:event, user_id: 1, name: "Signup", "meta.key": ["variant"], "meta.value": ["A"]),
|
|
|
|
build(:pageview, user_id: 2),
|
|
|
|
build(:event, user_id: 2, name: "Signup", "meta.key": ["variant"], "meta.value": ["B"])
|
2021-07-23 13:44:05 +03:00
|
|
|
])
|
|
|
|
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "Signup"})
|
|
|
|
filters = Jason.encode!(%{goal: "Signup", props: %{"variant" => "B"}})
|
|
|
|
prop_key = "variant"
|
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/stats/#{site.domain}/property/#{prop_key}?period=day&filters=#{filters}"
|
2020-10-28 12:09:04 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
2021-11-04 15:20:39 +03:00
|
|
|
%{
|
2021-11-10 17:53:38 +03:00
|
|
|
"unique_conversions" => 1,
|
2021-11-04 15:20:39 +03:00
|
|
|
"name" => "B",
|
|
|
|
"total_conversions" => 1,
|
|
|
|
"conversion_rate" => 50.0
|
|
|
|
}
|
2020-11-03 12:20:11 +03:00
|
|
|
]
|
2020-10-28 12:09:04 +03:00
|
|
|
end
|
2023-02-09 16:14:09 +03:00
|
|
|
|
|
|
|
test "Property breakdown with prop and goal filter", %{conn: conn, site: site} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview, user_id: 1, utm_campaign: "campaignA"),
|
|
|
|
build(:event,
|
|
|
|
user_id: 1,
|
|
|
|
name: "ButtonClick",
|
|
|
|
"meta.key": ["variant"],
|
|
|
|
"meta.value": ["A"]
|
|
|
|
),
|
|
|
|
build(:pageview, user_id: 2, utm_campaign: "campaignA"),
|
|
|
|
build(:event,
|
|
|
|
user_id: 2,
|
|
|
|
name: "ButtonClick",
|
|
|
|
"meta.key": ["variant"],
|
|
|
|
"meta.value": ["B"]
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "ButtonClick"})
|
|
|
|
|
|
|
|
filters =
|
|
|
|
Jason.encode!(%{
|
|
|
|
goal: "ButtonClick",
|
|
|
|
props: %{variant: "A"},
|
|
|
|
utm_campaign: "campaignA"
|
|
|
|
})
|
|
|
|
|
|
|
|
prop_key = "variant"
|
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/stats/#{site.domain}/property/#{prop_key}?period=day&filters=#{filters}"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{
|
|
|
|
"name" => "A",
|
|
|
|
"unique_conversions" => 1,
|
|
|
|
"total_conversions" => 1,
|
|
|
|
"conversion_rate" => 50.0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
2023-02-14 14:57:38 +03:00
|
|
|
|
|
|
|
test "Property breakdown with goal and source filter", %{conn: conn, site: site} do
|
|
|
|
populate_stats(site, [
|
|
|
|
build(:pageview, user_id: 1, referrer_source: "Google"),
|
|
|
|
build(:event,
|
|
|
|
user_id: 1,
|
|
|
|
name: "ButtonClick",
|
|
|
|
"meta.key": ["variant"],
|
|
|
|
"meta.value": ["A"]
|
|
|
|
),
|
|
|
|
build(:pageview, user_id: 2, referrer_source: "Google"),
|
|
|
|
build(:pageview, user_id: 3, referrer_source: "ignore"),
|
|
|
|
build(:event,
|
|
|
|
user_id: 3,
|
|
|
|
name: "ButtonClick",
|
|
|
|
"meta.key": ["variant"],
|
|
|
|
"meta.value": ["B"]
|
|
|
|
)
|
|
|
|
])
|
|
|
|
|
|
|
|
insert(:goal, %{domain: site.domain, event_name: "ButtonClick"})
|
|
|
|
|
|
|
|
filters =
|
|
|
|
Jason.encode!(%{
|
|
|
|
goal: "ButtonClick",
|
|
|
|
source: "Google"
|
|
|
|
})
|
|
|
|
|
|
|
|
prop_key = "variant"
|
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/stats/#{site.domain}/property/#{prop_key}?period=day&filters=#{filters}"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{
|
|
|
|
"name" => "A",
|
|
|
|
"unique_conversions" => 1,
|
|
|
|
"total_conversions" => 1,
|
|
|
|
"conversion_rate" => 50.0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
2020-10-28 12:09:04 +03:00
|
|
|
end
|
2021-03-02 15:53:03 +03:00
|
|
|
|
|
|
|
describe "GET /api/stats/:domain/conversions - with glob goals" do
|
|
|
|
setup [:create_user, :log_in, :create_site]
|
|
|
|
|
|
|
|
test "returns correct and sorted glob goal counts", %{conn: conn, site: site} do
|
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/register"})
|
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/reg*"})
|
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/*/register"})
|
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/billing**/success"})
|
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/billing*/success"})
|
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/signup"})
|
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/signup/*"})
|
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/signup/**"})
|
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/*"})
|
|
|
|
insert(:goal, %{domain: site.domain, page_path: "/**"})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
get(
|
|
|
|
conn,
|
|
|
|
"/api/stats/#{site.domain}/conversions?period=day&date=2019-07-01"
|
|
|
|
)
|
|
|
|
|
|
|
|
assert json_response(conn, 200) == [
|
|
|
|
%{
|
|
|
|
"conversion_rate" => 100.0,
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 8,
|
2021-03-02 15:53:03 +03:00
|
|
|
"name" => "Visit /**",
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 8,
|
2021-03-02 15:53:03 +03:00
|
|
|
"prop_names" => nil
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"conversion_rate" => 37.5,
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 3,
|
2021-03-02 15:53:03 +03:00
|
|
|
"name" => "Visit /*",
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 3,
|
2021-03-02 15:53:03 +03:00
|
|
|
"prop_names" => nil
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"conversion_rate" => 37.5,
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 3,
|
2021-03-02 15:53:03 +03:00
|
|
|
"name" => "Visit /signup/**",
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 3,
|
2021-03-02 15:53:03 +03:00
|
|
|
"prop_names" => nil
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"conversion_rate" => 25.0,
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 2,
|
2021-03-02 15:53:03 +03:00
|
|
|
"name" => "Visit /billing**/success",
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 2,
|
2021-03-02 15:53:03 +03:00
|
|
|
"prop_names" => nil
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"conversion_rate" => 25.0,
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 2,
|
2021-03-02 15:53:03 +03:00
|
|
|
"name" => "Visit /reg*",
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 2,
|
2021-03-02 15:53:03 +03:00
|
|
|
"prop_names" => nil
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"conversion_rate" => 12.5,
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 1,
|
2021-03-02 15:53:03 +03:00
|
|
|
"name" => "Visit /billing*/success",
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 1,
|
2021-03-02 15:53:03 +03:00
|
|
|
"prop_names" => nil
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"conversion_rate" => 12.5,
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 1,
|
2021-03-02 15:53:03 +03:00
|
|
|
"name" => "Visit /register",
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 1,
|
2021-03-02 15:53:03 +03:00
|
|
|
"prop_names" => nil
|
|
|
|
},
|
|
|
|
%{
|
|
|
|
"conversion_rate" => 12.5,
|
2021-11-05 16:18:59 +03:00
|
|
|
"unique_conversions" => 1,
|
2021-03-02 15:53:03 +03:00
|
|
|
"name" => "Visit /signup/*",
|
2021-11-04 15:20:39 +03:00
|
|
|
"total_conversions" => 1,
|
2021-03-02 15:53:03 +03:00
|
|
|
"prop_names" => nil
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2019-11-19 07:30:42 +03:00
|
|
|
end
|