Add referrers.csv to CSV export (#2624) (#3002)

* Add referrers to csv (#2624)

* Change CHANGELOG

* add missing files

* fix tests

* revert package files changes

* fix typo

* format

* rename
This commit is contained in:
Ёkaterina Krivich 2023-08-07 10:32:01 +03:00 committed by GitHub
parent 8c3b541971
commit 9e26ea2cdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 1 deletions

View File

@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
## Unreleased
- Add `referrers.csv` to CSV export
### Fixed
- Only return `(none)` values in custom property breakdown for the first page (pagination) of results
- Fixed weekly/monthly e-mail report [rendering issues](https://github.com/plausible/analytics/issues/284)

View File

@ -701,6 +701,35 @@ defmodule PlausibleWeb.Api.StatsController do
end
end
def referrers(conn, params) do
site = conn.assigns[:site]
query =
Query.from(site, params)
|> Filters.add_prefix()
pagination = parse_pagination(params)
metrics = [:visitors, :bounce_rate, :visit_duration]
res =
Stats.breakdown(site, query, "visit:referrer", metrics, pagination)
|> add_cr(site, query, pagination, :referrer, "visit:referrer")
|> transform_keys(%{referrer: :name})
if params["csv"] do
if Map.has_key?(query.filters, "event:goal") do
res
|> transform_keys(%{visitors: :conversions})
|> to_csv([:name, :conversions, :conversion_rate])
else
res |> to_csv([:name, :visitors, :bounce_rate, :visit_duration])
end
else
json(conn, res)
end
end
def referrer_drilldown(conn, %{"referrer" => "Google"} = params) do
site = conn.assigns[:site] |> Repo.preload(:google_auth)

View File

@ -145,7 +145,8 @@ defmodule PlausibleWeb.StatsController do
'operating_systems.csv' => fn -> Api.StatsController.operating_systems(conn, params) end,
'devices.csv' => fn -> Api.StatsController.screen_sizes(conn, params) end,
'conversions.csv' => fn -> Api.StatsController.conversions(conn, params) end,
'prop_breakdown.csv' => fn -> Api.StatsController.all_props_breakdown(conn, params) end
'prop_breakdown.csv' => fn -> Api.StatsController.all_props_breakdown(conn, params) end,
'referrers.csv' => fn -> Api.StatsController.referrers(conn, params) end
}
csvs =

View File

@ -0,0 +1,2 @@
name,conversions,conversion_rate
Direct / None,1,25.0
1 name conversions conversion_rate
2 Direct / None 1 25.0

View File

@ -0,0 +1,2 @@
name,visitors,bounce_rate,visit_duration
Direct / None,1,0,60
1 name visitors bounce_rate visit_duration
2 Direct / None 1 0 60

View File

@ -0,0 +1,2 @@
name,visitors,bounce_rate,visit_duration
Direct / None,4,75,15
1 name visitors bounce_rate visit_duration
2 Direct / None 4 75 15

View File

@ -0,0 +1,2 @@
name,visitors,bounce_rate,visit_duration
Direct / None,5,80,12
1 name visitors bounce_rate visit_duration
2 Direct / None 5 80 12