From d9ac8ccdb9c5c90ba5775a4166e7762a3533ac7d Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Wed, 18 Aug 2021 12:29:00 +0300 Subject: [PATCH] Fix samplign in main graph and top pages --- lib/plausible/stats/base.ex | 5 +---- .../controllers/api/stats_controller.ex | 12 ++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/plausible/stats/base.ex b/lib/plausible/stats/base.ex index bdffa2fb0..c7d372b88 100644 --- a/lib/plausible/stats/base.ex +++ b/lib/plausible/stats/base.ex @@ -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 = diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex index 5134770e2..a711157b4 100644 --- a/lib/plausible_web/controllers/api/stats_controller.ex +++ b/lib/plausible_web/controllers/api/stats_controller.ex @@ -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"],