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

# Metrics

> Access workspace metrics and analytics

## Get Metrics Summary

Retrieve a comprehensive summary of workspace metrics including client health, revenue, and engagement statistics.

<ParamField path="workspaceId" type="string" required>
  Your workspace domain (e.g., `yourcompany.com`)
</ParamField>

<ParamField query="windowDays" type="number">
  Time window in days for metrics calculation (default: 7, max: 90)
</ParamField>

<ParamField query="riskThreshold" type="number">
  Score threshold for identifying at-risk clients (default: 40, range: 0-100)
</ParamField>

### Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.gostanna.com/api/metrics/summary?workspaceId=yourcompany.com&windowDays=30" \
    -H "Authorization: Bearer sk-your-api-key-here"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.gostanna.com/api/metrics/summary?workspaceId=yourcompany.com&windowDays=30', {
    headers: {
      'Authorization': 'Bearer sk-your-api-key-here'
    }
  });

  const summary = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.gostanna.com/api/metrics/summary',
      params={
          'workspaceId': 'yourcompany.com',
          'windowDays': 30
      },
      headers={'Authorization': 'Bearer sk-your-api-key-here'}
  )

  summary = response.json()
  ```
</CodeGroup>

### Response

```json theme={null}
{
  "totals": {
    "clients": 125,
    "contacts": 450,
    "interactionsWindow": 1250,
    "renewals30d": 15,
    "openTasks": 8
  },
  "revenue": {
    "mrrTotal": 625000,
    "mrrAtRisk": 45000,
    "renewals30dValue": 85000,
    "avgClientValue": 5000
  },
  "health": {
    "avgScore": 72.5,
    "change7": 2.3,
    "change7Pct": 3.2,
    "threshold": 40,
    "atRiskCount": 18,
    "improvingCount": 42
  },
  "lists": {
    "topRisks": [
      {
        "clientId": "client_123",
        "name": "Example Corp",
        "score": 25,
        "mrr": 8000,
        "reason": "No interaction in 30 days"
      }
    ],
    "topImproving": [
      {
        "clientId": "client_456",
        "name": "Growth Inc",
        "score": 88,
        "scoreChange": 15,
        "mrr": 12000
      }
    ],
    "renewals": [
      {
        "clientId": "client_789",
        "name": "Renewal Co",
        "renewalDate": "2024-02-15",
        "mrr": 5000,
        "daysUntil": 14
      }
    ]
  },
  "asOf": "2024-01-31T23:59:59Z"
}
```

***

## Get Health Trends

Retrieve historical health score trends for your workspace.

<ParamField path="workspaceId" type="string" required>
  Your workspace domain
</ParamField>

<ParamField query="windowDays" type="number">
  Number of days of history to retrieve (default: 30, max: 365)
</ParamField>

<ParamField query="interval" type="string">
  Data point interval: `daily`, `weekly`, or `monthly` (default: `daily`)
</ParamField>

### Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.gostanna.com/api/metrics/trends/health?workspaceId=yourcompany.com&windowDays=30&interval=daily" \
    -H "Authorization: Bearer sk-your-api-key-here"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.gostanna.com/api/metrics/trends/health?workspaceId=yourcompany.com&windowDays=30', {
    headers: {
      'Authorization': 'Bearer sk-your-api-key-here'
    }
  });

  const trends = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.gostanna.com/api/metrics/trends/health',
      params={
          'workspaceId': 'yourcompany.com',
          'windowDays': 30,
          'interval': 'daily'
      },
      headers={'Authorization': 'Bearer sk-your-api-key-here'}
  )

  trends = response.json()
  ```
</CodeGroup>

### Response

```json theme={null}
[
  {
    "date": "2024-01-01",
    "avgScore": 70.2,
    "clientCount": 120
  },
  {
    "date": "2024-01-02",
    "avgScore": 70.5,
    "clientCount": 120
  },
  {
    "date": "2024-01-03",
    "avgScore": 71.1,
    "clientCount": 121
  }
]
```

***

## Get Sentiment Trends

Track sentiment analysis trends over time.

<ParamField path="workspaceId" type="string" required>
  Your workspace domain
</ParamField>

<ParamField query="windowDays" type="number">
  Number of days of history (default: 30)
</ParamField>

### Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.gostanna.com/api/metrics/trends/sentiment?workspaceId=yourcompany.com&windowDays=30" \
    -H "Authorization: Bearer sk-your-api-key-here"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.gostanna.com/api/metrics/trends/sentiment?workspaceId=yourcompany.com&windowDays=30', {
    headers: {
      'Authorization': 'Bearer sk-your-api-key-here'
    }
  });

  const sentiment = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.gostanna.com/api/metrics/trends/sentiment',
      params={
          'workspaceId': 'yourcompany.com',
          'windowDays': 30
      },
      headers={'Authorization': 'Bearer sk-your-api-key-here'}
  )

  sentiment = response.json()
  ```
</CodeGroup>

### Response

```json theme={null}
[
  {
    "date": "2024-01-01",
    "avgSentiment": 0.72,
    "volume": 45,
    "positive": 32,
    "neutral": 10,
    "negative": 3
  },
  {
    "date": "2024-01-02",
    "avgSentiment": 0.75,
    "volume": 52,
    "positive": 40,
    "neutral": 8,
    "negative": 4
  }
]
```

***

## Get Interaction Mix

Analyze the distribution of interaction types.

<ParamField path="workspaceId" type="string" required>
  Your workspace domain
</ParamField>

<ParamField query="windowDays" type="number">
  Time window for analysis (default: 30)
</ParamField>

### Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.gostanna.com/api/metrics/trends/interactions?workspaceId=yourcompany.com&windowDays=30" \
    -H "Authorization: Bearer sk-your-api-key-here"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.gostanna.com/api/metrics/trends/interactions?workspaceId=yourcompany.com&windowDays=30', {
    headers: {
      'Authorization': 'Bearer sk-your-api-key-here'
    }
  });

  const interactions = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.gostanna.com/api/metrics/trends/interactions',
      params={
          'workspaceId': 'yourcompany.com',
          'windowDays': 30
      },
      headers={'Authorization': 'Bearer sk-your-api-key-here'}
  )

  interactions = response.json()
  ```
</CodeGroup>

### Response

```json theme={null}
[
  {
    "source": "email",
    "count": 450,
    "percentage": 45
  },
  {
    "source": "slack",
    "count": 280,
    "percentage": 28
  },
  {
    "source": "meeting",
    "count": 150,
    "percentage": 15
  },
  {
    "source": "support_ticket",
    "count": 120,
    "percentage": 12
  }
]
```

***

## Get Score Deltas

Analyze significant changes in client health scores.

<ParamField path="workspaceId" type="string" required>
  Your workspace domain
</ParamField>

<ParamField query="windowDays" type="number">
  Time window for delta calculation (default: 7)
</ParamField>

<ParamField query="minDelta" type="number">
  Minimum score change to include (default: 10)
</ParamField>

### Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.gostanna.com/api/metrics/deltas?workspaceId=yourcompany.com&windowDays=7&minDelta=10" \
    -H "Authorization: Bearer sk-your-api-key-here"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.gostanna.com/api/metrics/deltas?workspaceId=yourcompany.com&windowDays=7', {
    headers: {
      'Authorization': 'Bearer sk-your-api-key-here'
    }
  });

  const deltas = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.gostanna.com/api/metrics/deltas',
      params={
          'workspaceId': 'yourcompany.com',
          'windowDays': 7,
          'minDelta': 10
      },
      headers={'Authorization': 'Bearer sk-your-api-key-here'}
  )

  deltas = response.json()
  ```
</CodeGroup>

### Response

```json theme={null}
[
  {
    "reason": "Increased positive interactions",
    "totalDelta": 125,
    "count": 15,
    "avgDelta": 8.3,
    "clients": [
      {
        "id": "client_123",
        "name": "Example Corp",
        "delta": 15,
        "currentScore": 85,
        "previousScore": 70
      }
    ]
  },
  {
    "reason": "Reduced response times",
    "totalDelta": -45,
    "count": 5,
    "avgDelta": -9,
    "clients": []
  }
]
```

***

## Get Email Engagement Stats

Analyze email engagement metrics across your client base.

<ParamField path="workspaceId" type="string" required>
  Your workspace domain
</ParamField>

<ParamField query="windowDays" type="number">
  Time window for statistics (default: 30)
</ParamField>

### Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://api.gostanna.com/api/metrics/email-stats?workspaceId=yourcompany.com&windowDays=30" \
    -H "Authorization: Bearer sk-your-api-key-here"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.gostanna.com/api/metrics/email-stats?workspaceId=yourcompany.com&windowDays=30', {
    headers: {
      'Authorization': 'Bearer sk-your-api-key-here'
    }
  });

  const emailStats = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.gostanna.com/api/metrics/email-stats',
      params={
          'workspaceId': 'yourcompany.com',
          'windowDays': 30
      },
      headers={'Authorization': 'Bearer sk-your-api-key-here'}
  )

  email_stats = response.json()
  ```
</CodeGroup>

### Response

```json theme={null}
{
  "avgOpenRate": 0.68,
  "avgResponseRate": 0.42,
  "totalEmailsSent": 1250,
  "totalEmailsReceived": 980,
  "topEngaged": [
    {
      "clientId": "client_123",
      "name": "Engaged Corp",
      "openRate": 0.95,
      "responseRate": 0.78,
      "emailCount": 45
    }
  ],
  "leastEngaged": [
    {
      "clientId": "client_456",
      "name": "Silent Co",
      "openRate": 0.12,
      "responseRate": 0.05,
      "emailCount": 20
    }
  ],
  "totalClients": 125
}
```
