# Get recommendation campaign statistics

- Operation ID: `PostCampaignsStats`
- HTTP method: `POST`
- Path: `/recommendations/v2/campaigns/stats`
- [Human-readable API reference](https://hub.synerise.com/api-reference/ai-recommendations#tag/Recommendation-statistics/operation/PostCampaignsStats)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /recommendations/v2/campaigns/stats:
    post:
      summary: Get recommendation campaign statistics
      description: |
        Retrieves the statistics of campaigns defined in the request.

        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=profileLogin" target="_blank" rel="noopener">Workspace (Business Profile)</a>, <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>

        **API key permission required:** `AI_STATS_READ`

        **User role permission required:** `campaigns_recommendations: read`
      operationId: PostCampaignsStats
      tags:
        - Recommendation statistics
      security:
        - JWT: []
        - TrackerKey: []
      requestBody:
        description: Request for recommendation campaigns stats.
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                campaignIds:
                  type: array
                  minItems: 1
                  items:
                    type: string
                  description: List of campaign IDs for which the statistics are requested. Must not be empty.
                from:
                  type: string
                  format: date
                  description: |
                    Upper bound of the interval for which the statistics will be retrieved.  
                    Must be provided with `to`, otherwise the filter is treated as unspecified.  
                    If not specified, the interval is last 7 days.
                to:
                  type: string
                  format: date
                  description: |
                    Lower bound of the interval for which the statistics will be retrieved.  
                    Must be provided with `from`, otherwise the filter is treated as unspecified.  
                    If not specified, the interval is last 7 days.
                timeZone:
                  type: string
                  description: Time zone identifier.
                  default: UTC
                  example: Europe/Warsaw
              required:
                - campaignIds
      responses:
        "200":
          description: Statistics returned
          content:
            application/json:
              schema:
                type: object
                description: |
                  Response envelope for `PostCampaignsStats`. The `data` field carries
                  aggregated statistics: an overall summary plus a per-campaign
                  breakdown for the requested campaign IDs.
                required:
                  - data
                properties:
                  data:
                    type: object
                    description: Recommendation campaigns stats payload.
                    properties:
                      summary:
                        type: object
                        description: Recommendation statistics.
                        properties:
                          views:
                            type: integer
                            description: The number of recommendation frame views.
                          revenue:
                            type: number
                            format: float
                            description: Total revenue generated by recommendations.
                          itemPurchases:
                            type: integer
                            description: The number of individual item purchases.
                          itemPurchasesPerItemClick:
                            type: number
                            format: float
                            description: Item purchases per item click ratio.
                          itemClicks:
                            type: number
                            format: integer
                            description: Number of clicks on a recommendation item.
                          transactions:
                            type: integer
                            description: The number of transactions resulting from the recommendation.
                          frameClicks:
                            type: number
                            format: integer
                            description: Number of clicks on a recommendation frame.
                          frameClicksPerGeneration:
                            type: number
                            format: float
                            description: Frame clicks per generation ratio.
                          frameClicksPerView:
                            type: number
                            format: float
                            description: Frame clicks per view ratio.
                          generations:
                            type: integer
                            description: The number of generated recommendations.
                          uniqueClients:
                            type: number
                            format: integer
                            description: Number of unique profiles which generated a recommendation.
                      byCampaign:
                        type: array
                        items:
                          type: object
                          description: Stats for a single recommendation campaign.
                          properties:
                            campaignId:
                              type: string
                              description: Id of the campaign.
                            stats:
                              type: object
                              description: Recommendation statistics.
                              properties:
                                views:
                                  type: integer
                                  description: The number of recommendation frame views.
                                revenue:
                                  type: number
                                  format: float
                                  description: Total revenue generated by recommendations.
                                itemPurchases:
                                  type: integer
                                  description: The number of individual item purchases.
                                itemPurchasesPerItemClick:
                                  type: number
                                  format: float
                                  description: Item purchases per item click ratio.
                                itemClicks:
                                  type: number
                                  format: integer
                                  description: Number of clicks on a recommendation item.
                                transactions:
                                  type: integer
                                  description: The number of transactions resulting from the recommendation.
                                frameClicks:
                                  type: number
                                  format: integer
                                  description: Number of clicks on a recommendation frame.
                                frameClicksPerGeneration:
                                  type: number
                                  format: float
                                  description: Frame clicks per generation ratio.
                                frameClicksPerView:
                                  type: number
                                  format: float
                                  description: Frame clicks per view ratio.
                                generations:
                                  type: integer
                                  description: The number of generated recommendations.
                                uniqueClients:
                                  type: number
                                  format: integer
                                  description: Number of unique profiles which generated a recommendation.
        "500":
          description: Service error
          content:
            application/json:
              schema:
                type: object
                properties:
                  httpStatus:
                    type: integer
                    example: 500
                    description: HTTP status of the error.
                  errorCode:
                    type: integer
                    description: Status code. See [error reference](https://developers.synerise.com/errors.html).
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred.
                  message:
                    type: string
                    description: Description of the problem.
                  traceId:
                    type: string
                    description: Trace ID for debugging.
                  help:
                    type: string
                    description: Currently unused.
        4xx:
          description: Incorrect request
          content:
            application/json:
              schema:
                type: object
                properties:
                  httpStatus:
                    type: integer
                    example: 500
                    description: HTTP status of the error.
                  errorCode:
                    type: integer
                    description: Status code. See [error reference](https://developers.synerise.com/errors.html).
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred.
                  message:
                    type: string
                    description: Description of the problem.
                  traceId:
                    type: string
                    description: Trace ID for debugging.
                  help:
                    type: string
                    description: Currently unused.
      x-snr-doc-urls:
        - /api-reference/ai-recommendations#tag/Recommendation-statistics/operation/PostCampaignsStats
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/recommendations/v2/campaigns/stats \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"campaignIds":["string"],"from":"2019-08-24","to":"2019-08-24","timeZone":"Europe/Warsaw"}'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            payload = "{\"campaignIds\":[\"string\"],\"from\":\"2019-08-24\",\"to\":\"2019-08-24\",\"timeZone\":\"Europe/Warsaw\"}"

            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("POST", "/recommendations/v2/campaigns/stats", payload, headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "campaignIds": [
                "string"
              ],
              "from": "2019-08-24",
              "to": "2019-08-24",
              "timeZone": "Europe/Warsaw"
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("POST", "https://api.synerise.com/recommendations/v2/campaigns/stats");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");
            xhr.setRequestHeader("content-type", "application/json");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "POST",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/recommendations/v2/campaigns/stats",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN",
                "content-type": "application/json"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.write(JSON.stringify({
              campaignIds: ['string'],
              from: '2019-08-24',
              to: '2019-08-24',
              timeZone: 'Europe/Warsaw'
            }));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/recommendations/v2/campaigns/stats');
            $request->setMethod(HTTP_METH_POST);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"campaignIds":["string"],"from":"2019-08-24","to":"2019-08-24","timeZone":"Europe/Warsaw"}');

            try {
              $response = $request->send();

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.post("https://api.synerise.com/recommendations/v2/campaigns/stats")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"campaignIds\":[\"string\"],\"from\":\"2019-08-24\",\"to\":\"2019-08-24\",\"timeZone\":\"Europe/Warsaw\"}")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Recommendation statistics
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
    TrackerKey:
      type: apiKey
      name: token
      in: query
      description: Authorization by tracker key sent as a query parameter. This is the same key as used in the website tracking code.
```
