|
- {countryFullName}
+ {this.props.renderIcon && this.props.renderIcon(tableItem)}
+ {this.props.renderIcon && ' '}
+ {tableItem.name}
|
{numberFormatter(tableItem.visitors)}
- {tableItem.percentage &&
+ {tableItem.percentage >= 0 &&
({tableItem.percentage}%) }
|
diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex
index 568054441..ad42b284f 100644
--- a/lib/plausible_web/controllers/api/stats_controller.ex
+++ b/lib/plausible_web/controllers/api/stats_controller.ex
@@ -494,8 +494,8 @@ defmodule PlausibleWeb.Api.StatsController do
countries =
countries
|> Enum.map(fn country ->
- iso3166 = Stats.CountryName.from_iso3166(country["code"])
- Map.put(country, "name", iso3166)
+ country_iso_info = ISOCodes.ISO3166_1.get(country["code"])
+ Map.put(country, "name", country_iso_info.name)
end)
if Map.has_key?(query.filters, "event:goal") do
@@ -507,10 +507,14 @@ defmodule PlausibleWeb.Api.StatsController do
end
else
countries =
- Enum.map(countries, fn country ->
- name = Stats.CountryName.from_iso3166(country["code"])
- code = Stats.CountryName.to_alpha3(country["code"])
- Map.merge(country, %{"name" => name, "code" => code})
+ Enum.map(countries, fn row ->
+ country = ISOCodes.ISO3166_1.get(row["code"])
+
+ Map.merge(row, %{
+ "name" => country.name,
+ "flag" => country.flag,
+ "code" => country.alpha_3
+ })
end)
json(conn, countries)
@@ -526,8 +530,11 @@ defmodule PlausibleWeb.Api.StatsController do
Stats.breakdown(site, query, "visit:region", ["visitors"], pagination)
|> transform_keys(%{"region" => "code"})
|> Enum.map(fn region ->
- name = Stats.CountryName.from_iso3166_2(region["code"])
- Map.put(region, "name", name)
+ country_code = region["code"] |> String.split("-") |> List.first()
+
+ region_entry = ISOCodes.ISO3166_2.get(region["code"])
+ country_entry = ISOCodes.ISO3166_1.get(country_code)
+ Map.merge(region, %{"name" => region_entry.name, "country_flag" => country_entry.flag})
end)
json(conn, countries)
diff --git a/mix.exs b/mix.exs
index 4be1eac35..aea4c9e05 100644
--- a/mix.exs
+++ b/mix.exs
@@ -85,6 +85,7 @@ defmodule Plausible.MixProject do
{:sshex, "2.2.1"},
{:geolix, "~> 1.0"},
{:clickhouse_ecto, git: "https://github.com/plausible/clickhouse_ecto.git"},
+ {:iso_codes, git: "https://github.com/plausible/iso_codes"},
{:geolix_adapter_mmdb2, "~> 0.5.0"},
{:cachex, "~> 3.4"},
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
diff --git a/mix.lock b/mix.lock
index 6548ac415..5aac48a2b 100644
--- a/mix.lock
+++ b/mix.lock
@@ -49,6 +49,7 @@
"httpoison": {:hex, :httpoison, "1.8.0", "6b85dea15820b7804ef607ff78406ab449dd78bed923a49c7160e1886e987a3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "28089eaa98cf90c66265b6b5ad87c59a3729bea2e74e9d08f9b51eb9729b3c3a"},
"hut": {:hex, :hut, "1.3.0", "71f2f054e657c03f959cf1acc43f436ea87580696528ca2a55c8afb1b06c85e7", [:"erlang.mk", :rebar, :rebar3], [], "hexpm", "7e15d28555d8a1f2b5a3a931ec120af0753e4853a4c66053db354f35bf9ab563"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
+ "iso_codes": {:git, "https://github.com/plausible/iso_codes", "413312b01cbdbd9a8283deb94f91bca12830eba4", []},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"jumper": {:hex, :jumper, "1.0.1", "3c00542ef1a83532b72269fab9f0f0c82bf23a35e27d278bfd9ed0865cecabff", [:mix], [], "hexpm", "318c59078ac220e966d27af3646026db9b5a5e6703cb2aa3e26bcfaba65b7433"},
"kaffy": {:hex, :kaffy, "0.9.0", "bef34c9729f6a3af4d0dea8eede8bcb9e11371a83ac9a8b393991bce81839517", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.11", [hex: :phoenix_html, repo: "hexpm", optional: false]}], "hexpm", "d18ff57b8e68feb433aed11e71510cd357abc7034e75358af5deff7d0d4c6ed3"},
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 345cd3f07..444ce4eff 100644
--- a/test/plausible_web/controllers/api/stats_controller/countries_test.exs
+++ b/test/plausible_web/controllers/api/stats_controller/countries_test.exs
@@ -24,12 +24,14 @@ defmodule PlausibleWeb.Api.StatsController.CountriesTest do
%{
"code" => "EST",
"name" => "Estonia",
+ "flag" => "🇪🇪",
"visitors" => 2,
"percentage" => 67
},
%{
"code" => "GBR",
"name" => "United Kingdom",
+ "flag" => "🇬🇧",
"visitors" => 1,
"percentage" => 33
}
@@ -62,6 +64,7 @@ defmodule PlausibleWeb.Api.StatsController.CountriesTest do
%{
"code" => "GBR",
"name" => "United Kingdom",
+ "flag" => "🇬🇧",
"total_visitors" => 1,
"visitors" => 1,
"conversion_rate" => 100.0
@@ -69,6 +72,7 @@ defmodule PlausibleWeb.Api.StatsController.CountriesTest do
%{
"code" => "EST",
"name" => "Estonia",
+ "flag" => "🇪🇪",
"total_visitors" => 2,
"visitors" => 1,
"conversion_rate" => 50.0