From 9a769a9fe6a9a01955791985840d653e7d142667 Mon Sep 17 00:00:00 2001 From: Karl-Aksel Puulmann Date: Mon, 1 Jul 2024 11:51:17 +0300 Subject: [PATCH] Allow querying events and pageviews from sessions table This is not strictly accurate, especially with shorter time frames, but is useful for a fallback mechanism. I'll figure out something around shorter time frames in the future. See also: https://github.com/plausible/analytics/pull/4292 --- lib/plausible/stats/table_decider.ex | 3 +++ .../api/external_stats_controller/breakdown_test.exs | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/plausible/stats/table_decider.ex b/lib/plausible/stats/table_decider.ex index 36302613c0f3..68747d0f22e6 100644 --- a/lib/plausible/stats/table_decider.ex +++ b/lib/plausible/stats/table_decider.ex @@ -64,6 +64,9 @@ defmodule Plausible.Stats.TableDecider do defp metric_partitioner(%Query{v2: true}, :group_conversion_rate), do: :either defp metric_partitioner(%Query{v2: true}, :visitors), do: :either defp metric_partitioner(%Query{v2: true}, :visits), do: :either + # Note: These are not very accurate on shorter time ranges + defp metric_partitioner(%Query{v2: true}, :pageviews), do: :either + defp metric_partitioner(%Query{v2: true}, :events), do: :either defp metric_partitioner(_, :conversion_rate), do: :event defp metric_partitioner(_, :group_conversion_rate), do: :event diff --git a/test/plausible_web/controllers/api/external_stats_controller/breakdown_test.exs b/test/plausible_web/controllers/api/external_stats_controller/breakdown_test.exs index d62cdf061030..d6b9a305b684 100644 --- a/test/plausible_web/controllers/api/external_stats_controller/breakdown_test.exs +++ b/test/plausible_web/controllers/api/external_stats_controller/breakdown_test.exs @@ -1023,7 +1023,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do "period" => "day", "date" => "2021-01-01", "property" => "visit:exit_page", - "metrics" => "visitors,visits,bounce_rate,visit_duration", + "metrics" => "visitors,visits,bounce_rate,visit_duration,events,pageviews", "with_imported" => "true" }) @@ -1034,14 +1034,18 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do "exit_page" => "/b", "visit_duration" => 150.0, "visitors" => 3, - "visits" => 4 + "visits" => 4, + "events" => 7, + "pageviews" => 7 }, %{ "bounce_rate" => 100.0, "exit_page" => "/a", "visit_duration" => 0.0, "visitors" => 1, - "visits" => 1 + "visits" => 1, + "events" => 1, + "pageviews" => 1 } ] }