# lookupCountry

**Kind:** Function

**Source:** [`atloria-monorepo/apps/api/src/analytics/utils/tracking-utils.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/apps/api/src/analytics/utils/tracking-utils.ts#L176)

Resolve a client IP to a 2-letter ISO country code using the bundled
MaxMind GeoLite2 database (via `geoip-lite`). This is the same approach
Umami, Plausible, and Matomo all use for server-side geolocation.

Returns null for:
  - localhost / private IPs (127.*, 10.*, 192.168.*, etc.)
  - IPs not found in the database
  - malformed inputs

The GeoLite2 database is loaded into RAM once at startup (~2MB). All
subsequent lookups are pure memory reads — sub-microsecond latency.

## Signature

```ts
function lookupCountry(ip: string | null): string | null
```

## Parameters

| Name | Type |
|---|---|
| `ip` | `string | null` |

**Returns:** `string | null`
