From f776c6bb30a0ee339a86a7997942f70e655133df Mon Sep 17 00:00:00 2001 From: Vignesh Joglekar Date: Tue, 22 Dec 2020 07:54:41 -0600 Subject: [PATCH] Improves realtime top stats and conversion rate calculation (#500) * Fixes goal conversion rate when period is realtime * Adds unique visitors (30m) to realtime top stats * Changelog Co-authored-by: Uku Taht --- CHANGELOG.md | 2 ++ lib/plausible/stats/clickhouse.ex | 1 + lib/plausible_web/controllers/api/stats_controller.ex | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5f846c92..c7fa32ca3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. - Simple notifications around traffic spikes plausible/analytics#453 - Dark theme option/system setting follow plausible/analytics#467 - "Load More" capability to pages modal plausible/analytics#480 +- Unique Visitors (last 30 min) as a top stat in realtime view plausible/analytics#500 - Pinned filter and date selector rows while scrolling plausible/analytics#472 ### Changed @@ -33,6 +34,7 @@ All notable changes to this project will be documented in this file. - Prevent picking dates before site insertion plausible/analtics#446 - Fix overly-sticky from and to in query parameters plausible/analytics#495 - Adds support for single-day date selection plausible/analytics#495 +- Goal conversion rate in realtime view is now accurate plausible/analytics#500 ### Security - Do not run the plausible Docker container as root plausible/analytics#362 diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.ex index e5271f409..cc678e556 100644 --- a/lib/plausible/stats/clickhouse.ex +++ b/lib/plausible/stats/clickhouse.ex @@ -166,6 +166,7 @@ defmodule Plausible.Stats.Clickhouse do end def unique_visitors(site, query) do + query = if query.period == "realtime", do: %Query{query | period: "30m"}, else: query ClickhouseRepo.one( from e in base_query_w_sessions(site, query), select: fragment("uniq(user_id)") diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex index c48b2f3bd..e9c165bc2 100644 --- a/lib/plausible_web/controllers/api/stats_controller.ex +++ b/lib/plausible_web/controllers/api/stats_controller.ex @@ -28,6 +28,10 @@ defmodule PlausibleWeb.Api.StatsController do name: "Current visitors", count: Stats.current_visitors(site, query) }, + %{ + name: "Unique visitors (last 30 min)", + count: Stats.unique_visitors(site, query) + }, %{ name: "Pageviews (last 30 min)", count: Stats.total_pageviews(site, query)