Statistics API
Rationale
We have created a separate service for statistics about your Kindly chatbots. This service is named Sage and lives at sage.kindly.ai. The statistics you can view in the Kindly platform are provided by Sage. The same API that the platform uses is available for you to collect statistics for your own purposes.
Sage has it's own database which contains only non-personal data. When end users chat with chatbots their messages are stored and processed in Kindly's database, and these can be manually or automatically deleted after some time to protect the end user's privacy. The data in Sage's database will not be deleted, but this data doesn't contain the user's message or any personal metadata, only an indication that someone messaged the bot at some specific time. This way we can keep aggregated statistics such as the number of chats per day, while also allowing the end user to have their privacy protected.

If you have the required permissions, you can create a permanent API key in the platform. This long-lived key can be used by a programmatic service you create to obtain short-lived JWTs which can then be used for statistics requests.
Send API key to api.kindly.ai to receive JWT:
Send a request to sage.kindly.ai to test your new token
About timezones
All time values in the database are stored as UTC. If you want results in your local timezone, which takes into consideration daylight saving time and other irregularities, you can provide a tz argument to your API request with the tzdb name of the timezone you want:
GET https://sage.kindly.ai/api/...&tz=Europe/Oslo
⚠ Timezone gotchas
The timezone parameter is important to consider if you are making a request where the data is aggregated by day. If someone messages the bot at 9 p.m. (summer time) on Monday in California, this is stored in the database as occurring at 4 a.m. on Tuesday. To get the API results scoped for California time, you would send a request with tz=America/Los_Angeles.
About granularity
Some aggregations can use a granularity parameter, for example the aggregation that counts the number of messages per hour, day or week. You can specify this with granularity=hour, etc. These default to granularity=day if not otherwise specified. Note that hour granularity is only allowed if the time between from and to is one week or less.
About sources and languages
The events that are aggregated by Sage are labeled by which source and language the user and bot were chatting with. Your API requests can be filtered by these values. Not adding any filters to your request will include all data in the results, unfiltered.
Sources
Sources are the different locations where your bot may be deployed. For example:
- test is source value for conversations by bot builders within the Kindly platform.
- web is the source value for Kindly Chat deployed on web sites, excluding the Kindly platform.
- app is the source value for chats via the Application API.
If you do not filter by sources, all data will be included in the results, including test data. To select only specific sources, you can send one or more filters like this:
GET https://sage.kindly.ai/api/...&sources[]=web&sources[]=app
You can also select sources to exclude, by prefixing with a minus sign. This means that the API will return data from every source except the ones listed. GET https://sage.kindly.ai/api/...&sources[]=-test
Language codes
The language used to chat between the user and the bot is represented by a two-letter language code. If your bot does not use multiple languages, you can safely ignore this parameter.
If you have multiple languages in your bot and you want to filter by language, you can send one or more filters like this:
GET https://sage.kindly.ai/api/...&language_code[]=en&language_code[]=nb
Statistics APIs
Filtering options
Most of the APIs can be filtered by time, language and source. To see what your options are for these filters, you can send a request to the /meta/options API.
Example request
Response
Chat sessions
Number of chats where users engaged with the bot
Required parameters
- from (YYYY-MM-DD)
- to (YYYY-MM-DD)
Optional parameters
- tz (default: UTC)
- granularity (default: day)
- sources[]
- language_codes[]
Example request
Response
User messages
Number of messages from users
Required parameters
- from (YYYY-MM-DD)
- to (YYYY-MM-DD)
Optional parameters
- tz (default: UTC)
- granularity (default: day)
- sources[]
- language_codes[]
Example request
Response
Fallback rate time series
Number of and fraction of bot replies that are fallbacks, as an aggregated time series.
Required parameters
- from (YYYY-MM-DD)
- to (YYYY-MM-DD)
Optional parameters
- tz (default: UTC)
- granularity (default: day)
- sources[]
- language_codes[]
Example request
Response
count represents the number of fallback messages in the given time interval, rate represents which fraction of the total number of bot replies in the time interval are fallbacks.
Fallback rate total
Number of and fraction of bot replies that are fallbacks, as a total aggregate for the selected time interval.
Required parameters
- from (YYYY-MM-DD)
- to (YYYY-MM-DD)
Optional parameters
- tz (default: UTC)
- sources[]
- language_codes[]
Example request
Response
count represents the number of fallback messages in the given time interval, rate represents which fraction of the total number of bot replies in the time interval are fallbacks.
Web client / Kindly Chat pages
Lists most frequent web pages where interactions with the bot has happened. Returns top 3 pages by default, use limit parameter to request more results.
Required parameters
- from (YYYY-MM-DD)
- to (YYYY-MM-DD)
Optional parameters
- tz (default: UTC)
- sources[]
- language_codes[]
- limit (default: 3)
Example request
Response
Number of handovers, time series
The number of handover requests (while open), requests while closed, started handovers and ended handovers in the requested time period, as a time series.
Required parameters
- from (YYYY-MM-DD)
- to (YYYY-MM-DD)
Optional parameters
- tz (default: UTC)
- granularity (default: day)
- sources[]
- language_codes[]
Example request
Response
Number of handovers, total
The total number of handover requests (while open), requests while closed, started handovers and ended handovers in the requested time period.
Required parameters
- from (YYYY-MM-DD)
- to (YYYY-MM-DD)
Optional parameters
- tz (default: UTC)
- sources[]
- language_codes[]
Example request
Response
Aggregated chatbubble feedback
If you have enabled the feedback feature in Kindly Chat you can get a summary of the ratings given by users in the period. The API considers the ratings as numbers, with 1 being the lowest rating. Both the count of the number of ratings and the ratio out of the total number of ratings is given.
This API only returns aggregated data. If you want to analyze the feedback texts users have given you can get these from an inbox backup. See also: Inbox backup to S3 bucket.
Required parameters
- from (YYYY-MM-DD)
- to (YYYY-MM-DD)
Optional parameters
- tz (default: UTC)
- sources[]
- language_codes[]
Example request
Response
Button clicks
An ordered list of the buttons most clicked by users chatting with the bot, and the dialogue to which each button belongs. Has both a count of the number of occurrences, and a ratio out of the total amount of button clicks for the period. Returns top 5 results by default, use the limit parameter to request more data.
Required parameters
- from (YYYY-MM-DD)
- to (YYYY-MM-DD)
Optional parameters
- tz (default: UTC)
- sources[]
- language_codes[]
- limit (default: 5)
Example request
Response
Labels
The most frequent labels added to chats. Returns top 5 labels by default, use limit parameter to request more data.
Required parameters
- from (YYYY-MM-DD)
- to (YYYY-MM-DD)
Optional parameters
- tz (default: UTC)
- sources[]
- language_codes[]
- limit (default: 5)
Example request
Response
Code example in python
This example requires Python 3.6 or higher (uses f-strings) and the package requests.
You will need to provide two values yourself, the relevant bot ID and an API key with "read statistics" permissions that you have created at https://app.kindly.ai/bot/BOT_ID/connect/api-keys. The code exchanges the API key for a JWT, uses the JWT to get data about the number of messages per day for the bot's lifetime, then renders the data as a Unicode box-character bar chart.