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
drop neighbor_aggregate_time_on_page/2 (#4206)
ruslandogab3fd41cc4e1b
diff --git a/lib/plausible/stats/aggregate.ex b/lib/plausible/stats/aggregate.exindex 73d33f0b24..01eef54e63 100644--- a/lib/plausible/stats/aggregate.ex+++ b/lib/plausible/stats/aggregate.ex@@ -60,90 +60,6 @@ defmodule Plausible.Stats.Aggregate doenddefp aggregate_time_on_page(site, query) do- if FunWithFlags.enabled?(:window_time_on_page) do- window_aggregate_time_on_page(site, query)- else- neighbor_aggregate_time_on_page(site, query)- end- end-- defp neighbor_aggregate_time_on_page(site, query) do- q =- from(- e in base_event_query(site, Query.remove_filters(query, ["event:page"])),- select: {- fragment("? as p", e.pathname),- fragment("? as t", e.timestamp),- fragment("? as s", e.session_id)- },- order_by: [e.session_id, e.timestamp]- )-- {base_query_raw, base_query_raw_params} = ClickhouseRepo.to_sql(:all, q)- where_param_idx = length(base_query_raw_params)-- {where_clause, where_arg} =- case Query.get_filter(query, "event:page") do- [:is, _, page] ->- {"p = {$#{where_param_idx}:String}", page}-- [:is_not, _, page] ->- {"p != {$#{where_param_idx}:String}", page}-- [:member, _, page] ->- {"p IN {$#{where_param_idx}:Array(String)}", page}-- [:not_member, _, page] ->- {"p NOT IN {$#{where_param_idx}:Array(String)}", page}-- [:matches, _, expr] ->- regex = page_regex(expr)- {"match(p, {$#{where_param_idx}:String})", regex}-- [:matches_member, _, exprs] ->- page_regexes = Enum.map(exprs, &page_regex/1)- {"multiMatchAny(p, {$#{where_param_idx}:Array(String)})", page_regexes}-- [:not_matches_member, _, exprs] ->- page_regexes = Enum.map(exprs, &page_regex/1)- {"not(multiMatchAny(p, {$#{where_param_idx}:Array(String)}))", page_regexes}-- [:does_not_match, _, expr] ->- regex = page_regex(expr)- {"not(match(p, {$#{where_param_idx}:String}))", regex}- end-- params = base_query_raw_params ++ [where_arg]-- time_query = "- SELECT- avg(ifNotFinite(avgTime, null))- FROM- (SELECT- p,- sum(td)/count(case when p2 != p then 1 end) as avgTime- FROM- (SELECT- p,- p2,- sum(t2-t) as td- FROM- (SELECT- *,- neighbor(t, 1) as t2,- neighbor(p, 1) as p2,- neighbor(s, 1) as s2- FROM (#{base_query_raw}))- WHERE s=s2 AND #{where_clause}- GROUP BY p,p2,s)- GROUP BY p)"-- {:ok, res} = ClickhouseRepo.query(time_query, params)- [[time_on_page]] = res.rows- %{time_on_page: time_on_page}- end-- defp window_aggregate_time_on_page(site, query) dowindowed_pages_q =from e in base_event_query(site, Query.remove_filters(query, ["event:page"])),select: %{