Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return empty list when breaking down by event:page without events #2530

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
## v1.5.1 - 2022-12-06

### Fixed
- Return empty list when breaking down by event:page without events plausible/analytics#2530
- Fallback to empty build metadata when failing to parse $BUILD_METADATA plausible/analytics#2503

## v1.5.0 - 2022-12-02
Expand Down
28 changes: 16 additions & 12 deletions lib/plausible/stats/breakdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,25 @@ defmodule Plausible.Stats.Breakdown do
Query.put_filter(query, "visit:entry_page", {:member, Enum.map(pages, & &1[:page])})
end

{limit, _page} = pagination
if Enum.any?(event_metrics) && Enum.empty?(event_result) do
[]
else
{limit, _page} = pagination

session_result =
breakdown_sessions(site, new_query, "visit:entry_page", session_metrics, {limit, 1})
|> transform_keys(%{entry_page: :page})
session_result =
breakdown_sessions(site, new_query, "visit:entry_page", session_metrics, {limit, 1})
|> transform_keys(%{entry_page: :page})

metrics = metrics ++ [:page]
metrics = metrics ++ [:page]

zip_results(
event_result,
session_result,
:page,
metrics
)
|> Enum.map(&Map.take(&1, metrics))
zip_results(
event_result,
session_result,
:page,
metrics
)
|> Enum.map(&Map.take(&1, metrics))
end
end

def breakdown(site, query, property, metrics, pagination) when property in @event_props do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,34 @@ defmodule PlausibleWeb.Api.ExternalStatsController.BreakdownTest do
}
end

test "breakdown by event:page when there are no events in the second page", %{
conn: conn,
site: site
} do
populate_stats([
build(:pageview, pathname: "/", domain: site.domain, timestamp: ~N[2021-01-01 00:00:00]),
build(:pageview, pathname: "/", domain: site.domain, timestamp: ~N[2021-01-01 00:25:00]),
build(:pageview,
pathname: "/plausible.io",
domain: site.domain,
timestamp: ~N[2021-01-01 00:00:00]
)
])

conn =
get(conn, "/api/v1/stats/breakdown", %{
"site_id" => site.domain,
"period" => "day",
"date" => "2021-01-01",
"property" => "event:page",
"metrics" => "visitors,bounce_rate",
"page" => 2,
"limit" => 2
})

assert json_response(conn, 200) == %{"results" => []}
end

describe "custom events" do
test "can breakdown by event:name", %{conn: conn, site: site} do
populate_stats([
Expand Down