diff --git a/assets/js/dashboard/router.js b/assets/js/dashboard/router.js
index 0e7ec77ef..84df38d8a 100644
--- a/assets/js/dashboard/router.js
+++ b/assets/js/dashboard/router.js
@@ -55,7 +55,7 @@ export default function Router({site, loggedIn, currentUserRole}) {
-
+
@@ -66,6 +66,10 @@ export default function Router({site, loggedIn, currentUserRole}) {
);
}
+function renderCityIcon(city) {
+ return {city.country_flag}
+}
+
function renderCountryIcon(country) {
return {country.flag}
}
diff --git a/assets/js/dashboard/stats/locations/index.js b/assets/js/dashboard/stats/locations/index.js
index ec6c22839..2327d9507 100644
--- a/assets/js/dashboard/stats/locations/index.js
+++ b/assets/js/dashboard/stats/locations/index.js
@@ -58,6 +58,10 @@ function Cities({query, site}) {
return api.get(apiPath(site, '/cities'), query, {limit: 9})
}
+ function renderIcon(city) {
+ return site.cities && {city.country_flag}
+ }
+
return (
)
diff --git a/lib/plausible/application.ex b/lib/plausible/application.ex
index 044c83de0..5e7f31285 100644
--- a/lib/plausible/application.ex
+++ b/lib/plausible/application.ex
@@ -24,6 +24,7 @@ defmodule Plausible.Application do
setup_opentelemetry()
setup_sentry()
setup_cache_stats()
+ Location.load_all()
Application.put_env(:plausible, :server_start, Timex.now())
Supervisor.start_link(children, opts)
end
diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex
index ad42b284f..a04596a35 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 ->
- country_iso_info = ISOCodes.ISO3166_1.get(country["code"])
- Map.put(country, "name", country_iso_info.name)
+ country_info = Location.get_country(country["code"])
+ Map.put(country, "name", country_info.name)
end)
if Map.has_key?(query.filters, "event:goal") do
@@ -508,7 +508,7 @@ defmodule PlausibleWeb.Api.StatsController do
else
countries =
Enum.map(countries, fn row ->
- country = ISOCodes.ISO3166_1.get(row["code"])
+ country = Location.get_country(row["code"])
Map.merge(row, %{
"name" => country.name,
@@ -530,10 +530,8 @@ defmodule PlausibleWeb.Api.StatsController do
Stats.breakdown(site, query, "visit:region", ["visitors"], pagination)
|> transform_keys(%{"region" => "code"})
|> Enum.map(fn region ->
- country_code = region["code"] |> String.split("-") |> List.first()
-
- region_entry = ISOCodes.ISO3166_2.get(region["code"])
- country_entry = ISOCodes.ISO3166_1.get(country_code)
+ region_entry = Location.get_subdivision(region["code"])
+ country_entry = Location.get_country(region_entry.country_code)
Map.merge(region, %{"name" => region_entry.name, "country_flag" => country_entry.flag})
end)
@@ -549,8 +547,18 @@ defmodule PlausibleWeb.Api.StatsController do
Stats.breakdown(site, query, "visit:city", ["visitors"], pagination)
|> transform_keys(%{"city" => "code"})
|> Enum.map(fn city ->
- name = Stats.CountryName.from_geoname_id(city["code"], "N/A")
- Map.put(city, "name", name)
+ city_info = Location.get_city(city["code"])
+
+ if city_info do
+ country_info = Location.get_country(city_info.country_code)
+
+ Map.merge(city, %{
+ "name" => city_info.name,
+ "country_flag" => country_info.flag
+ })
+ else
+ Map.merge(city, %{"name" => "N/A"})
+ end
end)
json(conn, cities)
diff --git a/mix.exs b/mix.exs
index f8cb2e03a..6e65f2c39 100644
--- a/mix.exs
+++ b/mix.exs
@@ -85,7 +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"},
+ {:location, git: "https://github.com/plausible/location.git"},
{: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 b76bf89c1..8719d2235 100644
--- a/mix.lock
+++ b/mix.lock
@@ -51,10 +51,10 @@
"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"},
+ "location": {:git, "https://github.com/plausible/location.git", "07a628bd6e698f674aa034409fb813505e61b207", []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mime": {:hex, :mime, "1.6.0", "dabde576a497cef4bbdd60aceee8160e02a6c89250d6c0b29e56c0dfb00db3d2", [:mix], [], "hexpm", "31a1a8613f8321143dde1dafc36006a17d28d02bdfecb9e95a880fa7aabd19a7"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},