Skip to content

Commit 5b3afaf

Browse files
authored
Exclude pathname from custom events (#6290)
1 parent 94db3ce commit 5b3afaf

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

extra/lib/plausible/stats/exploration.ex

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule Plausible.Stats.Exploration do
99
@type t() :: %__MODULE__{}
1010

1111
@derive {Jason.Encoder, only: [:name, :pathname, :label, :includes_subpaths, :subpaths_count]}
12-
defstruct name: nil, pathname: nil, label: nil, includes_subpaths: false, subpaths_count: 0
12+
defstruct name: nil, pathname: "", label: nil, includes_subpaths: false, subpaths_count: 0
1313

1414
@spec from(map()) :: t()
1515
def from(step) do
@@ -21,7 +21,7 @@ defmodule Plausible.Stats.Exploration do
2121
when is_boolean(includes_subpaths) and is_integer(subpaths_count) do
2222
label =
2323
if name != "pageview" do
24-
name <> " " <> pathname
24+
name
2525
else
2626
pathname
2727
end
@@ -289,10 +289,9 @@ defmodule Plausible.Stats.Exploration do
289289
label:
290290
selected_as(
291291
fragment(
292-
"if(? != 'pageview', concat(?, ' ', ?), ?)",
292+
"if(? != 'pageview', ?, ?)",
293293
m.name,
294294
m.name,
295-
m.pathname,
296295
m.pathname
297296
),
298297
:label
@@ -338,7 +337,7 @@ defmodule Plausible.Stats.Exploration do
338337
join: pname in fragment(@wildcard_array_join, em.name, em.pathname, em.pathname),
339338
on: true,
340339
hints: "ARRAY",
341-
where: selected_as(:pathname) != "",
340+
where: em.name != "pageview" or selected_as(:pathname) != "",
342341
select: %{
343342
name: em.name,
344343
pathname: selected_as(fragment("?", pname), :pathname),
@@ -354,7 +353,7 @@ defmodule Plausible.Stats.Exploration do
354353

355354
defp combined_query(q_matches, false = _include_wildcard?) do
356355
from(em in subquery(q_matches),
357-
where: selected_as(:pathname) != "",
356+
where: em.name != "pageview" or selected_as(:pathname) != "",
358357
select: %{
359358
name: em.name,
360359
pathname: selected_as(em.pathname, :pathname),
@@ -427,7 +426,7 @@ defmodule Plausible.Stats.Exploration do
427426
_sample_factor: e._sample_factor,
428427
row_number: row_number() |> over(:session_window),
429428
name: e.name,
430-
pathname: e.pathname,
429+
pathname: fragment("if(? = 'pageview', ?, '')", e.name, e.pathname),
431430
timestamp: e.timestamp
432431
},
433432
where: e.name != "engagement"
@@ -460,7 +459,8 @@ defmodule Plausible.Stats.Exploration do
460459
defp select_previous(query, :forward) do
461460
from(e in query,
462461
select_merge: %{
463-
prev_pathname: lag(e.pathname) |> over(:session_window),
462+
prev_pathname:
463+
lag(fragment("if(? = 'pageview', ?, '')", e.name, e.pathname)) |> over(:session_window),
464464
prev_name: lag(e.name) |> over(:session_window)
465465
}
466466
)
@@ -470,8 +470,7 @@ defmodule Plausible.Stats.Exploration do
470470
from(e in query,
471471
select_merge: %{
472472
prev_pathname:
473-
lead(e.pathname)
474-
|> over(:session_window),
473+
lead(fragment("if(? = 'pageview', ?, '')", e.name, e.pathname)) |> over(:session_window),
475474
prev_name: lead(e.name) |> over(:session_window)
476475
}
477476
)

test/plausible/stats/exploration_test.exs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,17 @@ defmodule Plausible.Stats.ExplorationTest do
142142

143143
journey = [
144144
%Exploration.Journey.Step{name: "pageview", pathname: "/register"},
145-
%Exploration.Journey.Step{name: "Signup", pathname: "/register"},
145+
%Exploration.Journey.Step{name: "Signup"},
146146
%Exploration.Journey.Step{name: "pageview", pathname: "/activate"},
147-
%Exploration.Journey.Step{name: "Create site", pathname: "/sites/new"}
147+
%Exploration.Journey.Step{name: "Create site"}
148148
]
149149

150150
assert {:ok, [step1, step2, step3, step4]} = Exploration.journey_funnel(query, journey)
151151

152152
assert step1.step.label == "/register"
153-
assert step2.step.label == "Signup /register"
153+
assert step2.step.label == "Signup"
154154
assert step3.step.label == "/activate"
155-
assert step4.step.label == "Create site /sites/new"
155+
assert step4.step.label == "Create site"
156156
end
157157

158158
test "respects filters in the query", %{site: site} do
@@ -493,7 +493,7 @@ defmodule Plausible.Stats.ExplorationTest do
493493
assert next_step1.step.label == "/"
494494
assert next_step1.visitors == 2
495495

496-
assert next_step2.step.label == "Signup /register"
496+
assert next_step2.step.label == "Signup"
497497
assert next_step2.visitors == 1
498498
end
499499

@@ -528,11 +528,11 @@ defmodule Plausible.Stats.ExplorationTest do
528528
]
529529

530530
assert {:ok, [next_step]} =
531-
Exploration.next_steps(query, journey, search_term: "up /regi")
531+
Exploration.next_steps(query, journey, search_term: "up")
532532

533-
assert next_step.step.label == "Signup /register"
533+
assert next_step.step.label == "Signup"
534534
assert next_step.step.name == "Signup"
535-
assert next_step.step.pathname == "/register"
535+
assert next_step.step.pathname == ""
536536
assert next_step.visitors == 1
537537
end
538538

0 commit comments

Comments
 (0)