From f576fa2a2c6a9296f01b4a5169c9301d2686f4c3 Mon Sep 17 00:00:00 2001
From: Matt Colligan <44536113+m-col@users.noreply.github.com>
Date: Thu, 4 Nov 2021 12:20:39 +0000
Subject: [PATCH] Improvements to CSV export (#1427)
* Add details=True to export API parameters
This makes the ZIP export add `%{"details" => "True"}` to the query's
`params` when fetching data internally for packaging in the ZIP.
This adds bounce_rate and time_on_page to the data in pages.csv, and
bounce_rate and visit_duration to sources.csv.
* Make API return data with consistent names
Some of the data types returned via the JSON or CSV API use inconsistent
naming, and some have redundant name changes (i.e. count -> visitors ->
count). This makes these all consistent and removes the redundancy.
This addresses #1426, fixes some of the CSV headers, and unifies the
JSON and CSV return data labels.
* Update changelog
* Test should use Timex.shift, not relative time
* Return full country names in CSV export
This also replaces the " character with ' in two country names, as those
are the characters used in the names, yielding a more predictable and
'correct' output.
* Fetch CSV exported data concurrently
* Use spinner to indicate when export has started
* Use 300 as default number of brekadown entries for export
Higher numbers (e.g. 1000) seem to cause clickhouse errors when there
many pages to request. It is unclear what is causing the error, as
clickhouse returns an "unknown" error code and an empty error message.
---
CHANGELOG.md | 1 +
assets/js/dashboard/stats/bar.js | 12 +-
.../js/dashboard/stats/conversions/index.js | 4 +-
.../stats/conversions/prop-breakdown.js | 4 +-
assets/js/dashboard/stats/devices/browsers.js | 4 +-
assets/js/dashboard/stats/devices/index.js | 4 +-
.../stats/devices/operating-systems.js | 4 +-
.../js/dashboard/stats/locations/countries.js | 4 +-
assets/js/dashboard/stats/locations/map.js | 4 +-
assets/js/dashboard/stats/modals/countries.js | 2 +-
.../js/dashboard/stats/modals/entry-pages.js | 4 +-
.../js/dashboard/stats/modals/exit-pages.js | 4 +-
.../dashboard/stats/modals/google-keywords.js | 2 +-
assets/js/dashboard/stats/modals/pages.js | 2 +-
.../stats/modals/referrer-drilldown.js | 4 +-
assets/js/dashboard/stats/modals/sources.js | 2 +-
.../js/dashboard/stats/pages/entry-pages.js | 5 +-
assets/js/dashboard/stats/pages/exit-pages.js | 5 +-
assets/js/dashboard/stats/pages/pages.js | 4 +-
.../dashboard/stats/sources/referrer-list.js | 4 +-
.../dashboard/stats/sources/search-terms.js | 4 +-
.../js/dashboard/stats/sources/source-list.js | 8 +-
assets/js/dashboard/stats/visitor-graph.js | 33 +++-
lib/plausible/stats/breakdown.ex | 4 +
lib/plausible/stats/countries.ex | 4 +-
.../controllers/api/stats_controller.ex | 94 +++++-----
.../controllers/stats_controller.ex | 35 ++--
.../api/stats_controller/browsers_test.exs | 10 +-
.../api/stats_controller/conversions_test.exs | 79 ++++++---
.../api/stats_controller/countries_test.exs | 8 +-
.../operating_systems_test.exs | 10 +-
.../api/stats_controller/pages_test.exs | 48 +++---
.../stats_controller/screen_sizes_test.exs | 6 +-
.../api/stats_controller/sources_test.exs | 42 ++---
.../controllers/stats_controller_test.exs | 160 +++++++++---------
35 files changed, 353 insertions(+), 271 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 55e754046..46a5ece9a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
### Added
- Data exported via the download button will contain CSV data for all visible graps in a zip file.
+- JSON API has renamed some metric items to be more clear and match the CSV API output.
### Fixed
- Fixes database error when pathname contains a question mark
diff --git a/assets/js/dashboard/stats/bar.js b/assets/js/dashboard/stats/bar.js
index f1585b3f2..1acb6f977 100644
--- a/assets/js/dashboard/stats/bar.js
+++ b/assets/js/dashboard/stats/bar.js
@@ -1,17 +1,17 @@
import React from 'react';
-function barWidth(count, all) {
- let maxVal = all[0].count;
+function barWidth(count, all, plot) {
+ let maxVal = all[0][plot];
- for (const entry of all) {
- if (entry.count > maxVal) maxVal = entry.count
+ for (const val of all) {
+ if (val > maxVal) maxVal = val[plot]
}
return count / maxVal * 100
}
-export default function Bar({count, all, bg, maxWidthDeduction, children}) {
- const width = barWidth(count, all)
+export default function Bar({count, all, bg, maxWidthDeduction, children, plot = "visitors"}) {
+ const width = barWidth(count, all, plot)
return (