Add "events" metrics to public breakdown endpoint (#1529)

pull/1542/head
Ralf Zimmermann 5 years ago committed by GitHub
parent 66575f497b
commit faf4459b15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Added
- API route `PUT /api/v1/sites/goals` with form params `site_id`, `event_name` and/or `page_path`, and `goal_type` with supported types `event` and `page`
- API route `DELETE /api/v1/sites/goals/:goal_id` with form params `site_id`
- The public breakdown endpoint can be queried with the "events" metric
### Added
- Data exported via the download button will contain CSV data for all visible graps in a zip file.

@ -88,7 +88,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController do
defp event_only_property?("event:props:" <> _), do: true
defp event_only_property?(_), do: false
@event_metrics ["visitors", "pageviews"]
@event_metrics ["visitors", "pageviews", "events"]
@session_metrics ["visits", "bounce_rate", "visit_duration"]
defp parse_metrics(params, property, query) do
metrics =

@ -527,6 +527,65 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do
}
end
test "can breakdown by event:name with visitors and events metrics", %{conn: conn, site: site} do
populate_stats([
build(:pageview,
domain: site.domain,
pathname: "/non-existing",
user_id: @user_id,
timestamp: ~N[2021-01-01 00:00:00]
),
build(:event,
name: "404",
domain: site.domain,
pathname: "/non-existing",
user_id: @user_id,
timestamp: ~N[2021-01-01 00:00:00]
),
build(:pageview,
domain: site.domain,
pathname: "/non-existing",
user_id: @user_id,
timestamp: ~N[2021-01-01 00:00:01]
),
build(:pageview,
domain: site.domain,
pathname: "/non-existing",
user_id: @user_id,
timestamp: ~N[2021-01-01 00:00:02]
),
build(:event,
name: "404",
domain: site.domain,
pathname: "/non-existing",
user_id: @user_id,
timestamp: ~N[2021-01-01 00:00:02]
),
build(:pageview,
domain: site.domain,
pathname: "/non-existing",
user_id: @user_id,
timestamp: ~N[2021-01-01 00:00:03]
)
])
conn =
get(conn, "/api/v1/stats/breakdown", %{
"site_id" => site.domain,
"period" => "day",
"date" => "2021-01-01",
"property" => "event:name",
"metrics" => "visitors,events"
})
assert json_response(conn, 200) == %{
"results" => [
%{"name" => "pageview", "visitors" => 1, "events" => 4},
%{"name" => "404", "visitors" => 1, "events" => 2}
]
}
end
test "can breakdown by event:name while filtering for something", %{conn: conn, site: site} do
populate_stats([
build(:event,
@ -1489,7 +1548,7 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do
"period" => "day",
"date" => "2021-01-01",
"property" => "event:page",
"metrics" => "visitors,pageviews,bounce_rate,visit_duration"
"metrics" => "visitors,pageviews,events,bounce_rate,visit_duration"
})
assert json_response(conn, 200) == %{
@ -1499,14 +1558,16 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do
"visitors" => 2,
"bounce_rate" => 50,
"visit_duration" => 300,
"pageviews" => 2
"pageviews" => 2,
"events" => 2
},
%{
"page" => "/plausible.io",
"visitors" => 2,
"bounce_rate" => 100,
"visit_duration" => 0,
"pageviews" => 2
"pageviews" => 2,
"events" => 2
}
]
}

Loading…
Cancel
Save