Filter out GA imported data with no visitors recorded (#3123)

pull/3021/head r2023.07.11-141
hq1 3 years ago committed by GitHub
parent 9debcdee24
commit cf5cc8de94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -114,6 +114,7 @@ defmodule Plausible.Stats.Imported do
group_by: field(i, ^dim),
where: i.site_id == ^site.id,
where: i.date >= ^query.date_range.first and i.date <= ^query.date_range.last,
where: i.visitors > 0,
select: %{}
)
|> select_imported_metrics(metrics)

@ -130,6 +130,27 @@ defmodule PlausibleWeb.Api.StatsController.BrowsersTest do
]
end
test "skips breakdown when visitors=0 (possibly due to 'Enable Users Metric' in GA)", %{
conn: conn,
site: site
} do
populate_stats(site, [
build(:imported_browsers, browser: "Chrome", visitors: 0, visits: 14),
build(:imported_browsers, browser: "Firefox", visitors: 0, visits: 14),
build(:imported_browsers,
browser: "''",
visitors: 0,
visits: 14,
visit_duration: 0,
bounces: 14
)
])
conn = get(conn, "/api/stats/#{site.domain}/browsers?period=day&with_imported=true")
assert json_response(conn, 200) == []
end
test "returns (not set) when appropriate", %{conn: conn, site: site} do
populate_stats(site, [
build(:pageview,

Loading…
Cancel
Save