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 revenue goals from exploration steps & funnel (#6381)
Adam Rutkowski83485f3b582f
diff --git a/extra/lib/plausible/stats/exploration.ex b/extra/lib/plausible/stats/exploration.exindex 4de2828f15..73d3a1c14e 100644--- a/extra/lib/plausible/stats/exploration.ex+++ b/extra/lib/plausible/stats/exploration.ex@@ -451,7 +451,7 @@ defmodule Plausible.Stats.Exploration dopathname: fragment("if(? = 'pageview', ?, '')", e.name, e.pathname),timestamp: e.timestamp},- where: e.name != "engagement"+ where: e.name != "engagement" and e.revenue_reporting_currency == "")|> select_previous(direction)diff --git a/test/plausible/stats/exploration_test.exs b/test/plausible/stats/exploration_test.exsindex bdc5df4aa6..c331f8a9fe 100644--- a/test/plausible/stats/exploration_test.exs+++ b/test/plausible/stats/exploration_test.exs@@ -210,6 +210,47 @@ defmodule Plausible.Stats.ExplorationTest doassert {:error, :journey_too_long} = Exploration.journey_funnel(query, journey)end+ test "excludes revenue events from journey funnel steps" do+ site = new_site()+ now = DateTime.utc_now()++ populate_stats(site, [+ build(:pageview,+ user_id: 123,+ pathname: "/home",+ timestamp: DateTime.shift(now, minute: -50)+ ),+ build(:event,+ user_id: 123,+ name: "Purchase",+ pathname: "/checkout",+ revenue_reporting_amount: Decimal.new("100"),+ revenue_reporting_currency: "USD",+ timestamp: DateTime.shift(now, minute: -40)+ ),+ build(:pageview,+ user_id: 123,+ pathname: "/thank-you",+ timestamp: DateTime.shift(now, minute: -30)+ )+ ])++ query = QueryBuilder.build!(site, input_date_range: :all)++ journey = [+ %Exploration.Journey.Step{name: "pageview", pathname: "/home"},+ %Exploration.Journey.Step{name: "pageview", pathname: "/thank-you"}+ ]++ assert {:ok, [step1, step2]} = Exploration.journey_funnel(query, journey)++ # Revenue event is skipped+ assert step1.step.pathname == "/home"+ assert step1.visitors == 1+ assert step2.step.pathname == "/thank-you"+ assert step2.visitors == 1+ end+test "supports backward journey funnel", %{site: site} doquery = QueryBuilder.build!(site, input_date_range: :all)@@ -372,6 +413,47 @@ defmodule Plausible.Stats.ExplorationTest doassert next_step3.visitors == 1end+ test "excludes revenue events from next step suggestions" do+ site = new_site()+ now = DateTime.utc_now()++ populate_stats(site, [+ build(:pageview,+ user_id: 123,+ pathname: "/home",+ timestamp: DateTime.shift(now, minute: -50)+ ),+ build(:event,+ user_id: 123,+ name: "Purchase",+ pathname: "/checkout",+ revenue_reporting_amount: Decimal.new("100"),+ revenue_reporting_currency: "USD",+ timestamp: DateTime.shift(now, minute: -40)+ ),+ build(:pageview,+ user_id: 123,+ pathname: "/thank-you",+ timestamp: DateTime.shift(now, minute: -30)+ )+ ])++ {:ok, _} =+ Plausible.Goals.create(site, %{"event_name" => "Purchase", "currency" => "USD"})++ query = QueryBuilder.build!(site, input_date_range: :all)++ assert {:ok, steps} = Exploration.next_steps(site, query, [])++ refute "Purchase" in Enum.map(steps, & &1.step.name)+ refute "/checkout" in Enum.map(steps, & &1.step.pathname)++ journey = [%Exploration.Journey.Step{name: "pageview", pathname: "/home"}]+ assert {:ok, [next_step]} = Exploration.next_steps(site, query, journey)+ assert next_step.step.pathname == "/thank-you"+ assert next_step.step.name == "pageview"+ end+test "respects max_candidates", %{site: site} doquery = QueryBuilder.build!(site, input_date_range: :all)