# Analytics

Generate a custom report with full access to all metrics and dimensions.\
**Authentication**: Required (Bearer Token)\
**Role** **Required**: Admin or Publisher

#### POST /api/reportv2/

```json
{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "dimensions": ["date", "publisher"],
  "metrics": ["impression", "revenue", "ecpm"],
  "filters": [
    {
      "key": "publisher",
      "value": "123",
      "operator": "="
    }
  ],
  "order": "revenue DESC",
  "limit": "100",
  "skip": "0",
  "csv": false,
  "totals": true
}
```

#### Pagination & Sorting Parameters

| Parameter | Type   | Default | Description                                                                            |
| --------- | ------ | ------- | -------------------------------------------------------------------------------------- |
| order     | string | -       | Sort order. Format: column \[ASC\|DESC]. Examples: "date", "revenue DESC", "impression |
| limit     | string | -       | Maximum number of rows to return. Example: "100"                                       |
| skip      | string | "0"     | Number of rows to skip (for pagination). Example: "50" to get page 2 with limit 50     |

#### Pagination Example

```json
// Page 1 (first 50 results)
{
  "limit": "50",
  "skip": "0",
  "order": "date DESC"
}

// Page 2 (next 50 results)
{
  "limit": "50",
  "skip": "50",
  "order": "date DESC"
}

// Page 3
{
  "limit": "50",
  "skip": "100",
  "order": "date DESC"
}

```

***

#### Output Format Parameters

| Parameter | Type    | Default | Description                                                         |
| --------- | ------- | ------- | ------------------------------------------------------------------- |
| csv       | boolean | false   | If true, returns CSV file download instead of JSON                  |
| totals    | boolean | false   | If true, includes a totals row as the first element in the response |

#### CSV Response

When CSV: true, the response is a downloadable CSV file:

#### Request

```json
{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "dimensions": ["date"],
  "metrics": ["impression", "revenue"],
  "csv": true
}
```

#### Response Headers

```http
Content-Type: text/csv
Content-Disposition: attachment; filename="report_2024-01-01.csv"
```

#### Response Body

```csv
date,impression,revenue
2024-01-01,50000,150.50
2024-01-02,48000,144.00
2024-01-03,52000,156.00
```

***

#### Totals Response

When **totals**: true, the first row contains aggregated totals across all data

#### Request

```json
{
  "startDate": "2024-01-01",
  "endDate": "2024-01-03",
  "dimensions": ["date"],
  "metrics": ["impression", "revenue"],
  "totals": true
}
```

#### Response

```json
[
  {
    "date": "Total",
    "impression": 150000,
    "revenue": 450.50
  },
  {
    "date": "2024-01-01",
    "impression": 50000,
    "revenue": 150.50
  },
  {
    "date": "2024-01-02",
    "impression": 48000,
    "revenue": 144.00
  },
  {
    "date": "2024-01-03",
    "impression": 52000,
    "revenue": 156.00
  }
]
```

***

#### Complete Request Example

```json
{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "dimensions": ["date", "country"],
  "metrics": ["impression", "revenue", "ecpm", "fillrate"],
  "filters": [
    {
      "key": "publisher",
      "value": "123",
      "operator": "="
    },
    {
      "key": "country",
      "values": ["US", "CA", "GB"],
      "operator": "IN"
    }
  ],
  "order": "revenue DESC",
  "limit": "100",
  "skip": "0",
  "csv": false,
  "totals": true
}
```

#### Response

```json
[
  {
    "date": "Total",
    "country": "",
    "impression": 500000,
    "revenue": 1500.00,
    "ecpm": 3.00,
    "fillrate": 75.5
  },
  {
    "date": "2024-01-15",
    "country": "US",
    "impression": 25000,
    "revenue": 87.50,
    "ecpm": 3.50,
    "fillrate": 82.3
  },
  {
    "date": "2024-01-14",
    "country": "US",
    "impression": 24000,
    "revenue": 84.00,
    "ecpm": 3.50,
    "fillrate": 80.1
  }
]
```

***

### Parameter Summary Table

<table><thead><tr><th valign="top">Parameter</th><th> Type</th><th data-type="checkbox">Required</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td valign="top">startDate</td><td>string</td><td>true</td><td>-</td><td>Start date (YYYY-MM-DD)</td></tr><tr><td valign="top">endDate</td><td>string</td><td>true</td><td>-</td><td>End date (YYYY-MM-DD)</td></tr><tr><td valign="top">dimensions</td><td>string[]</td><td>true</td><td>-</td><td>Grouping columns</td></tr><tr><td valign="top">metrics</td><td>string[]</td><td>true</td><td>-</td><td>Aggregation columns</td></tr><tr><td valign="top">filters</td><td>Filter[]</td><td>false</td><td>[]</td><td>Filter conditions</td></tr><tr><td valign="top">order</td><td>string</td><td>false</td><td>-</td><td>Sort column and direction</td></tr><tr><td valign="top">limit</td><td>string</td><td>false</td><td>-</td><td>Max rows to return</td></tr><tr><td valign="top">skip</td><td>string</td><td>false</td><td>"0"</td><td>Rows to skip (pagination)</td></tr><tr><td valign="top">csv</td><td>boolean</td><td>false</td><td>false</td><td>Return as CSV file</td></tr><tr><td valign="top">totals</td><td>boolean</td><td>false</td><td>false</td><td>Include totals row</td></tr></tbody></table>
