mirror of
https://github.com/plausible/analytics.git
synced 2024-11-23 11:12:15 +03:00
Ignore unknown country code
This commit is contained in:
parent
81eb2b73df
commit
cd40579740
@ -27,7 +27,8 @@ config :geolix,
|
||||
adapter: Geolix.Adapter.Fake,
|
||||
data: %{
|
||||
{1, 1, 1, 1} => %{country: %{iso_code: "US"}},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1} => %{country: %{iso_code: "US"}}
|
||||
{1, 1, 1, 1, 1, 1, 1, 1} => %{country: %{iso_code: "US"}},
|
||||
{0, 0, 0, 0} => %{country: %{iso_code: "ZZ"}}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -385,7 +385,10 @@ defmodule PlausibleWeb.Api.ExternalController do
|
||||
PlausibleWeb.RemoteIp.get(conn)
|
||||
|> Geolix.lookup()
|
||||
|
||||
country_code = get_in(result, [:geolocation, :country, :iso_code])
|
||||
country_code =
|
||||
get_in(result, [:geolocation, :country, :iso_code])
|
||||
|> ignore_unknown_country
|
||||
|
||||
city_geoname_id = get_in(result, [:geolocation, :city, :geoname_id])
|
||||
|
||||
subdivision1_code =
|
||||
@ -414,6 +417,9 @@ defmodule PlausibleWeb.Api.ExternalController do
|
||||
}
|
||||
end
|
||||
|
||||
defp ignore_unknown_country("ZZ"), do: nil
|
||||
defp ignore_unknown_country(country), do: country
|
||||
|
||||
@decorate trace("ingest.parse_referrer")
|
||||
defp parse_referrer(_, nil), do: nil
|
||||
|
||||
|
@ -558,6 +558,22 @@ defmodule PlausibleWeb.Api.ExternalControllerTest do
|
||||
assert pageview.country_code == "US"
|
||||
end
|
||||
|
||||
test "ignores unknown country code ZZ", %{conn: conn} do
|
||||
params = %{
|
||||
name: "pageview",
|
||||
domain: "external-controller-test-zz-country.com",
|
||||
url: "http://gigride.live/"
|
||||
}
|
||||
|
||||
conn
|
||||
|> put_req_header("x-forwarded-for", "0.0.0.0")
|
||||
|> post("/api/event", params)
|
||||
|
||||
pageview = get_event("external-controller-test-zz-country.com")
|
||||
|
||||
assert pageview.country_code == <<0, 0>>
|
||||
end
|
||||
|
||||
test "scrubs port from x-forwarded-for", %{conn: conn} do
|
||||
params = %{
|
||||
name: "pageview",
|
||||
|
Loading…
Reference in New Issue
Block a user