Skip to content

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

Ignore unknown country in imported data (#2247)

Uku Taht669091f2efbb
diff --git a/lib/plausible/stats/imported.ex b/lib/plausible/stats/imported.ex
index 198311c029..9888bba5f6 100644
--- a/lib/plausible/stats/imported.ex
+++ b/lib/plausible/stats/imported.ex
@@ -179,7 +179,7 @@ defmodule Plausible.Stats.Imported do
|> select_merge([i], %{exit_page: i.exit_page, visits: sum(i.exits)})
:country ->
- imported_q |> select_merge([i], %{country: i.country})
+ imported_q |> where([i], i.country != "ZZ") |> select_merge([i], %{country: i.country})
:region ->
imported_q |> where([i], i.region != "") |> select_merge([i], %{region: i.region})
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 91e266b60b..bdf2df11f1 100644
--- a/test/plausible_web/controllers/api/stats_controller/countries_test.exs
+++ b/test/plausible_web/controllers/api/stats_controller/countries_test.exs
@@ -68,9 +68,12 @@ 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")])
+ populate_stats(site, [
+ build(:pageview, country_code: "ZZ"),
+ build(:imported_locations, country: "ZZ")
+ ])
- conn = get(conn, "/api/stats/#{site.domain}/countries?period=day")
+ conn = get(conn, "/api/stats/#{site.domain}/countries?period=day&with_imported=true")
assert json_response(conn, 200) == []
end