Fix 'field key does not exist' error (#2674)

This commit is contained in:
Uku Taht 2023-02-14 13:57:38 +02:00 committed by GitHub
parent 0db52ff977
commit 8fcf4d3304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 2 deletions

View File

@ -336,12 +336,13 @@ defmodule Plausible.Stats.Breakdown do
else else
from( from(
e in q, e in q,
inner_lateral_join: meta in fragment("meta") inner_lateral_join: meta in fragment("meta"),
as: :meta
) )
end end
from( from(
[e, meta] in q, [e, meta: meta] in q,
where: meta.key == ^prop, where: meta.key == ^prop,
group_by: meta.value, group_by: meta.value,
select_merge: %{^prop => meta.value}, select_merge: %{^prop => meta.value},

View File

@ -430,6 +430,51 @@ defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
} }
] ]
end end
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
end end
describe "GET /api/stats/:domain/conversions - with glob goals" do describe "GET /api/stats/:domain/conversions - with glob goals" do