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

# Get Analytics with Comparison

> Get analytics data with period-over-period comparison

# Get Analytics with Comparison

Returns comprehensive analytics data along with comparisons to the previous period of the same length.

<Note>This endpoint is only accessible to users with `manager` or `admin` roles.</Note>

## Request

<ParamField header="Authorization" type="string" required>
  Bearer token from authentication
</ParamField>

<ParamField query="timeRange" type="string" default="30d">
  Time range for analytics. Options: `7d`, `30d`, `90d`

  The comparison is made against the previous period of the same length. For example, `30d` compares the last 30 days to the 30 days before that.
</ParamField>

## Response

The response includes all fields from the [base analytics endpoint](/api-reference/analytics/overview), plus a `comparisons` object.

### Comparison Object

Each comparison contains:

<ResponseField name="comparisons.*.current" type="number">
  Current period value
</ResponseField>

<ResponseField name="comparisons.*.previous" type="number">
  Previous period value
</ResponseField>

<ResponseField name="comparisons.*.change" type="number">
  Absolute change (current - previous)
</ResponseField>

<ResponseField name="comparisons.*.changePercent" type="number">
  Percentage change from previous period
</ResponseField>

<ResponseField name="comparisons.*.trend" type="string">
  Trend indicator: `up`, `down`, or `stable`

  * `up`: changePercent > 5%
  * `down`: changePercent \< -5%
  * `stable`: -5% to +5%
</ResponseField>

### Available Comparisons

| Field            | Description                |
| ---------------- | -------------------------- |
| `tasksCreated`   | Total tasks created        |
| `tasksCompleted` | Total tasks completed      |
| `completionRate` | Task completion percentage |
| `moodAverage`    | Average mood score         |
| `activeUsers`    | Number of active users     |
| `flagsCreated`   | Total flags raised         |

<RequestExample>
  ```bash theme={null}
  curl -X GET "https://api.hitler.app/analytics/comparison?timeRange=30d" \
    -H "Authorization: Bearer YOUR_TOKEN"
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "taskMetrics": {
      "totalCreated": 245,
      "totalCompleted": 198,
      "completionRate": 81,
      "avgCompletionTime": 24,
      "overdueCount": 12
    },
    "moodMetrics": {
      "averageScore": 3.7,
      "totalResponses": 156,
      "trend": "up",
      "distribution": [...]
    },
    "teamMetrics": {
      "activeUsers": 18,
      "totalUsers": 24,
      "topPerformers": [...]
    },
    "flagMetrics": {
      "total": 15,
      "bySeverity": [...],
      "resolved": 11,
      "pending": 4
    },
    "comparisons": {
      "tasksCreated": {
        "current": 245,
        "previous": 210,
        "change": 35,
        "changePercent": 17,
        "trend": "up"
      },
      "tasksCompleted": {
        "current": 198,
        "previous": 175,
        "change": 23,
        "changePercent": 13,
        "trend": "up"
      },
      "completionRate": {
        "current": 81,
        "previous": 83,
        "change": -2,
        "changePercent": -2,
        "trend": "stable"
      },
      "moodAverage": {
        "current": 3.7,
        "previous": 3.4,
        "change": 0.3,
        "changePercent": 9,
        "trend": "up"
      },
      "activeUsers": {
        "current": 18,
        "previous": 16,
        "change": 2,
        "changePercent": 13,
        "trend": "up"
      },
      "flagsCreated": {
        "current": 15,
        "previous": 22,
        "change": -7,
        "changePercent": -32,
        "trend": "down"
      }
    }
  }
  ```
</ResponseExample>
