> ## Documentation Index
> Fetch the complete documentation index at: https://documentation.onesignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# View in-app message stats

> Retrieve all-time impression and click totals for an in-app message, for the whole in-app message or grouped by page and clickable element.

## Overview

Retrieve impression and click totals for an [in-app message](https://documentation.onesignal.com/docs/en/in-app-messages-setup.md) by its UUID. Without `group_by`, the response is one row of totals for the whole in-app message. With `group_by`, the response is one row per page, per clickable element, or per combination of the two.

All totals are all-time. This endpoint has no date range or granularity option, and it does not split totals by language or device type. Use the [in-app message report](https://documentation.onesignal.com/docs/en/in-app-message-reports.md) in the dashboard for a timeseries view.

***

## How to use this API

Authenticate with your [App API Key](https://documentation.onesignal.com/docs/en/keys-and-ids.md). Find an in-app message's `id` from the [View in-app messages](https://documentation.onesignal.com/reference/view-in-app-messages.md) API.

```http theme={null}
GET /apps/{app_id}/in_app_messages/{id}/stats?group_by=page_name,element_name&click_type=first
```

### Group the totals

`group_by` accepts `page_name`, `element_name`, or both. Send the values comma-separated (`group_by=page_name,element_name`) or as a repeated parameter (`group_by[]=page_name&group_by[]=element_name`).

* A page is one card of a carousel and only applies to carousel in-app messages created in the dashboard. A custom HTML in-app message has a single page.
* A clickable element of a custom HTML in-app message is named by its `data-onesignal-unique-label` value. See the [in-app message JavaScript API](https://documentation.onesignal.com/docs/en/in-app-message-api.md).

### Filter the rows

| Parameter | Description |
| - | - |
| `page_names` | Optional. Only include these pages. Requires `page_name` in `group_by`. |
| `element_names` | Optional. Only include these clickable elements. Requires `element_name` in `group_by`. |
| `show_deleted_pages` | Optional. Set to `true` to include pages removed from the in-app message. No effect without `group_by`. |
| `show_deleted_elements` | Optional. Set to `true` to include clickable elements removed from the in-app message. No effect without `group_by`. |

A filter must be paired with its dimension in `group_by`. For example, `group_by=element_name&element_names=cta-button` reports one element, and `group_by=page_name&element_names=cta-button` is rejected with a `400`.

Filter values are split on commas. A page or element whose name contains a comma cannot be named in a filter. Omit the filter and select its row from the response instead.

### Choose which clicks to count

`click_type` sets what the `clicks` field counts.

* `all` (default) counts every click.
* `first` counts only the first click a user makes on the in-app message. Later clicks are not counted, whether on the same element or a different one. A row's `clicks` is then the number of times one of its elements was the first thing clicked.

## Response

A successful request returns `200 OK`. `payload.stats` is an array with one row per group. This example is a carousel grouped by page and clickable element:

```json theme={null}
{
  "success": true,
  "payload": {
    "stats": [
      { "page_name": "Card 1", "element_name": "cta-button", "impressions": 500, "clicks": 42 },
      { "page_name": "Card 1", "element_name": "dismiss", "impressions": 500, "clicks": 300 },
      { "page_name": "Card 2", "element_name": "cta-button", "impressions": 120, "clicks": 9 }
    ]
  }
}
```

| Field | Type | Description |
| - | - | - |
| `page_name` | string | Present when `page_name` is in `group_by`. |
| `element_name` | string | Present when `element_name` is in `group_by`. |
| `impressions` | integer | Impressions of the in-app message, or for a carousel, of the pages the row covers. |
| `clicks` | integer | Clicks on the row's elements, counted per `click_type`. |

> [!WARNING]
>
> Impressions are never counted per element. For a carousel they are counted per page, so every element row on the same page repeats that page's impressions. For every other in-app message, including every custom HTML in-app message, they are counted once for the whole in-app message, so every row repeats the same number. Do not add `impressions` across rows. `clicks` can be added across rows.

An in-app message with no clickable elements returns no rows when grouped by `element_name`.

### Totals for the whole in-app message

Without `group_by`, `stats` holds exactly one row with no group fields:

```json theme={null}
{
  "success": true,
  "payload": {
    "stats": [
      { "impressions": 620, "clicks": 351 }
    ]
  }
}
```

* `impressions` is the number of times the in-app message was displayed. A carousel counts once per display, not once per page viewed.
* `clicks` adds up every clickable element, including elements and pages since removed from the in-app message.
* With `click_type=first`, `clicks` counts only the first click on the in-app message. A user who clicks two different elements adds one click, not two.


## OpenAPI

````yaml GET /apps/{app_id}/in_app_messages/{id}/stats
openapi: 3.1.0
info:
  title: api.onesignal.com
  version: '11.6'
servers:
  - url: https://api.onesignal.com
security:
  - {}
paths:
  /apps/{app_id}/in_app_messages/{id}/stats:
    get:
      summary: View in-app message stats
      description: >-
        Retrieve all-time impression and click totals for an in-app message.
        Without `group_by` the response is one row for the whole in-app message.
        With `group_by` it is one row per page, per clickable element, or per
        combination of the two.
      operationId: view-in-app-message-stats
      parameters:
        - name: app_id
          in: path
          description: >-
            Your OneSignal App ID in UUID v4 format. See [Keys &
            IDs](/docs/en/keys-and-ids).
          schema:
            type: string
            default: YOUR_APP_ID
          required: true
        - name: id
          in: path
          description: UUID of the in-app message to retrieve stats for.
          required: true
          schema:
            type: string
            default: YOUR_IN_APP_MESSAGE_ID
        - name: Authorization
          in: header
          description: >-
            Your App API key with prefix `Key `. See [Keys &
            IDs](/docs/en/keys-and-ids).
          required: true
          schema:
            type: string
            default: Key YOUR_APP_API_KEY
        - name: group_by
          in: query
          style: form
          explode: false
          description: >-
            Dimensions each row is grouped by: `page_name`, `element_name`, or
            both, comma-separated. Omit for a single row of totals for the whole
            in-app message.
          schema:
            type: array
            items:
              type: string
              enum:
                - page_name
                - element_name
        - name: click_type
          in: query
          description: >-
            Which clicks the `clicks` field counts. `all` counts every click.
            `first` counts only the first click a user makes on the in-app
            message. Later clicks on any element are not counted.
          schema:
            type: string
            enum:
              - all
              - first
            default: all
        - name: page_names
          in: query
          style: form
          explode: false
          description: >-
            Only include these pages, comma-separated. Requires `page_name` in
            `group_by`.
          schema:
            type: array
            items:
              type: string
        - name: element_names
          in: query
          style: form
          explode: false
          description: >-
            Only include these clickable elements, comma-separated. For custom
            HTML in-app messages, element names are the
            `data-onesignal-unique-label` values. Requires `element_name` in
            `group_by`.
          schema:
            type: array
            items:
              type: string
        - name: show_deleted_pages
          in: query
          description: >-
            Include pages that have been removed from the in-app message. No
            effect without `group_by`.
          schema:
            type: boolean
            default: false
        - name: show_deleted_elements
          in: query
          description: >-
            Include clickable elements that have been removed from the in-app
            message. No effect without `group_by`.
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: '200'
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    description: '`true` when the request succeeded.'
                  payload:
                    type: object
                    properties:
                      stats:
                        type: array
                        description: >-
                          One row per group. Exactly one row when `group_by` is
                          omitted.
                        items:
                          type: object
                          properties:
                            page_name:
                              type: string
                              description: Present when `page_name` is in `group_by`.
                            element_name:
                              type: string
                              description: Present when `element_name` is in `group_by`.
                            impressions:
                              type: integer
                              description: >-
                                Impressions of the in-app message, or for a
                                carousel, of the pages the row covers.
                            clicks:
                              type: integer
                              description: >-
                                Clicks on the row's elements, counted per
                                `click_type`.
              example:
                success: true
                payload:
                  stats:
                    - page_name: Card 1
                      element_name: cta-button
                      impressions: 500
                      clicks: 42
                    - page_name: Card 1
                      element_name: dismiss
                      impressions: 500
                      clicks: 300
                    - page_name: Card 2
                      element_name: cta-button
                      impressions: 120
                      clicks: 9
        '400':
          description: The request is invalid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InAppMessageErrorResponse'
              example:
                success: false
                errors:
                  - 'Invalid click_type ''distinct''. Must be one of: all, first'
        '401':
          description: >-
            The API key is missing or invalid, or belongs to another app or
            organization. This body has no `success` key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BasicErrorResponse'
              example:
                errors:
                  - >-
                    Access denied.  Please include an 'Authorization: ...'
                    header with a valid API key
                    (https://documentation.onesignal.com/docs/en/keys-and-ids#api-keys).
        '404':
          description: No in-app message with that `id` exists for this app.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InAppMessageErrorResponse'
              example:
                success: false
                errors:
                  - In-App Message not found
        '429':
          description: >-
            Rate limit exceeded. Requests to this path are blocked for 60
            seconds. This body has no `success` key.
          content:
            application/json:
              schema:
                type: object
                properties:
                  errors:
                    type: array
                    items:
                      type: string
                  limit:
                    type: string
                    description: Name of the rate limit that was exceeded.
              example:
                errors:
                  - API rate limit exceeded
                limit: API Per App
        '500':
          description: The totals could not be read. Retry later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InAppMessageErrorResponse'
              example:
                success: false
                errors:
                  - Stats are temporarily unavailable
components:
  schemas:
    InAppMessageErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          description: Always `false`.
        errors:
          type: array
          items:
            type: string
          description: >-
            Every problem found with the request. Field-level errors start with
            the quoted field name, for example `'name' Message name required`.
    BasicErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            type: string
          description: One or more human-readable error messages.
        success:
          type: boolean
          description: >-
            Present (and `false`) on some endpoints (notifications, templates,
            segments). Not emitted by every endpoint.
        reference:
          type: array
          items:
            type: string
          description: >-
            Documentation URL fragments related to the error. Only emitted by
            the API-key auth error helpers.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.