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 time on page from exports (#4051)
ruslandoga8712e91bcb5b
diff --git a/lib/plausible/exports.ex b/lib/plausible/exports.exindex 078e62c418..32bb71edd4 100644--- a/lib/plausible/exports.ex+++ b/lib/plausible/exports.ex@@ -242,7 +242,6 @@ defmodule Plausible.Exports do%{filename.("imported_visitors") => export_visitors_q(site_id, timezone, date_range),filename.("imported_sources") => export_sources_q(site_id, timezone, date_range),- # NOTE: this query can result in `MEMORY_LIMIT_EXCEEDED` errorfilename.("imported_pages") => export_pages_q(site_id, timezone, date_range),filename.("imported_entry_pages") => export_entry_pages_q(site_id, timezone, date_range),filename.("imported_exit_pages") => export_exit_pages_q(site_id, timezone, date_range),@@ -372,39 +371,12 @@ defmodule Plausible.Exports doenddefp export_pages_q(site_id, timezone, date_range) do- window_q =- from e in sampled("events_v2", nil),- where: e.site_id == ^site_id,- where: [name: "pageview"],- select: %{- timestamp: selected_as(fragment("toTimeZone(?,?)", e.timestamp, ^timezone), :timestamp),- next_timestamp:- over(fragment("leadInFrame(toTimeZone(?,?))", e.timestamp, ^timezone),- partition_by: e.session_id,- order_by: e.timestamp,- frame: fragment("ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING")- ),- pathname: e.pathname,- hostname: e.hostname,- user_id: e.user_id,- session_id: e.session_id,- _sample_factor: fragment("_sample_factor")- }-- window_q =- if date_range do- from e in window_q,- where: selected_as(:timestamp) >= ^date_range.first,- where: fragment("toDate(?)", selected_as(:timestamp)) <= ^date_range.last- else- window_q- end-- from e in subquery(window_q),+ from e in sampled("events_v2", date_range),+ where: [site_id: ^site_id, name: "pageview"],group_by: [selected_as(:date), e.pathname],order_by: selected_as(:date),select: [- selected_as(fragment("toDate(?)", e.timestamp), :date),+ date(e.timestamp, ^timezone),selected_as(fragment("any(?)", e.hostname), :hostname),selected_as(e.pathname, :page),selected_as(@@ -412,15 +384,7 @@ defmodule Plausible.Exports do:visits),visitors(e),- selected_as(fragment("toUInt64(round(count()*any(_sample_factor)))"), :pageviews),- selected_as(- fragment("toUInt64(round(countIf(?=0)*any(_sample_factor)))", e.next_timestamp),- :exits- ),- selected_as(- fragment("sum(greatest(?,0))", e.next_timestamp - e.timestamp),- :time_on_page- )+ selected_as(fragment("toUInt64(round(count()*any(_sample_factor)))"), :pageviews)]enddiff --git a/lib/plausible/imported/csv_importer.ex b/lib/plausible/imported/csv_importer.exindex 28d2ee517a..b9348d53ef 100644--- a/lib/plausible/imported/csv_importer.ex+++ b/lib/plausible/imported/csv_importer.ex@@ -159,7 +159,7 @@ defmodule Plausible.Imported.CSVImporter do"imported_operating_systems" =>"date Date, operating_system String, operating_system_version String, visitors UInt64, visits UInt64, visit_duration UInt64, bounces UInt32, pageviews UInt64","imported_pages" =>- "date Date, hostname String, page String, visits UInt64, visitors UInt64, pageviews UInt64, exits UInt64, time_on_page UInt64",+ "date Date, hostname String, page String, visits UInt64, visitors UInt64, pageviews UInt64","imported_sources" =>"date Date, source String, referrer String, utm_source String, utm_medium String, utm_campaign String, utm_content String, utm_term String, pageviews UInt64, visitors UInt64, visits UInt64, visit_duration UInt64, bounces UInt32","imported_visitors" =>diff --git a/test/plausible/imported/csv_importer_test.exs b/test/plausible/imported/csv_importer_test.exsindex cc801e0cb3..0f356c3b73 100644--- a/test/plausible/imported/csv_importer_test.exs+++ b/test/plausible/imported/csv_importer_test.exs@@ -247,23 +247,23 @@ defmodule Plausible.Imported.CSVImporterTest do%{name: "imported_pages_20211230_20220101.csv",body: """- "date","visitors","pageviews","exits","time_on_page","hostname","page"- "2021-12-30",1,1,0,43,"lucky.numbers.com","/14776416252794997127"- "2021-12-30",1,1,1,0,"lucky.numbers.com","/14776416252794997127"- "2021-12-30",6,6,6,0,"lucky.numbers.com","/14776416252794997127"- "2021-12-30",1,1,1,0,"lucky.numbers.com","/9102354072466236765"- "2021-12-30",1,1,1,0,"lucky.numbers.com","/7478911940502018071"- "2021-12-30",1,1,1,0,"lucky.numbers.com","/6402607186523575652"- "2021-12-30",2,2,2,0,"lucky.numbers.com","/9962503789684934900"- "2021-12-30",8,10,10,0,"lucky.numbers.com","/13595620304963848161"- "2021-12-30",2,2,2,0,"lucky.numbers.com","/17019199732013993436"- "2021-12-30",32,33,32,211,"lucky.numbers.com","/9874837495456455794"- "2021-12-31",4,4,4,0,"lucky.numbers.com","/14776416252794997127"- "2021-12-31",1,1,1,0,"lucky.numbers.com","/8738789417178304429"- "2021-12-31",1,1,1,0,"lucky.numbers.com","/7445073500314667742"- "2021-12-31",1,1,1,0,"lucky.numbers.com","/4897404798407749335"- "2021-12-31",1,2,1,29,"lucky.numbers.com","/11263893625781431659"- "2022-01-01",2,2,2,0,"lucky.numbers.com","/5878724061840196349"+ "date","visitors","pageviews","hostname","page"+ "2021-12-30",1,1,"lucky.numbers.com","/14776416252794997127"+ "2021-12-30",1,1,"lucky.numbers.com","/14776416252794997127"+ "2021-12-30",6,6,"lucky.numbers.com","/14776416252794997127"+ "2021-12-30",1,1,"lucky.numbers.com","/9102354072466236765"+ "2021-12-30",1,1,"lucky.numbers.com","/7478911940502018071"+ "2021-12-30",1,1,"lucky.numbers.com","/6402607186523575652"+ "2021-12-30",2,2,"lucky.numbers.com","/9962503789684934900"+ "2021-12-30",8,10,"lucky.numbers.com","/13595620304963848161"+ "2021-12-30",2,2,"lucky.numbers.com","/17019199732013993436"+ "2021-12-30",32,33,"lucky.numbers.com","/9874837495456455794"+ "2021-12-31",4,4,"lucky.numbers.com","/14776416252794997127"+ "2021-12-31",1,1,"lucky.numbers.com","/8738789417178304429"+ "2021-12-31",1,1,"lucky.numbers.com","/7445073500314667742"+ "2021-12-31",1,1,"lucky.numbers.com","/4897404798407749335"+ "2021-12-31",1,2,"lucky.numbers.com","/11263893625781431659"+ "2022-01-01",2,2,"lucky.numbers.com","/5878724061840196349""""},%{