mirror of
https://github.com/plausible/analytics.git
synced 2024-12-24 10:02:10 +03:00
Fix how sampling is applied when filtering for a goal
This commit is contained in:
parent
2f3bee800d
commit
f42f4da44b
@ -23,7 +23,9 @@ defmodule Plausible.Stats.Props do
|
||||
end)
|
||||
end
|
||||
else
|
||||
query = Plausible.Stats.Query.remove_goal(query)
|
||||
query =
|
||||
Plausible.Stats.Query.remove_goal(query)
|
||||
|> Plausible.Stats.Query.put_filter("event:name", nil)
|
||||
|
||||
ClickhouseRepo.all(
|
||||
from e in base_event_query(site, query),
|
||||
|
@ -192,7 +192,7 @@ defmodule Plausible.Stats.Query do
|
||||
query.filters
|
||||
|> Map.drop(props)
|
||||
|> Map.delete("event:goal")
|
||||
|> Map.delete("event:name")
|
||||
|> Map.put("event:name", {:is, "pageview"})
|
||||
|
||||
%__MODULE__{query | filters: new_filters}
|
||||
end
|
||||
|
@ -38,14 +38,14 @@ defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
|
||||
"count" => 2,
|
||||
"total_count" => 3,
|
||||
"prop_names" => ["variant"],
|
||||
"conversion_rate" => 33.3
|
||||
"conversion_rate" => 50
|
||||
},
|
||||
%{
|
||||
"name" => "Visit /register",
|
||||
"count" => 2,
|
||||
"total_count" => 2,
|
||||
"prop_names" => nil,
|
||||
"conversion_rate" => 33.3
|
||||
"conversion_rate" => 50
|
||||
}
|
||||
]
|
||||
end
|
||||
@ -59,7 +59,7 @@ defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
|
||||
build(:pageview, pathname: "/"),
|
||||
build(:pageview, pathname: "/"),
|
||||
build(:pageview, pathname: "/register"),
|
||||
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["A"]),
|
||||
build(:pageview, pathname: "/register"),
|
||||
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["A"]),
|
||||
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["B"])
|
||||
])
|
||||
@ -78,8 +78,8 @@ defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
|
||||
assert json_response(conn, 200) == [
|
||||
%{
|
||||
"name" => "Signup",
|
||||
"count" => 3,
|
||||
"total_count" => 3,
|
||||
"count" => 2,
|
||||
"total_count" => 2,
|
||||
"prop_names" => ["variant"],
|
||||
"conversion_rate" => 50
|
||||
}
|
||||
@ -111,19 +111,19 @@ defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == [
|
||||
%{"count" => 2, "name" => "B", "total_count" => 2, "conversion_rate" => 33.3},
|
||||
%{"count" => 1, "name" => "A", "total_count" => 1, "conversion_rate" => 16.7}
|
||||
%{"count" => 2, "name" => "B", "total_count" => 2, "conversion_rate" => 66.7},
|
||||
%{"count" => 1, "name" => "A", "total_count" => 1, "conversion_rate" => 33.3}
|
||||
]
|
||||
end
|
||||
|
||||
test "returns (none) values in 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"),
|
||||
build(:event, name: "Signup"),
|
||||
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"]),
|
||||
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["B"])
|
||||
build(:event, name: "Signup", "meta.key": ["variant"], "meta.value": ["A"])
|
||||
])
|
||||
|
||||
insert(:goal, %{domain: site.domain, event_name: "Signup"})
|
||||
@ -137,9 +137,8 @@ defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
|
||||
)
|
||||
|
||||
assert json_response(conn, 200) == [
|
||||
%{"count" => 3, "name" => "B", "total_count" => 3, "conversion_rate" => 50.0},
|
||||
%{"count" => 2, "name" => "(none)", "total_count" => 2, "conversion_rate" => 33.3},
|
||||
%{"count" => 1, "name" => "A", "total_count" => 1, "conversion_rate" => 16.7}
|
||||
%{"count" => 2, "name" => "(none)", "total_count" => 2, "conversion_rate" => 66.7},
|
||||
%{"count" => 1, "name" => "A", "total_count" => 1, "conversion_rate" => 33.3}
|
||||
]
|
||||
end
|
||||
|
||||
|
@ -253,7 +253,7 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
|
||||
)
|
||||
|
||||
res = json_response(conn, 200)
|
||||
assert %{"name" => "Unique visitors", "value" => 3, "change" => 100} in res["top_stats"]
|
||||
assert %{"name" => "Unique visitors", "value" => 2, "change" => 100} in res["top_stats"]
|
||||
end
|
||||
|
||||
test "returns converted visitors", %{conn: conn, site: site} do
|
||||
@ -294,7 +294,7 @@ defmodule PlausibleWeb.Api.StatsController.MainGraphTest do
|
||||
|
||||
res = json_response(conn, 200)
|
||||
|
||||
assert %{"name" => "Conversion rate", "value" => 33.3, "change" => 100} in res["top_stats"]
|
||||
assert %{"name" => "Conversion rate", "value" => 50.0, "change" => 100} in res["top_stats"]
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user