View in-app message stats
curl --request GET \
--url https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats \
--header 'Authorization: <authorization>'const options = {method: 'GET', headers: {Authorization: '<authorization>'}};
fetch('https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats"
headers = {"Authorization": "<authorization>"}
response = requests.get(url, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_bodyHttpResponse<String> response = Unirest.get("https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats")
.header("Authorization", "<authorization>")
.asString();using RestSharp;
var options = new RestClientOptions("https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "<authorization>");
var response = await client.GetAsync(request);
Console.WriteLine("{0}", response.Content);
false{
"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
}
]
}
}{
"success": false,
"errors": [
"Invalid click_type 'distinct'. Must be one of: all, first"
]
}{
"errors": [
"Access denied. Please include an 'Authorization: ...' header with a valid API key (https://documentation.onesignal.com/docs/en/keys-and-ids#api-keys)."
]
}{
"success": false,
"errors": [
"In-App Message not found"
]
}{
"errors": [
"API rate limit exceeded"
],
"limit": "API Per App"
}{
"success": false,
"errors": [
"Stats are temporarily unavailable"
]
}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.
GET
/
apps
/
{app_id}
/
in_app_messages
/
{id}
/
stats
View in-app message stats
curl --request GET \
--url https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats \
--header 'Authorization: <authorization>'const options = {method: 'GET', headers: {Authorization: '<authorization>'}};
fetch('https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats"
headers = {"Authorization": "<authorization>"}
response = requests.get(url, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "<authorization>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<authorization>'
response = http.request(request)
puts response.read_bodyHttpResponse<String> response = Unirest.get("https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats")
.header("Authorization", "<authorization>")
.asString();using RestSharp;
var options = new RestClientOptions("https://api.onesignal.com/apps/{app_id}/in_app_messages/{id}/stats");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "<authorization>");
var response = await client.GetAsync(request);
Console.WriteLine("{0}", response.Content);
false{
"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
}
]
}
}{
"success": false,
"errors": [
"Invalid click_type 'distinct'. Must be one of: all, first"
]
}{
"errors": [
"Access denied. Please include an 'Authorization: ...' header with a valid API key (https://documentation.onesignal.com/docs/en/keys-and-ids#api-keys)."
]
}{
"success": false,
"errors": [
"In-App Message not found"
]
}{
"errors": [
"API rate limit exceeded"
],
"limit": "API Per App"
}{
"success": false,
"errors": [
"Stats are temporarily unavailable"
]
}Overview
Retrieve impression and click totals for an in-app message by its UUID. Withoutgroup_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 in the dashboard for a timeseries view.
How to use this API
Authenticate with your App API Key. Find an in-app message’sid from the View in-app messages API.
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-labelvalue. See the in-app message JavaScript API.
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. |
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.firstcounts 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’sclicksis then the number of times one of its elements was the first thing clicked.
Response
A successful request returns200 OK. payload.stats is an array with one row per group. This example is a carousel grouped by page and clickable element:
{
"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. |
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.element_name.
Totals for the whole in-app message
Withoutgroup_by, stats holds exactly one row with no group fields:
{
"success": true,
"payload": {
"stats": [
{ "impressions": 620, "clicks": 351 }
]
}
}
impressionsis the number of times the in-app message was displayed. A carousel counts once per display, not once per page viewed.clicksadds up every clickable element, including elements and pages since removed from the in-app message.- With
click_type=first,clickscounts only the first click on the in-app message. A user who clicks two different elements adds one click, not two.
Headers
Your App API key with prefix Key. See Keys & IDs.
Path Parameters
Your OneSignal App ID in UUID v4 format. See Keys & IDs.
Query Parameters
Was this page helpful?