From 4175a7abae5a2734ebc06bf4896510e00af34df2 Mon Sep 17 00:00:00 2001 From: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com> Date: Mon, 20 Mar 2023 10:40:37 +0200 Subject: [PATCH] make CSV export return only conversions with goal filter (#2760) * make CSV export return only conversions with goal filter * update changelog --- CHANGELOG.md | 1 + .../controllers/stats_controller.ex | 15 +++-- .../CSVs/30d-filter-goal/visitors.csv | 64 +++++++++---------- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad4fd3b6..cfb0177c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - Add support for more Bamboo adapters, i.e. `Bamboo.MailgunAdapter`, `Bamboo.MandrillAdapter`, `Bamboo.SendGridAdapter` plausible/analytics#2649 ### Fixed +- Make goal-filtered CSV export return only unique_conversions timeseries in the 'visitors.csv' file - Stop treating page filter as an entry page filter - City report showing N/A instead of city names with imported data plausible/analytics#2675 - Empty values for Screen Size, OS and Browser are uniformly replaced with "(not set)" diff --git a/lib/plausible_web/controllers/stats_controller.ex b/lib/plausible_web/controllers/stats_controller.ex index 355ae5be8..dd6600cb7 100644 --- a/lib/plausible_web/controllers/stats_controller.ex +++ b/lib/plausible_web/controllers/stats_controller.ex @@ -98,7 +98,7 @@ defmodule PlausibleWeb.StatsController do metrics = cond do query.filters["event:goal"] -> - [:visitors, :pageviews, :bounce_rate, :visit_duration] + [:visitors] FunWithFlags.enabled?(:visits_metric, for: conn.assigns[:current_user]) -> [:visitors, :pageviews, :visits, :views_per_visit, :bounce_rate, :visit_duration] @@ -108,11 +108,18 @@ defmodule PlausibleWeb.StatsController do end graph = Plausible.Stats.timeseries(site, query, metrics) - headers = [:date | metrics] + columns = [:date | metrics] + + column_headers = + if query.filters["event:goal"] do + [:date, :unique_conversions] + else + columns + end visitors = - Enum.map(graph, fn row -> Enum.map(headers, &row[&1]) end) - |> (fn data -> [headers | data] end).() + Enum.map(graph, fn row -> Enum.map(columns, &row[&1]) end) + |> (fn data -> [column_headers | data] end).() |> CSV.encode() |> Enum.join() diff --git a/test/plausible_web/controllers/CSVs/30d-filter-goal/visitors.csv b/test/plausible_web/controllers/CSVs/30d-filter-goal/visitors.csv index 0887396c4..f42b575ee 100644 --- a/test/plausible_web/controllers/CSVs/30d-filter-goal/visitors.csv +++ b/test/plausible_web/controllers/CSVs/30d-filter-goal/visitors.csv @@ -1,32 +1,32 @@ -date,visitors,pageviews,bounce_rate,visit_duration -2021-09-20,0,0,, -2021-09-21,0,0,, -2021-09-22,0,0,, -2021-09-23,0,0,, -2021-09-24,0,0,, -2021-09-25,0,0,, -2021-09-26,0,0,, -2021-09-27,0,0,, -2021-09-28,0,0,, -2021-09-29,0,0,, -2021-09-30,0,0,, -2021-10-01,0,0,, -2021-10-02,0,0,, -2021-10-03,0,0,, -2021-10-04,0,0,, -2021-10-05,0,0,, -2021-10-06,0,0,, -2021-10-07,0,0,, -2021-10-08,0,0,, -2021-10-09,0,0,, -2021-10-10,0,0,, -2021-10-11,0,0,, -2021-10-12,0,0,, -2021-10-13,0,0,, -2021-10-14,0,0,, -2021-10-15,0,0,, -2021-10-16,0,0,, -2021-10-17,0,0,, -2021-10-18,0,0,, -2021-10-19,1,0,100,0 -2021-10-20,0,0,, +date,unique_conversions +2021-09-20,0 +2021-09-21,0 +2021-09-22,0 +2021-09-23,0 +2021-09-24,0 +2021-09-25,0 +2021-09-26,0 +2021-09-27,0 +2021-09-28,0 +2021-09-29,0 +2021-09-30,0 +2021-10-01,0 +2021-10-02,0 +2021-10-03,0 +2021-10-04,0 +2021-10-05,0 +2021-10-06,0 +2021-10-07,0 +2021-10-08,0 +2021-10-09,0 +2021-10-10,0 +2021-10-11,0 +2021-10-12,0 +2021-10-13,0 +2021-10-14,0 +2021-10-15,0 +2021-10-16,0 +2021-10-17,0 +2021-10-18,0 +2021-10-19,1 +2021-10-20,0