Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

time-on-page: `imported_pages` new columns (#5158)

Karl-Aksel Puulmann831db4ee7f40
diff --git a/priv/ingest_repo/migrations/20250221124625_imported_pages_total_time_on_page.exs b/priv/ingest_repo/migrations/20250221124625_imported_pages_total_time_on_page.exs
new file mode 100644
index 0000000000..b88a9432af
--- /dev/null
+++ b/priv/ingest_repo/migrations/20250221124625_imported_pages_total_time_on_page.exs
@@ -0,0 +1,10 @@
+defmodule Plausible.IngestRepo.Migrations.ImportedPagesTotalTimeOnPage do
+ use Ecto.Migration
+
+ def change do
+ alter table(:imported_pages) do
+ add :total_time_on_page, :UInt64
+ add :total_time_on_page_visits, :UInt64
+ end
+ end
+end
diff --git a/priv/ingest_repo/migrations/20250304074501_populate_imported_pages_total_time_on_page.exs b/priv/ingest_repo/migrations/20250304074501_populate_imported_pages_total_time_on_page.exs
new file mode 100644
index 0000000000..548aa36993
--- /dev/null
+++ b/priv/ingest_repo/migrations/20250304074501_populate_imported_pages_total_time_on_page.exs
@@ -0,0 +1,19 @@
+defmodule Plausible.IngestRepo.Migrations.PopulateImportedPagesTotalTimeOnPage do
+ use Ecto.Migration
+
+ def up do
+ # Note: This only populates the new column for old GA4 imports.
+ # Other imports didn't populate the `time_on_page` column.
+ execute """
+ ALTER TABLE imported_pages
+ UPDATE
+ total_time_on_page = time_on_page,
+ total_time_on_page_visits = visits
+ WHERE time_on_page > 0
+ """
+ end
+
+ def down do
+ raise "Irreversible"
+ end
+end