# Get recommendation campaign statistics

- Operation ID: `GetCampaignStats`
- HTTP method: `GET`
- Path: `/recommendations/v2/campaigns/{campaignId}/stats`
- [Human-readable API reference](https://hub.synerise.com/api-reference/ai-suite#operation/GetCampaignStats)

## 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/{campaignId}/stats:
    get:
      summary: Get recommendation campaign statistics
      description: |
        Retrieves the statistics of a single recommendation campaign.

        ---

        **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: GetCampaignStats
      tags:
        - Recommendation statistics
      security:
        - JWT: []
        - TrackerKey: []
      parameters:
        - name: campaignId
          in: path
          required: true
          description: ID of the recommendation campaign
          schema:
            type: string
            example: 50NCGoRK0VRb
        - name: from
          in: query
          required: false
          description: |
            Upper 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.
          schema:
            type: string
            format: date
        - name: to
          in: query
          required: false
          description: |
            Lower bound of the interval for which the statistics will be retrieved.
            If not specified, the interval is last 7 days.
          schema:
            type: string
            format: date
        - name: timeZone
          in: query
          required: false
          description: Time zone identifier.
          schema:
            type: string
            default: UTC
          example: Europe/Warsaw
      responses:
        "200":
          description: Statistics returned
          content:
            application/json:
              schema:
                type: object
                description: |
                  Response envelope for `GetCampaignsGlobalStats` and `GetCampaignStats`.
                  The `data` field carries aggregated campaign statistics: an overall
                  summary plus a per-day breakdown.
                required:
                  - data
                properties:
                  data:
                    type: object
                    description: Recommendation campaigns statistics 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.
                      byDate:
                        type: array
                        description: Results for individual days.
                        items:
                          type: object
                          description: Recommendation campaigns stats for a single date.
                          properties:
                            date:
                              type: string
                              description: The date.
                              format: date
                            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/GetCampaignStats
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request GET \
              --url 'https://api.synerise.com/recommendations/v2/campaigns/50NCGoRK0VRb/stats?from=SOME_STRING_VALUE&to=SOME_STRING_VALUE&timeZone=Europe%2FWarsaw' \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN'
        - lang: Python
          label: Python
          source: |-
            import http.client

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

            headers = { 'Authorization': "Bearer REPLACE_BEARER_TOKEN" }

            conn.request("GET", "/recommendations/v2/campaigns/50NCGoRK0VRb/stats?from=SOME_STRING_VALUE&to=SOME_STRING_VALUE&timeZone=Europe%2FWarsaw", headers=headers)

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

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = null;

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

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

            xhr.open("GET", "https://api.synerise.com/recommendations/v2/campaigns/50NCGoRK0VRb/stats?from=SOME_STRING_VALUE&to=SOME_STRING_VALUE&timeZone=Europe%2FWarsaw");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");

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

            const options = {
              "method": "GET",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/recommendations/v2/campaigns/50NCGoRK0VRb/stats?from=SOME_STRING_VALUE&to=SOME_STRING_VALUE&timeZone=Europe%2FWarsaw",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN"
              }
            };

            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.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

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

            $request->setQueryData([
              'from' => 'SOME_STRING_VALUE',
              'to' => 'SOME_STRING_VALUE',
              'timeZone' => 'Europe/Warsaw'
            ]);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN'
            ]);

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

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.get("https://api.synerise.com/recommendations/v2/campaigns/50NCGoRK0VRb/stats?from=SOME_STRING_VALUE&to=SOME_STRING_VALUE&timeZone=Europe%2FWarsaw")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .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.
```
