# 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/campaigns#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.5
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: []
        - BasicAuth: []
      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: Basic REPLACE_BASIC_AUTH'
        - lang: Python
          label: Python
          source: |-
            import http.client

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

            headers = { 'Authorization': "Basic REPLACE_BASIC_AUTH" }

            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", "Basic REPLACE_BASIC_AUTH");

            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": "Basic REPLACE_BASIC_AUTH"
              }
            };

            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' => 'Basic REPLACE_BASIC_AUTH'
            ]);

            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", "Basic REPLACE_BASIC_AUTH")
              .asString();
servers:
  - url: https://api.synerise.com
    description: Microsoft Azure EU
  - url: https://api.azu.synerise.com
    description: Microsoft Azure USA
  - url: https://api.geb.synerise.com
    description: Google Cloud Platform
tags:
  - name: Recommendation statistics
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |
        Synerise uses [JSON Web Token (JWT)](https://jwt.io/) as the authorization method.

        The token is generated by the *auth/login* endpoints.

        You need to include it in the `Authorization` header of your requests, with a `Bearer` prefix.


        By default, the token is valid for **one week** (see [workspace settings](https://hub.synerise.com/docs/settings/tool/iam-for-apps/general/#jwt-lifetime)).  
        You can request a refreshed key for the session by using the *auth/refresh* endpoint **before** the current token expires.


        You can verify your JWT signature by using the [public key](https://api.synerise.com/v4/public.pem).


        See Developer Guides on JWT API authentication for:
        - [profiles](https://hub.synerise.com/developers/api/api-authorization/client-login/);
        - [workspaces](https://hub.synerise.com/developers/api/api-authorization/workspace-login/#api-authentication-with-jwt);
        - [users](https://hub.synerise.com/developers/api/api-authorization/user-login/).
    TrackerKey:
      type: apiKey
      in: query
      name: token
      description: |
        Authentication by tracker key sent in a `token` query parameter. This can be the same key as used in the tracking code of the website. For details, see:

        - [Creating tracking codes](https://hub.synerise.com/developers/web/installation-and-configuration/#creating-a-tracking-code)
        - [Authenticating API requests with the tracker key](https://hub.synerise.com/developers/api/api-authorization/client-login/#tracker-key-authentication)
    BasicAuth:
      type: http
      scheme: basic
      description: |
        Basic authentication with login (workspace GUID) and password (workspace API key) encoded with Base64 and sent in the `Authorization` header. **Must be enabled in the settings of the API key**.

        <span style="color:red">This is less secure than JWTs.</span> Limit the API key permissions to only those that you need. Consider API key rotation and other security measures.

        You can still use JWTs from the same API key when basic authentication is enabled.

        For details, see ["Workspace authentication"](https://hub.synerise.com/jwt-or-basic/#basic-api-authentication-with-api-keys).
```
