Fix samplign in main graph and top pages

This commit is contained in:
Uku Taht 2021-08-18 12:29:00 +03:00
parent 96df035285
commit d9ac8ccdb9
2 changed files with 13 additions and 4 deletions

View File

@ -62,11 +62,8 @@ defmodule Plausible.Stats.Base do
{:member, list} ->
from(e in q, where: e.name in ^list)
# Logically, this isn't necessary and might even cause some confusion (request with no filters will still filter for event:name==pageviews).
nil ->
from(e in q, where: e.name == "pageview")
# When removing this, however, sampling in clickhouse goes a bit weird (dashboard with 3m pageviews will start getting sampled which is weird)
q
end
q =

View File

@ -9,6 +9,12 @@ defmodule PlausibleWeb.Api.StatsController do
site = conn.assigns[:site]
query = Query.from(site.timezone, params) |> Filters.add_prefix()
query =
case query.filters["visit:goal"] do
nil -> Query.put_filter(query, "event:name", {:is, "pageview"})
_ -> query
end
timeseries = Task.async(fn -> Stats.timeseries(site, query, ["visitors"]) end)
{top_stats, sample_percent} = fetch_top_stats(site, query)
@ -313,6 +319,12 @@ defmodule PlausibleWeb.Api.StatsController do
site = conn.assigns[:site]
query = Query.from(site.timezone, params) |> Filters.add_prefix()
query =
case query.filters["visit:goal"] do
nil -> Query.put_filter(query, "event:name", {:is, "pageview"})
_ -> query
end
metrics =
if params["detailed"],
do: ["visitors", "pageviews", "bounce_rate", "time_on_page"],