Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unknown bind meta #2654

Merged
merged 3 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- Automatically update all visible dashboard reports in the realtime view
- Connect via TLS when using HTTPS scheme in ClickHouse URL plausible/analytics#2570
- Fix bug with [showing property breakdown with a prop filter](https://github.com/plausible/analytics/issues/1789)
- Fix bug when combining goal and prop filters plausible/analytics#2654

### Changed
- Reject events with long URIs and data URIs plausible/analytics#2536
Expand Down
33 changes: 16 additions & 17 deletions lib/plausible/stats/props.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ defmodule Plausible.Stats.Props do
prop_filter =
Enum.find(query.filters, fn {key, _} -> String.starts_with?(key, "event:props:") end)

if prop_filter do
{key, val} = prop_filter
case prop_filter do
{"event:props:" <> key, {_, "(none)"}} ->
{_, _, goal_name} = query.filters["event:goal"]
%{goal_name => [key]}

if val == "(none)" do
goal = query.filters["goal"]
%{goal => [key]}
else
{"event:props:" <> _key, _} ->
ClickhouseRepo.all(
from [e, meta: meta] in base_event_query(site, query),
select: {e.name, meta.key},
Expand All @@ -21,17 +20,17 @@ defmodule Plausible.Stats.Props do
|> Enum.reduce(%{}, fn {goal_name, meta_key}, acc ->
Map.update(acc, goal_name, [meta_key], fn list -> [meta_key | list] end)
end)
end
else
ClickhouseRepo.all(
from e in base_event_query(site, query),
inner_lateral_join: meta in fragment("meta as m"),
select: {e.name, meta.key},
distinct: true
)
|> Enum.reduce(%{}, fn {goal_name, meta_key}, acc ->
Map.update(acc, goal_name, [meta_key], fn list -> [meta_key | list] end)
end)

nil ->
ClickhouseRepo.all(
from e in base_event_query(site, query),
inner_lateral_join: meta in fragment("meta as m"),
select: {e.name, meta.key},
distinct: true
)
|> Enum.reduce(%{}, fn {goal_name, meta_key}, acc ->
Map.update(acc, goal_name, [meta_key], fn list -> [meta_key | list] end)
end)
end
end
end
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