Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Ignore unknown country code (#2223)

Uku Tahtb239f73a6d96
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bc0c1675ae..55f97d8333 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,6 +54,7 @@ All notable changes to this project will be documented in this file.
- Remove the `+ Add Site` link to the site-switcher dropdown in the dashboard.
- `DISABLE_REGISTRATIONS` configuration parameter can now accept `invite_only` to allow invited users to register an account while keeping regular registrations disabled plausible/analytics#1841
- New and improved Session tracking module for higher throughput and lower latency. [PR#1934](https://github.com/plausible/analytics#1934)
+- Do not display ZZ country code in countries report [PR#1934](https://github.com/plausible/analytics#2223)
## v1.4.1
diff --git a/lib/plausible/stats/breakdown.ex b/lib/plausible/stats/breakdown.ex
index 494e5a612c..abba5bfc0b 100644
--- a/lib/plausible/stats/breakdown.ex
+++ b/lib/plausible/stats/breakdown.ex
@@ -381,7 +381,7 @@ defmodule Plausible.Stats.Breakdown do
defp do_group_by(q, "visit:country") do
from(
s in q,
- where: s.country_code != "\0\0",
+ where: s.country_code != "\0\0" and s.country_code != "ZZ",
group_by: s.country_code,
select_merge: %{country: s.country_code}
)
diff --git a/test/plausible_web/controllers/api/stats_controller/countries_test.exs b/test/plausible_web/controllers/api/stats_controller/countries_test.exs
index 45fa35749c..91e266b60b 100644
--- a/test/plausible_web/controllers/api/stats_controller/countries_test.exs
+++ b/test/plausible_web/controllers/api/stats_controller/countries_test.exs
@@ -67,6 +67,14 @@ defmodule PlausibleWeb.Api.StatsController.CountriesTest do
]
end
+ test "ignores unknown country code ZZ", %{conn: conn, site: site} do
+ populate_stats(site, [build(:pageview, country_code: "ZZ")])
+
+ conn = get(conn, "/api/stats/#{site.domain}/countries?period=day")
+
+ assert json_response(conn, 200) == []
+ end
+
test "calculates conversion_rate when filtering for goal", %{conn: conn, site: site} do
populate_stats(site, [
build(:pageview,