# extractClientIp

**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#L128)

Extract the client IP from a NestJS/Express request. Checks headers set
by reverse proxies and CDNs in this order:
  1. CF-Connecting-IP (Cloudflare)
  2. X-Real-IP (nginx default)
  3. X-Forwarded-For (standard proxy header — first IP in the chain)
  4. req.ip / connection.remoteAddress (direct connection fallback)

Returns `null` if nothing usable is found (should be rare in production).

## Signature

```ts
function extractClientIp(req: {
  headers?: Record<string, string | string[] | undefined>;
  ip?: string;
  connection?: { remoteAddress?: string };
  socket?: { remoteAddress?: string };
}): string | null
```

## Parameters

| Name | Type |
|---|---|
| `req` | `{
  headers?: Record<string, string | string[] | undefined>;
  ip?: string;
  connection?: { remoteAddress?: string };
  socket?: { remoteAddress?: string };
}` |

**Returns:** `string | null`
