Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Fixes goal filters for glob goals (#781)
Vignesh Joglekar61c3959626e6
diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.exindex e1f71e5864..27f0cba00c 100644--- a/lib/plausible/stats/clickhouse.ex+++ b/lib/plausible/stats/clickhouse.ex@@ -1162,22 +1162,7 @@ defmodule Plausible.Stats.Clickhouse doenddefp base_query_w_sessions(site, query) do- q = base_query_w_sessions_bare(site, query)-- {goal_event, path} = event_name_for_goal(query)-- q =- if goal_event do- from(e in q, where: e.name == ^goal_event)- else- from(e in q, where: e.name == "pageview")- end-- if path do- from(e in q, where: e.pathname == ^path)- else- q- end+ base_query_w_sessions_bare(site, query) |> include_goal_conversions(query)enddefp base_session_query(site, query) do@@ -1412,22 +1397,7 @@ defmodule Plausible.Stats.Clickhouse doenddefp base_query(site, query) do- q = base_query_bare(site, query)-- {goal_event, path} = event_name_for_goal(query)-- q =- if path do- from(e in q, where: e.pathname == ^path)- else- q- end-- if goal_event do- from(e in q, where: e.name == ^goal_event)- else- from(e in q, where: e.name == "pageview")- end+ base_query_bare(site, query) |> include_goal_conversions(query)enddefp utc_boundaries(%Query{period: "30m"}, _timezone) do@@ -1472,4 +1442,30 @@ defmodule Plausible.Stats.Clickhouse do{nil, nil}endend++ defp include_goal_conversions(db_query, query) do+ {goal_event, path} = event_name_for_goal(query)++ q =+ if goal_event do+ from(e in db_query, where: e.name == ^goal_event)+ else+ from(e in db_query, where: e.name == "pageview")+ end++ if path do+ if String.match?(path, ~r/\*/) do+ path_regex =+ "^#{path}\/?$"+ |> String.replace(~r/\*\*/, ".*")+ |> String.replace(~r/(?<!\.)\*/, "[^/]*")++ from(e in q, where: fragment("match(?, ?)", e.pathname, ^path_regex))+ else+ from(e in q, where: e.pathname == ^path)+ end+ else+ q+ end+ endend