Skip to content

Commit

Permalink
Fix 'unknown bind meta' error
Browse files Browse the repository at this point in the history
  • Loading branch information
ukutaht committed Feb 7, 2023
1 parent af43a84 commit 300fac0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/plausible/stats/props.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ defmodule Plausible.Stats.Props do
Enum.find(query.filters, fn {key, _} -> String.starts_with?(key, "event:props:") end)

if prop_filter do
{key, val} = prop_filter
{"event:props:" <> key, {_, val}} = prop_filter

if val == "(none)" do
goal = query.filters["goal"]
%{goal => [key]}
{_, _, goal_name} = query.filters["event:goal"]
%{goal_name => [key]}
else
ClickhouseRepo.all(
from [e, meta: meta] in base_event_query(site, query),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,39 @@ defmodule PlausibleWeb.Api.StatsController.ConversionsTest do
end
end

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

describe "GET /api/stats/:domain/property/:key" do
setup [:create_user, :log_in, :create_new_site]

Expand Down

0 comments on commit 300fac0

Please sign in to comment.