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
Make small refinements to funnel exploration logic (#6244)
Adrian Gruntkowski7ed1bbad76ce
diff --git a/lib/plausible/stats/exploration.ex b/lib/plausible/stats/exploration.exindex 84ceaf1ae3..3c5f702c86 100644--- a/lib/plausible/stats/exploration.ex+++ b/lib/plausible/stats/exploration.ex@@ -36,17 +36,7 @@ defmodule Plausible.Stats.Exploration do@spec next_steps(Query.t(), journey(), String.t()) ::{:ok, [next_step()]}- def next_steps(query, journey, search_term \\ "")-- def next_steps(query, [], search_term) do- query- |> Base.base_event_query()- |> next_steps_first_query(search_term)- |> ClickhouseRepo.all()- |> then(&{:ok, &1})- end-- def next_steps(query, journey, search_term) do+ def next_steps(query, journey, search_term \\ "") doquery|> Base.base_event_query()|> next_steps_query(journey, search_term)@@ -67,29 +57,6 @@ defmodule Plausible.Stats.Exploration do|> then(&{:ok, &1})end- defp next_steps_first_query(query, search_term) do- q_steps = steps_query(query, 1)-- from(s in subquery(q_steps),- where: selected_as(:next_name) != "",- select: %{- step: %Journey.Step{- name: selected_as(s.name1, :next_name),- pathname: selected_as(s.pathname1, :next_pathname)- },- visitors: selected_as(scale_sample(fragment("uniq(?)", s.user_id)), :count)- },- group_by: [selected_as(:next_name), selected_as(:next_pathname)],- order_by: [- desc: selected_as(:count),- asc: selected_as(:next_pathname),- asc: selected_as(:next_name)- ],- limit: 10- )- |> maybe_search(search_term)- end-defp next_steps_query(query, steps, search_term) donext_step_idx = length(steps) + 1q_steps = steps_query(query, next_step_idx)@@ -99,10 +66,7 @@ defmodule Plausible.Stats.Exploration doq_next =from(s in subquery(q_steps),- # avoid cycling back to the beginning of the exploration- where:- selected_as(:next_name) != "" and- (selected_as(:next_name) != s.name1 or selected_as(:next_pathname) != s.pathname1),+ where: selected_as(:next_name) != "",select: %{step: %Journey.Step{name: selected_as(field(s, ^next_name), :next_name),diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.exindex 4711d1182e..2ab0333ef3 100644--- a/lib/plausible_web/controllers/api/stats_controller.ex+++ b/lib/plausible_web/controllers/api/stats_controller.ex@@ -372,7 +372,6 @@ defmodule PlausibleWeb.Api.StatsController doinput|> Jason.decode!()|> Enum.map(&parse_journey_step/1)- |> Enum.reject(&is_nil/1)|> then(&{:ok, &1})enddiff --git a/test/plausible/stats/exploration_test.exs b/test/plausible/stats/exploration_test.exsindex 8976517236..9f385bbc61 100644--- a/test/plausible/stats/exploration_test.exs+++ b/test/plausible/stats/exploration_test.exs@@ -140,12 +140,14 @@ defmodule Plausible.Stats.ExplorationTest do%Exploration.Journey.Step{name: "pageview", pathname: "/login"}]- assert {:ok, [next_step1, next_step2]} = Exploration.next_steps(query, journey)+ assert {:ok, [next_step1, next_step2, next_step3]} = Exploration.next_steps(query, journey)assert next_step1.step.pathname == "/docs"assert next_step1.visitors == 1- assert next_step2.step.pathname == "/logout"+ assert next_step2.step.pathname == "/home"assert next_step2.visitors == 1+ assert next_step3.step.pathname == "/logout"+ assert next_step3.visitors == 1endtest "suggests the first step in the journey", %{site: site} dodiff --git a/test/plausible_web/controllers/api/stats_controller/exploration_test.exs b/test/plausible_web/controllers/api/stats_controller/exploration_test.exsindex 0b7b71edff..e2deb58d05 100644--- a/test/plausible_web/controllers/api/stats_controller/exploration_test.exs+++ b/test/plausible_web/controllers/api/stats_controller/exploration_test.exs@@ -74,11 +74,13 @@ defmodule PlausibleWeb.Api.StatsController.ExplorationTest do|> get("/api/stats/#{site.domain}/exploration/next/?journey=#{journey}&period=24h")|> json_response(200)- assert [next_step1, next_step2] = resp+ assert [next_step1, next_step2, next_step3] = respassert next_step1["step"]["pathname"] == "/docs"assert next_step1["visitors"] == 1- assert next_step2["step"]["pathname"] == "/logout"+ assert next_step2["step"]["pathname"] == "/home"assert next_step2["visitors"] == 1+ assert next_step3["step"]["pathname"] == "/logout"+ assert next_step3["visitors"] == 1endtest "it filters", %{conn: conn, site: site} do