Facade for IP → geo lookup.
Reads configuration from config :good_analytics, :geo:
config :good_analytics, :geo,
provider: GoodAnalytics.Geo.Locus,
loader: {:maxmind, "GeoLite2-City"},
normalizer: GoodAnalytics.Geo.Normalizer.MaxMind # defaultReturns the normalized canonical map (see
GoodAnalytics.Geo.Normalizer.normalized) on success.
Failure modes
{:error, :geo_disabled}— the:locusdependency is not loaded OR no:provideris configured. Callers SHOULD treat this as non-fatal and continue without enrichment.{:error, :loader_not_ready}— provider is configured but the MMDB loader has not finished initialising (cold start, or fetch failure). The redirect path falls back to the link's default URL and skipsgeo_targeting.{:error, :not_found}— IP did not match any range in the loaded database (private/reserved range, etc.).{:error, {:invalid_ip, value}}— the input could not be parsed as an IP address.
Summary
Functions
True when geo enrichment is configured AND :locus is loaded.
Fire-and-forget geo enrichment for a known visitor.
Looks up the geo data for an IP.
Parses a value into an :inet.ip_address/0 tuple.
Functions
@spec enabled?() :: boolean()
True when geo enrichment is configured AND :locus is loaded.
@spec enqueue_enrichment(Ecto.UUID.t(), term()) :: :ok
Fire-and-forget geo enrichment for a known visitor.
No-op when geo is not enabled. Tasks run under GoodAnalytics.GeoTaskSupervisor
which is capped at 10,000 in-flight tasks; when the cap is reached the
enrichment is dropped and a single info-level log line is emitted. Event
ingest is never affected — enrichment is purely advisory.
@spec lookup(term()) :: {:ok, GoodAnalytics.Geo.Normalizer.normalized()} | {:error, term()}
Looks up the geo data for an IP.
Accepts a string, an :inet.ip_address/0 tuple, or an EctoNetwork.INET
struct.
@spec parse_ip(term()) :: {:ok, :inet.ip_address()} | {:error, {:invalid_ip, term()}}
Parses a value into an :inet.ip_address/0 tuple.
Accepts:
- an
:inet.ip_address/0tuple (passes through) - a string (parsed via
:inet.parse_address/1) - a
Postgrex.INETstruct (the underlying type backingEctoNetwork.INET—:addressis unwrapped)