# Get statistics for top items in a campaign

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

## 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}/products/stats:
    get:
      summary: Get statistics for top items in a campaign
      description: |
        Retrieves the statistics of top products for 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: GetRecoTopProductsStats
      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
        - name: metric
          in: query
          required: false
          description: |
            The response will include statistics for up to 10 top-performing items according to the selected metric, sorted from best to worst.
            If not specified, the default metric is `views`.
            - views - the number of displayed recommendation frames.
            - generations - the number of generated recommendation frames.
            - clicks - the number of times an item in a recommendation frame was clicked.
            - charges - the number of transactions caused by the recommendation.
            - revenue - the revenue generated by the recommendation.
          schema:
            type: string
            default: views
            enum:
              - views
              - clicks
              - revenue
              - generations
              - charges
      responses:
        "200":
          description: Statistics returned
          content:
            application/json:
              schema:
                type: object
                description: |
                  Response envelope for `GetRecoTopProductsStats`. The `data` field
                  carries an array of per-product statistics, one entry per product,
                  ordered by the metric selected in the request.
                required:
                  - data
                properties:
                  data:
                    type: array
                    description: Statistics of best-performing products in the campaign, ordered by the selected metric. Each item is one product's stats.
                    items:
                      type: object
                      description: Statistics for a single item.
                      properties:
                        productId:
                          type: string
                          description: Id of the item.
                        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/GetRecoTopProductsStats
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request GET \
              --url 'https://api.synerise.com/recommendations/v2/campaigns/50NCGoRK0VRb/products/stats?from=SOME_STRING_VALUE&to=SOME_STRING_VALUE&timeZone=Europe%2FWarsaw&metric=SOME_STRING_VALUE' \
              --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/products/stats?from=SOME_STRING_VALUE&to=SOME_STRING_VALUE&timeZone=Europe%2FWarsaw&metric=SOME_STRING_VALUE", 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/products/stats?from=SOME_STRING_VALUE&to=SOME_STRING_VALUE&timeZone=Europe%2FWarsaw&metric=SOME_STRING_VALUE");
            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/products/stats?from=SOME_STRING_VALUE&to=SOME_STRING_VALUE&timeZone=Europe%2FWarsaw&metric=SOME_STRING_VALUE",
              "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/products/stats');
            $request->setMethod(HTTP_METH_GET);

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

            $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/products/stats?from=SOME_STRING_VALUE&to=SOME_STRING_VALUE&timeZone=Europe%2FWarsaw&metric=SOME_STRING_VALUE")
              .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.
```
