Skip to content

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

Fix Dashboard CSV export with entry or exit page filter (#6604)

Marko Saricd76d23fcffba
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 06ba4676f7..531a54b0a5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -58,6 +58,7 @@ All notable changes to this project will be documented in this file.
- Fixed main graph being clipped when the browser's root font size is smaller than the default 16px
- Fixed issue with users with billing role not being able to create personal segments
- Fixed period arrow keys hijacking custom-range calendar
+- Fixed dashboard CSV export failing when the dashboard is filtered by entry page or exit page
## v3.2.0 - 2026-01-16
diff --git a/lib/plausible/stats/sql/query_builder.ex b/lib/plausible/stats/sql/query_builder.ex
index 8e5b4132c4..9e905e63d1 100644
--- a/lib/plausible/stats/sql/query_builder.ex
+++ b/lib/plausible/stats/sql/query_builder.ex
@@ -177,7 +177,7 @@ defmodule Plausible.Stats.SQL.QueryBuilder do
on: true,
group_by: meta.key
)
- |> select_merge_as([_e, meta], %{shortname(query, dimension) => meta.key})
+ |> select_merge_as([..., meta], %{shortname(query, dimension) => meta.key})
end
defp dimension_group_by(q, :events, query, "event:goal" = dimension) do
diff --git a/test/plausible_web/controllers/api/stats_controller/dashboard_csv_export_test.exs b/test/plausible_web/controllers/api/stats_controller/dashboard_csv_export_test.exs
index fee06be0c2..8b8fff10f2 100644
--- a/test/plausible_web/controllers/api/stats_controller/dashboard_csv_export_test.exs
+++ b/test/plausible_web/controllers/api/stats_controller/dashboard_csv_export_test.exs
@@ -188,6 +188,82 @@ defmodule PlausibleWeb.Api.StatsController.DashboardCsvExportTest do
assert ~c"utm_terms.csv" in zip
end
+ test "exports custom props with an entry_page filter", %{conn: conn, site: site} do
+ {:ok, site} = Plausible.Props.allow(site, ["author"])
+
+ populate_stats(site, [
+ build(:pageview,
+ user_id: 123,
+ pathname: "/blog",
+ "meta.key": ["author"],
+ "meta.value": ["john"]
+ ),
+ build(:pageview,
+ user_id: 123,
+ pathname: "/another",
+ "meta.key": ["author"],
+ "meta.value": ["john"]
+ ),
+ build(:pageview, pathname: "/ignored", "meta.key": ["author"], "meta.value": ["someone"]),
+ build(:pageview, pathname: "/blog")
+ ])
+
+ custom_props =
+ conn
+ |> do_export(site, %{
+ @base_params
+ | date_range: "day",
+ filters: [["is", "visit:entry_page", ["/blog"]]]
+ })
+ |> response(200)
+ |> unzip_and_parse_csv(~c"custom_props.csv")
+
+ assert custom_props == [
+ ["property", "value", "visitors", "events", "percentage"],
+ ["author", "(none)", "1", "1", "50.0"],
+ ["author", "john", "1", "2", "50.0"],
+ [""]
+ ]
+ end
+
+ test "exports custom props with an exit_page filter", %{conn: conn, site: site} do
+ {:ok, site} = Plausible.Props.allow(site, ["author"])
+
+ populate_stats(site, [
+ build(:pageview,
+ user_id: 123,
+ pathname: "/blog",
+ "meta.key": ["author"],
+ "meta.value": ["john"]
+ ),
+ build(:pageview,
+ user_id: 123,
+ pathname: "/another",
+ "meta.key": ["author"],
+ "meta.value": ["john"]
+ ),
+ build(:pageview, pathname: "/ignored", "meta.key": ["author"], "meta.value": ["someone"]),
+ build(:pageview, pathname: "/another")
+ ])
+
+ custom_props =
+ conn
+ |> do_export(site, %{
+ @base_params
+ | date_range: "day",
+ filters: [["is", "visit:exit_page", ["/another"]]]
+ })
+ |> response(200)
+ |> unzip_and_parse_csv(~c"custom_props.csv")
+
+ assert custom_props == [
+ ["property", "value", "visitors", "events", "percentage"],
+ ["author", "(none)", "1", "1", "50.0"],
+ ["author", "john", "1", "2", "50.0"],
+ [""]
+ ]
+ end
+
test "limits pages.csv and exit_pages.csv to 100 rows", %{conn: conn, site: site} do
events = for i <- 1..101, do: build(:pageview, pathname: "/page-#{i}")
populate_stats(site, events)