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
Exclude pathname from custom events (#6290)
Adam Rutkowski5b3afafef877
diff --git a/extra/lib/plausible/stats/exploration.ex b/extra/lib/plausible/stats/exploration.exindex 9c0814399f..7ebab60274 100644--- a/extra/lib/plausible/stats/exploration.ex+++ b/extra/lib/plausible/stats/exploration.ex@@ -9,7 +9,7 @@ defmodule Plausible.Stats.Exploration do@type t() :: %__MODULE__{}@derive {Jason.Encoder, only: [:name, :pathname, :label, :includes_subpaths, :subpaths_count]}- defstruct name: nil, pathname: nil, label: nil, includes_subpaths: false, subpaths_count: 0+ defstruct name: nil, pathname: "", label: nil, includes_subpaths: false, subpaths_count: 0@spec from(map()) :: t()def from(step) do@@ -21,7 +21,7 @@ defmodule Plausible.Stats.Exploration dowhen is_boolean(includes_subpaths) and is_integer(subpaths_count) dolabel =if name != "pageview" do- name <> " " <> pathname+ nameelsepathnameend@@ -289,10 +289,9 @@ defmodule Plausible.Stats.Exploration dolabel:selected_as(fragment(- "if(? != 'pageview', concat(?, ' ', ?), ?)",+ "if(? != 'pageview', ?, ?)",m.name,m.name,- m.pathname,m.pathname),:label@@ -338,7 +337,7 @@ defmodule Plausible.Stats.Exploration dojoin: pname in fragment(@wildcard_array_join, em.name, em.pathname, em.pathname),on: true,hints: "ARRAY",- where: selected_as(:pathname) != "",+ where: em.name != "pageview" or selected_as(:pathname) != "",select: %{name: em.name,pathname: selected_as(fragment("?", pname), :pathname),@@ -354,7 +353,7 @@ defmodule Plausible.Stats.Exploration dodefp combined_query(q_matches, false = _include_wildcard?) dofrom(em in subquery(q_matches),- where: selected_as(:pathname) != "",+ where: em.name != "pageview" or selected_as(:pathname) != "",select: %{name: em.name,pathname: selected_as(em.pathname, :pathname),@@ -427,7 +426,7 @@ defmodule Plausible.Stats.Exploration do_sample_factor: e._sample_factor,row_number: row_number() |> over(:session_window),name: e.name,- pathname: e.pathname,+ pathname: fragment("if(? = 'pageview', ?, '')", e.name, e.pathname),timestamp: e.timestamp},where: e.name != "engagement"@@ -460,7 +459,8 @@ defmodule Plausible.Stats.Exploration dodefp select_previous(query, :forward) dofrom(e in query,select_merge: %{- prev_pathname: lag(e.pathname) |> over(:session_window),+ prev_pathname:+ lag(fragment("if(? = 'pageview', ?, '')", e.name, e.pathname)) |> over(:session_window),prev_name: lag(e.name) |> over(:session_window)})@@ -470,8 +470,7 @@ defmodule Plausible.Stats.Exploration dofrom(e in query,select_merge: %{prev_pathname:- lead(e.pathname)- |> over(:session_window),+ lead(fragment("if(? = 'pageview', ?, '')", e.name, e.pathname)) |> over(:session_window),prev_name: lead(e.name) |> over(:session_window)})diff --git a/test/plausible/stats/exploration_test.exs b/test/plausible/stats/exploration_test.exsindex 4b86d90ddf..c99572f9a8 100644--- a/test/plausible/stats/exploration_test.exs+++ b/test/plausible/stats/exploration_test.exs@@ -142,17 +142,17 @@ defmodule Plausible.Stats.ExplorationTest dojourney = [%Exploration.Journey.Step{name: "pageview", pathname: "/register"},- %Exploration.Journey.Step{name: "Signup", pathname: "/register"},+ %Exploration.Journey.Step{name: "Signup"},%Exploration.Journey.Step{name: "pageview", pathname: "/activate"},- %Exploration.Journey.Step{name: "Create site", pathname: "/sites/new"}+ %Exploration.Journey.Step{name: "Create site"}]assert {:ok, [step1, step2, step3, step4]} = Exploration.journey_funnel(query, journey)assert step1.step.label == "/register"- assert step2.step.label == "Signup /register"+ assert step2.step.label == "Signup"assert step3.step.label == "/activate"- assert step4.step.label == "Create site /sites/new"+ assert step4.step.label == "Create site"endtest "respects filters in the query", %{site: site} do@@ -493,7 +493,7 @@ defmodule Plausible.Stats.ExplorationTest doassert next_step1.step.label == "/"assert next_step1.visitors == 2- assert next_step2.step.label == "Signup /register"+ assert next_step2.step.label == "Signup"assert next_step2.visitors == 1end@@ -528,11 +528,11 @@ defmodule Plausible.Stats.ExplorationTest do]assert {:ok, [next_step]} =- Exploration.next_steps(query, journey, search_term: "up /regi")+ Exploration.next_steps(query, journey, search_term: "up")- assert next_step.step.label == "Signup /register"+ assert next_step.step.label == "Signup"assert next_step.step.name == "Signup"- assert next_step.step.pathname == "/register"+ assert next_step.step.pathname == ""assert next_step.visitors == 1end