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
Record trace metadata when executing funnel and exploration queries (#6267)
Adrian Gruntkowskie48c6a12ad4a
diff --git a/extra/lib/plausible/stats/funnel.ex b/extra/lib/plausible/stats/funnel.exindex 81883944e5..39cdd3d785 100644--- a/extra/lib/plausible/stats/funnel.ex+++ b/extra/lib/plausible/stats/funnel.ex@@ -35,7 +35,10 @@ defmodule Plausible.Stats.Funnel doquery|> Query.set(preloaded_goals: %{all: [], matching_toplevel_filters: goals})|> Base.base_event_query()- |> query_funnel(funnel)+ |> funnel_query(funnel)+ # We pass the query struct to record query metadata for+ # the CH debug console.+ |> ClickhouseRepo.all(query: query)# Funnel definition steps are 1-indexed, if there's index 0 in the resulting query,# it signifies the number of visitors that haven't entered the funnel.@@ -62,7 +65,7 @@ defmodule Plausible.Stats.Funnel do}}end- defp query_funnel(query, funnel_definition) do+ defp funnel_query(query, funnel_definition) doq_events =from(e in query,select: %{user_id: e.user_id, _sample_factor: fragment("any(_sample_factor)")},@@ -72,13 +75,10 @@ defmodule Plausible.Stats.Funnel do)|> select_funnel(funnel_definition)- query =- from(f in subquery(q_events),- select: {f.step, total()},- group_by: f.step- )-- ClickhouseRepo.all(query)+ from(f in subquery(q_events),+ select: {f.step, total()},+ group_by: f.step+ )enddefp select_funnel(db_query, funnel_definition) dodiff --git a/lib/plausible/stats/exploration.ex b/lib/plausible/stats/exploration.exindex 8c51e55955..0892a73d3c 100644--- a/lib/plausible/stats/exploration.ex+++ b/lib/plausible/stats/exploration.ex@@ -60,7 +60,9 @@ defmodule Plausible.Stats.Exploration doquery|> Base.base_event_query()|> next_steps_query(journey, search_term, direction)- |> ClickhouseRepo.all()+ # We pass the query struct to record query metadata for+ # the CH debug console.+ |> ClickhouseRepo.all(query: query)|> then(&{:ok, &1})end@@ -74,7 +76,9 @@ defmodule Plausible.Stats.Exploration doquery|> Base.base_event_query()|> journey_funnel_query(journey, direction)- |> ClickhouseRepo.all()+ # We pass the query struct to record query metadata for+ # the CH debug console.+ |> ClickhouseRepo.all(query: query)|> to_funnel(journey)|> then(&{:ok, &1})end