Source: https://datafa.st/docs/api-realtime
Markdown source: https://datafa.st/docs/api-realtime.md
Description: Get real-time visitor count for your website (visitors active in the last 5 minutes).

# Get real-time visitors

`GET https://datafa.st/api/v1/analytics/realtime`

Retrieve the count of active visitors on your website in real-time (visitors with activity in the last 5 minutes). Requires [Bearer Token](/docs/api-introduction) authentication.

## Response

**Success (200 OK):** Returns real-time visitor count

```json
{
  "status": "success",
  "data": [
    {
      "visitors": 42
    }
  ]
}
```

## Notes

- Real-time data shows visitors who have had activity (pageviews, events) within the last 5 minutes
- This endpoint is optimized for frequent polling with shorter cache times
- Unlike other analytics endpoints, this does not support date range filtering as it always shows current activity

## Errors

- **401 Unauthorized:** Missing or invalid API key
- **404 Not Found:** Website not found
- **500 Internal Server Error:** Server-side issue

## Query parameters

### Optional parameters

- **`fields`** (string): Comma-separated list of fields to return. Valid field: `visitors`. If not specified, all fields are returned.

## Code examples

### Example request (Node.js/Express)

```javascript
const response = await fetch(
  "https://datafa.st/api/v1/analytics/realtime",
  {
    method: "GET",
    headers: {
      Authorization: `Bearer ${DATAFAST_API_KEY}`,
      "Content-Type": "application/json",
    },
  }
);

const result = await response.json();
console.log(`Active visitors: ${result.data[0].visitors}`);
```

### Success response (200 OK)

```json
{
  "status": "success",
  "data": [
    {
      "visitors": 42
    }
  ]
}
```
