From b239f73a6d96594fe43f8ea8d77f439005f0166a Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Fri, 16 Sep 2022 11:02:39 +0300 Subject: [PATCH] Ignore unknown country code (#2223) * Ignore unknown country code * Add changelog entry --- CHANGELOG.md | 1 + lib/plausible/stats/breakdown.ex | 2 +- .../controllers/api/stats_controller/countries_test.exs | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc0c1675a..55f97d833 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 494e5a612..abba5bfc0 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 45fa35749..91e266b60 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,