@@ -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 )
0 commit comments