mirror of
https://github.com/plausible/analytics.git
synced 2024-11-26 23:27:54 +03:00
Move hostname filter appending to Breakdown module (#3998)
We currently update the query filtered by hostname to its respective visit props in some cases. This patch moves it down, from controllers, to the Breakdown module, so any changes in logic will be also reflected in the Stats API.
This commit is contained in:
parent
aee69e44c8
commit
39fdbb3a67
@ -195,6 +195,7 @@ defmodule Plausible.Stats.Breakdown do
|
||||
end
|
||||
|
||||
def breakdown(site, query, property, metrics, pagination, opts) do
|
||||
query = maybe_update_breakdown_filters(property, query)
|
||||
if !Keyword.get(opts, :skip_tracing), do: trace(query, property, metrics)
|
||||
|
||||
metrics_to_select = Util.maybe_add_visitors_metric(metrics) -- @computed_metrics
|
||||
@ -212,6 +213,32 @@ defmodule Plausible.Stats.Breakdown do
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_update_breakdown_filters("visit:source", query) do
|
||||
update_hostname(query, "visit:entry_page_hostname")
|
||||
end
|
||||
|
||||
defp maybe_update_breakdown_filters("visit:entry_page", query) do
|
||||
update_hostname(query, "visit:entry_page_hostname")
|
||||
end
|
||||
|
||||
defp maybe_update_breakdown_filters("visit:exit_page", query) do
|
||||
update_hostname(query, "visit:exit_page_hostname")
|
||||
end
|
||||
|
||||
defp maybe_update_breakdown_filters(_, query) do
|
||||
query
|
||||
end
|
||||
|
||||
defp update_hostname(query, visit_prop) do
|
||||
case query.filters["event:hostname"] do
|
||||
nil ->
|
||||
query
|
||||
|
||||
some ->
|
||||
Plausible.Stats.Query.put_filter(query, visit_prop, some)
|
||||
end
|
||||
end
|
||||
|
||||
# Backwards compatibility
|
||||
defp breakdown_table(%Query{experimental_reduced_joins?: false}, _, _), do: :session
|
||||
|
||||
|
@ -458,13 +458,6 @@ defmodule PlausibleWeb.Api.StatsController do
|
||||
query = Query.from(site, params)
|
||||
pagination = parse_pagination(params)
|
||||
|
||||
query =
|
||||
if query.filters["event:hostname"] do
|
||||
Query.put_filter(query, "visit:entry_page_hostname", query.filters["event:hostname"])
|
||||
else
|
||||
query
|
||||
end
|
||||
|
||||
extra_metrics =
|
||||
if params["detailed"], do: [:bounce_rate, :visit_duration], else: []
|
||||
|
||||
@ -770,13 +763,6 @@ defmodule PlausibleWeb.Api.StatsController do
|
||||
pagination = parse_pagination(params)
|
||||
metrics = breakdown_metrics(query, [:visits, :visit_duration])
|
||||
|
||||
query =
|
||||
if query.filters["event:hostname"] do
|
||||
Query.put_filter(query, "visit:entry_page_hostname", query.filters["event:hostname"])
|
||||
else
|
||||
query
|
||||
end
|
||||
|
||||
entry_pages =
|
||||
Stats.breakdown(site, query, "visit:entry_page", metrics, pagination)
|
||||
|> transform_keys(%{entry_page: :name})
|
||||
@ -807,13 +793,6 @@ defmodule PlausibleWeb.Api.StatsController do
|
||||
{limit, page} = parse_pagination(params)
|
||||
metrics = breakdown_metrics(query, [:visits])
|
||||
|
||||
query =
|
||||
if query.filters["event:hostname"] do
|
||||
Query.put_filter(query, "visit:exit_page_hostname", query.filters["event:hostname"])
|
||||
else
|
||||
query
|
||||
end
|
||||
|
||||
exit_pages =
|
||||
Stats.breakdown(site, query, "visit:exit_page", metrics, {limit, page})
|
||||
|> add_exit_rate(site, query, limit)
|
||||
|
Loading…
Reference in New Issue
Block a user