> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leaf7.fun/llms.txt
> Use this file to discover all available pages before exploring further.

# Analytics

> Fetch execution statistics, security events, and system health data.

# Analytics

The analytics endpoints provide real-time data about your script executions, security events, and system health. Use them to build custom dashboards or monitoring tools.

***

## Dashboard overview

`GET` `/api/vendor/metrics/overview`

Get top-line metrics for your vendor account.

#### Headers

| Name            | Type   | Required | Description           |
| --------------- | ------ | -------- | --------------------- |
| `Authorization` | String | ✅        | `Bearer YOUR_API_KEY` |

<Tabs>
  <Tab title="200 OK">
    ```json theme={null}
    {
        "active_projects": 3,
        "total_executions": 12847,
        "active_keys": 156,
        "api_status": "Operational"
    }
    ```

    | Field              | Description                           |
    | ------------------ | ------------------------------------- |
    | `active_projects`  | Number of projects you own            |
    | `total_executions` | Sum of all key + project executions   |
    | `active_keys`      | Keys that are not expired             |
    | `api_status`       | Always `"Operational"` when reachable |
  </Tab>
</Tabs>

***

## Security events

`GET` `/api/vendor/metrics/events`

Fetch recent security events (key creations, HWID resets, blacklists, etc.).

#### Query Parameters

| Name    | Type    | Required | Description                               |
| ------- | ------- | -------- | ----------------------------------------- |
| `limit` | Integer | ❌        | Number of events to return (default: `4`) |

<Tabs>
  <Tab title="200 OK">
    ```json theme={null}
    [
        {
            "id": 42,
            "type": "Success",
            "activity": "New project vault initialized",
            "project": "Premium Hub",
            "time": "5 min ago"
        },
        {
            "id": 41,
            "type": "Warning",
            "activity": "HWID Reset for key XkJ9a2bR...",
            "project": "Premium Hub",
            "time": "2 hours ago"
        },
        {
            "id": 40,
            "type": "Critical",
            "activity": "Blacklisted IP: 192.168.1.100 - Attempted script dump",
            "project": "System",
            "time": "1 days ago"
        }
    ]
    ```

    | Event Type | Meaning                                            |
    | ---------- | -------------------------------------------------- |
    | `Success`  | Normal operations (project created, key generated) |
    | `Warning`  | Suspicious activity (HWID mismatch, reset)         |
    | `Critical` | Security threat (blacklist, blocked execution)     |
  </Tab>
</Tabs>

***

## Analytics chart data

`GET` `/api/vendor/metrics/chart`

Get detailed analytics data including execution stats, 12-hour event history, and system health.

#### Query Parameters

| Name         | Type   | Required | Description                       |
| ------------ | ------ | -------- | --------------------------------- |
| `project_id` | String | ❌        | Filter data to a specific project |

<Tabs>
  <Tab title="200 OK">
    ```json theme={null}
    {
        "stats": [
            { "label": "Total Executions", "val": "12847" },
            { "label": "Active Script Keys", "val": "156" },
            { "label": "Unique Devices", "val": "89" },
            { "label": "Auth Failures", "val": "12" }
        ],
        "chartData": [0, 3, 5, 2, 8, 12, 7, 4, 6, 3, 1, 9],
        "timeLabels": [
            "03:00", "04:00", "05:00", "06:00",
            "07:00", "08:00", "09:00", "10:00",
            "11:00", "12:00", "13:00", "14:00"
        ],
        "geography": [],
        "systemHealth": [
            { "label": "Global DB", "val": "100.0%" },
            { "label": "API Gateway", "val": "100.0%" },
            { "label": "Auth Proxy", "val": "100.0%" }
        ]
    }
    ```

    | Field          | Description                                      |
    | -------------- | ------------------------------------------------ |
    | `stats`        | Summary metrics as label-value pairs             |
    | `chartData`    | Array of 12 values — event count per hour bucket |
    | `timeLabels`   | Corresponding hour labels for the chart          |
    | `systemHealth` | Real-time health check for all subsystems        |
  </Tab>
</Tabs>
