Fix entry pages

This commit is contained in:
Uku Taht 2021-08-16 11:58:36 +03:00
parent 79f6756ba2
commit ecbc68f05b
5 changed files with 21 additions and 31 deletions

View File

@ -270,10 +270,10 @@ class LineGraph extends React.Component {
} }
topStatTooltip(stat) { topStatTooltip(stat) {
if (typeof(stat.count) == 'number') { if (typeof(stat.value) == 'number') {
let name = stat.name.toLowerCase() let name = stat.name.toLowerCase()
name = stat.count === 1 ? name.slice(0, -1) : name name = stat.value === 1 ? name.slice(0, -1) : name
return stat.count.toLocaleString() + ' ' + name return stat.value.toLocaleString() + ' ' + name
} }
} }

View File

@ -73,9 +73,6 @@ defmodule Plausible.Stats.Base do
nil -> nil ->
q q
_ ->
raise "Unknown goal type"
end end
Enum.reduce(query.filters, q, fn {filter_key, filter_value}, query -> Enum.reduce(query.filters, q, fn {filter_key, filter_value}, query ->
@ -121,28 +118,6 @@ defmodule Plausible.Stats.Base do
where: s.timestamp >= ^first_datetime and s.start < ^last_datetime where: s.timestamp >= ^first_datetime and s.start < ^last_datetime
) )
sessions_q =
case query.filters["event:page"] do
{:is, page} ->
from(e in sessions_q, where: e.entry_page == ^page)
{:is_not, page} ->
from(e in sessions_q, where: e.entry_page != ^page)
{:matches, glob_expr} ->
regex = page_regex(glob_expr)
from(s in sessions_q, where: fragment("match(?, ?)", s.entry_page, ^regex))
{:member, list} ->
from(e in sessions_q, where: e.entry_page in ^list)
nil ->
sessions_q
_ ->
raise "Unknown filter type"
end
Enum.reduce(Filters.visit_props(), sessions_q, fn prop_name, sessions_q -> Enum.reduce(Filters.visit_props(), sessions_q, fn prop_name, sessions_q ->
filter = query.filters["visit:" <> prop_name] filter = query.filters["visit:" <> prop_name]
prop_name = Map.get(@api_prop_name_to_db, prop_name, prop_name) prop_name = Map.get(@api_prop_name_to_db, prop_name, prop_name)

View File

@ -158,6 +158,7 @@ defmodule Plausible.Stats.Breakdown do
defp breakdown_sessions(site, query, property, metrics, {limit, page}) do defp breakdown_sessions(site, query, property, metrics, {limit, page}) do
offset = (page - 1) * limit offset = (page - 1) * limit
query = treat_page_filter_as_entry_page(query)
from(s in query_sessions(site, query), from(s in query_sessions(site, query),
order_by: [desc: fragment("uniq(?)", s.user_id), asc: fragment("min(?)", s.start)], order_by: [desc: fragment("uniq(?)", s.user_id), asc: fragment("min(?)", s.start)],
@ -168,9 +169,21 @@ defmodule Plausible.Stats.Breakdown do
|> filter_converted_sessions(site, query) |> filter_converted_sessions(site, query)
|> do_group_by(property) |> do_group_by(property)
|> select_metrics(metrics) |> select_metrics(metrics)
|> IO.inspect()
|> ClickhouseRepo.all() |> ClickhouseRepo.all()
end end
defp treat_page_filter_as_entry_page(query) do
case query.filters["event:page"] do
nil ->
query
filter ->
new_filters = Map.put(query.filters, "visit:entry_page", filter)
%Query{query | filters: new_filters}
end
end
defp filter_converted_sessions(db_query, site, query) do defp filter_converted_sessions(db_query, site, query) do
if query.filters["event:name"] || query.filters["event:page"] || query.filters["visit:goal"] do if query.filters["event:name"] || query.filters["event:page"] || query.filters["visit:goal"] do
converted_sessions = converted_sessions =

View File

@ -11,7 +11,9 @@ defmodule Plausible.Stats.Filters do
"browser_version", "browser_version",
"os", "os",
"os_version", "os_version",
"country" "country",
"entry_page",
"exit_page"
] ]
@event_props [ @event_props [

View File

@ -334,8 +334,8 @@ defmodule PlausibleWeb.Api.StatsController do
metrics = ["visitors", "visits", "visit_duration"] metrics = ["visitors", "visits", "visit_duration"]
entry_pages = entry_pages =
Stats.breakdown(site, query, "event:page", metrics, pagination) Stats.breakdown(site, query, "visit:entry_page", metrics, pagination)
|> transform_keys(%{"page" => "name", "visits" => "entries", "visitors" => "count"}) |> transform_keys(%{"entry_page" => "name", "visits" => "entries", "visitors" => "count"})
json(conn, entry_pages) json(conn, entry_pages)
end end