Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Apply sampling factor multiplication consistently across CSV export queries (#4074)
Adrian Gruntkowski62138e0dad6d
diff --git a/lib/plausible/exports.ex b/lib/plausible/exports.exindex d08dd0a331..4910567e06 100644--- a/lib/plausible/exports.ex+++ b/lib/plausible/exports.ex@@ -277,7 +277,11 @@ defmodule Plausible.Exports dodefmacrop visit_duration(t) doquote doselected_as(- fragment("greatest(sum(?*?),0)", unquote(t).sign, unquote(t).duration),+ fragment(+ "toUInt64(round(greatest(sum(?*?),0)*any(_sample_factor)))",+ unquote(t).sign,+ unquote(t).duration+ ),:visit_duration)end@@ -294,14 +298,21 @@ defmodule Plausible.Exports dodefmacrop visits(t) doquote do- selected_as(sum(unquote(t).sign), :visits)+ selected_as(+ fragment("toUInt64(round(greatest(sum(?),0)*any(_sample_factor)))", unquote(t).sign),+ :visits+ )endenddefmacrop bounces(t) doquote doselected_as(- fragment("greatest(sum(?*?),0)", unquote(t).sign, unquote(t).is_bounce),+ fragment(+ "toUInt32(round(greatest(sum(?*?),0)*any(_sample_factor)))",+ unquote(t).sign,+ unquote(t).is_bounce+ ),:bounces)end@@ -310,7 +321,11 @@ defmodule Plausible.Exports dodefmacrop pageviews(t) doquote doselected_as(- fragment("greatest(sum(?*?),0)", unquote(t).sign, unquote(t).pageviews),+ fragment(+ "toUInt64(round(greatest(sum(?*?),0)*any(_sample_factor)))",+ unquote(t).sign,+ unquote(t).pageviews+ ),:pageviews)end@@ -420,7 +435,7 @@ defmodule Plausible.Exports dos.entry_page,visitors(s),selected_as(- fragment("toUInt64(round(sum(?)*any(_sample_factor)))", s.sign),+ fragment("toUInt64(round(greatest(sum(?),0)*any(_sample_factor)))", s.sign),:entrances),visit_duration(s),@@ -440,7 +455,7 @@ defmodule Plausible.Exports dovisitors(s),visit_duration(s),selected_as(- fragment("toUInt64(round(sum(?)*any(_sample_factor)))", s.sign),+ fragment("toUInt64(round(greatest(sum(?),0)*any(_sample_factor)))", s.sign),:exits),bounces(s),