mirror of
https://github.com/plausible/analytics.git
synced 2024-11-25 07:06:11 +03:00
Channels in dashboard CSV export (#4787)
* Add channels.csv to dashboard CSV export * Feature flag channels in CSV * Disable credo
This commit is contained in:
parent
3af8f24d34
commit
98bc3e7554
@ -495,11 +495,21 @@ defmodule PlausibleWeb.Api.StatsController do
|
|||||||
Stats.breakdown(site, query, metrics, pagination)
|
Stats.breakdown(site, query, metrics, pagination)
|
||||||
|> transform_keys(%{channel: :name})
|
|> transform_keys(%{channel: :name})
|
||||||
|
|
||||||
json(conn, %{
|
if params["csv"] do
|
||||||
results: res,
|
if Filters.filtering_on_dimension?(query, "event:goal") do
|
||||||
meta: Stats.Breakdown.formatted_date_ranges(query),
|
res
|
||||||
skip_imported_reason: query.skip_imported_reason
|
|> transform_keys(%{visitors: :conversions})
|
||||||
})
|
|> to_csv([:name, :conversions, :conversion_rate])
|
||||||
|
else
|
||||||
|
res |> to_csv([:name, :visitors, :bounce_rate, :visit_duration])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
json(conn, %{
|
||||||
|
results: res,
|
||||||
|
meta: Stats.Breakdown.formatted_date_ranges(query),
|
||||||
|
skip_imported_reason: query.skip_imported_reason
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
on_ee do
|
on_ee do
|
||||||
|
@ -144,6 +144,15 @@ defmodule PlausibleWeb.StatsController do
|
|||||||
~c"custom_props.csv" => fn -> Api.StatsController.all_custom_prop_values(conn, params) end
|
~c"custom_props.csv" => fn -> Api.StatsController.all_custom_prop_values(conn, params) end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# credo:disable-for-lines:7
|
||||||
|
csvs =
|
||||||
|
if FunWithFlags.enabled?(:channels, for: site) ||
|
||||||
|
FunWithFlags.enabled?(:channels, for: conn.assigns[:current_user]) do
|
||||||
|
Map.put(csvs, ~c"channels.csv", fn -> Api.StatsController.channels(conn, params) end)
|
||||||
|
else
|
||||||
|
csvs
|
||||||
|
end
|
||||||
|
|
||||||
csv_values =
|
csv_values =
|
||||||
Map.values(csvs)
|
Map.values(csvs)
|
||||||
|> Plausible.ClickhouseRepo.parallel_tasks()
|
|> Plausible.ClickhouseRepo.parallel_tasks()
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
name,conversions,conversion_rate
|
||||||
|
Direct,1,50.0
|
|
@ -0,0 +1,2 @@
|
|||||||
|
name,visitors,bounce_rate,visit_duration
|
||||||
|
Organic Search,1,0,60
|
|
4
test/plausible_web/controllers/CSVs/30d/channels.csv
Normal file
4
test/plausible_web/controllers/CSVs/30d/channels.csv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
name,visitors,bounce_rate,visit_duration
|
||||||
|
Direct,2,50,30
|
||||||
|
Organic Search,1,0,60
|
||||||
|
Paid Search,1,100,0
|
|
4
test/plausible_web/controllers/CSVs/6m/channels.csv
Normal file
4
test/plausible_web/controllers/CSVs/6m/channels.csv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
name,visitors,bounce_rate,visit_duration
|
||||||
|
Direct,2,50,30
|
||||||
|
Paid Search,2,100,0
|
||||||
|
Organic Search,1,0,60
|
|
@ -208,6 +208,7 @@ defmodule PlausibleWeb.StatsControllerTest do
|
|||||||
assert ~c"pages.csv" in zip
|
assert ~c"pages.csv" in zip
|
||||||
assert ~c"regions.csv" in zip
|
assert ~c"regions.csv" in zip
|
||||||
assert ~c"sources.csv" in zip
|
assert ~c"sources.csv" in zip
|
||||||
|
assert ~c"channels.csv" in zip
|
||||||
assert ~c"utm_campaigns.csv" in zip
|
assert ~c"utm_campaigns.csv" in zip
|
||||||
assert ~c"utm_contents.csv" in zip
|
assert ~c"utm_contents.csv" in zip
|
||||||
assert ~c"utm_mediums.csv" in zip
|
assert ~c"utm_mediums.csv" in zip
|
||||||
@ -423,6 +424,7 @@ defmodule PlausibleWeb.StatsControllerTest do
|
|||||||
expected_filenames = [
|
expected_filenames = [
|
||||||
"visitors.csv",
|
"visitors.csv",
|
||||||
"sources.csv",
|
"sources.csv",
|
||||||
|
"channels.csv",
|
||||||
"utm_mediums.csv",
|
"utm_mediums.csv",
|
||||||
"utm_sources.csv",
|
"utm_sources.csv",
|
||||||
"utm_campaigns.csv",
|
"utm_campaigns.csv",
|
||||||
@ -471,6 +473,13 @@ defmodule PlausibleWeb.StatsControllerTest do
|
|||||||
[""]
|
[""]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Dummy - imported data is not actually included in exported CSVs yet
|
||||||
|
{~c"channels.csv", data} ->
|
||||||
|
assert parse_csv(data) == [
|
||||||
|
["name", "visitors", "bounce_rate", "visit_duration"],
|
||||||
|
[""]
|
||||||
|
]
|
||||||
|
|
||||||
{~c"utm_mediums.csv", data} ->
|
{~c"utm_mediums.csv", data} ->
|
||||||
assert parse_csv(data) == [
|
assert parse_csv(data) == [
|
||||||
["name", "visitors", "bounce_rate", "visit_duration"],
|
["name", "visitors", "bounce_rate", "visit_duration"],
|
||||||
@ -685,7 +694,8 @@ defmodule PlausibleWeb.StatsControllerTest do
|
|||||||
country_code: "EE",
|
country_code: "EE",
|
||||||
subdivision1_code: "EE-37",
|
subdivision1_code: "EE-37",
|
||||||
city_geoname_id: 588_409,
|
city_geoname_id: 588_409,
|
||||||
referrer_source: "Google"
|
referrer_source: "Google",
|
||||||
|
channel: "Organic Search"
|
||||||
),
|
),
|
||||||
build(:pageview,
|
build(:pageview,
|
||||||
user_id: 123,
|
user_id: 123,
|
||||||
@ -695,7 +705,8 @@ defmodule PlausibleWeb.StatsControllerTest do
|
|||||||
country_code: "EE",
|
country_code: "EE",
|
||||||
subdivision1_code: "EE-37",
|
subdivision1_code: "EE-37",
|
||||||
city_geoname_id: 588_409,
|
city_geoname_id: 588_409,
|
||||||
referrer_source: "Google"
|
referrer_source: "Google",
|
||||||
|
channel: "Organic Search"
|
||||||
),
|
),
|
||||||
build(:pageview,
|
build(:pageview,
|
||||||
pathname: "/",
|
pathname: "/",
|
||||||
@ -706,6 +717,7 @@ defmodule PlausibleWeb.StatsControllerTest do
|
|||||||
utm_source: "google",
|
utm_source: "google",
|
||||||
utm_content: "content",
|
utm_content: "content",
|
||||||
utm_term: "term",
|
utm_term: "term",
|
||||||
|
channel: "Paid Search",
|
||||||
browser: "Firefox",
|
browser: "Firefox",
|
||||||
browser_version: "120",
|
browser_version: "120",
|
||||||
operating_system: "Mac",
|
operating_system: "Mac",
|
||||||
@ -726,6 +738,7 @@ defmodule PlausibleWeb.StatsControllerTest do
|
|||||||
utm_campaign: "ads",
|
utm_campaign: "ads",
|
||||||
country_code: "EE",
|
country_code: "EE",
|
||||||
referrer_source: "Google",
|
referrer_source: "Google",
|
||||||
|
channel: "Paid Search",
|
||||||
browser: "FirefoxNoVersion",
|
browser: "FirefoxNoVersion",
|
||||||
operating_system: "MacNoVersion"
|
operating_system: "MacNoVersion"
|
||||||
),
|
),
|
||||||
|
@ -6,6 +6,7 @@ end
|
|||||||
Mox.defmock(Plausible.HTTPClient.Mock, for: Plausible.HTTPClient.Interface)
|
Mox.defmock(Plausible.HTTPClient.Mock, for: Plausible.HTTPClient.Interface)
|
||||||
Application.ensure_all_started(:double)
|
Application.ensure_all_started(:double)
|
||||||
|
|
||||||
|
FunWithFlags.enable(:channels)
|
||||||
# Temporary flag to test `read_team_schemas` flag on all tests.
|
# Temporary flag to test `read_team_schemas` flag on all tests.
|
||||||
if System.get_env("TEST_READ_TEAM_SCHEMAS") == "1" do
|
if System.get_env("TEST_READ_TEAM_SCHEMAS") == "1" do
|
||||||
FunWithFlags.enable(:read_team_schemas)
|
FunWithFlags.enable(:read_team_schemas)
|
||||||
|
Loading…
Reference in New Issue
Block a user