Using APIs for analytics
This section describes the API operations that you use to retrieve analytics for a bot.
Note
To use the ListUtteranceMetrics and ListUtteranceAnalyticsData, your IAM role must have permissions to perform the ListAggregatedUtterances operation, which provides access to utterance-related analytics. See Viewing utterance statistics from Lex V2 conversations for details and the IAM policy to apply to the IAM role.
-
The following API operations retrieve summary metrics for a bot:
-
The following API operations retrieve a list of metadata for sessions and utterances:
-
The ListIntentPaths operation retrieves metrics about an order of intents that customers take in conversations with a bot.
Filtering results
The Analytics API requests require you to specify the startTime
and
endTime
. The API returns sessions, intents, intent stages, or
utterances that began after the startTime
and
ended before the endTime
.
filters
is an optional field in the Analytics API requests. It maps
to a list of AnalyticsSessionFilter, AnalyticsIntentFilter, AnalyticsIntentStageFilter, or AnalyticsUtteranceFilter objects. In each object, use the fields to
create an expression to filter by. For example, if you add the following filter to
the list, the bot searches for conversations that are longer than 30
seconds.
{ "name": "Duration", "operator": "GT", "value": "30 sec", }
Retrieving metrics for a bot
Use the ListSessionMetrics
, ListIntentMetrics
,
ListIntentStageMetrics
, and ListUtteranceMetrics
operations to retrieve summary metrics for sessions,
intents, intent stages, and
utterances.
For these operations, fill in the following required fields:
-
Provide a
startTime
andendTime
to define a time range for which you want to retrieve results. -
Specify the metrics you want to calculate in
metrics
, a list of AnalyticsSessionMetric, AnalyticsIntentMetric, AnalyticsIntentStageMetric, or AnalyticsUtteranceMetric objects. In each object, use thename
field to specify the metric to calculate thestatistic
field to specify whether to calculate theSum
,Average
, orMax
number, and theorder
field to specify whether to sort the results inAscending
orDescending
order.Note
Both the
metrics
andbinBy
objects contain anorder
field. You can specify the sortingorder
in only one of the two objects.
The remaining fields in the request are optional. You can filter and organize the results in the following ways:
-
Filtering results – Use the
filters
field to filter the results. See Filtering results for more details. -
Grouping results by category – Specify the
groupBy
field, a list containing a single AnalyticsSessionResult, AnalyticsIntentResult, AnalyticsIntentStageResult, or AnalyticsUtteranceResult object. In the object, specify thename
field with the category by which you want to group the results.If you specify a
groupBy
field in the request, theresults
object in the response containsgroupByKeys
, a list of AnalyticsSessionGroupByKey, AnalyticsIntentGroupByKey, AnalyticsIntentStageGroupByKey, or AnalyticsUtteranceGroupByKey objects, each with thename
that you specified in the request and a member of that category in thevalue
field. -
Binning results by time – Specify the
binBy
field, a list containing a single AnalyticsBinBySpecification object. In the object, specify thename
field withConversationStartTime
to bin the results by when the conversation began orUtteranceTimestamp
to bin the results by when the utterance took place. Specify the interval of time by which you want to bin the results in theinterval
field, and whether to sort inAscending
orDescending
order of time in theorder
field.If you specify a
binBy
field in the request, theresults
object in the response containsbinKeys
, a list of AnalyticsBinKey objects, each with thename
that you specified in the request and the interval of time that defines that bin in thevalue
field.Note
Both the
metrics
andbinBy
objects contain anorder
field. You can specify the sortingorder
in only one of the two objects.
Use the following fields to handle the display of the response:
-
Specify a number between 1 and 1,000 in the
maxResults
field to limit the number of results to return in a single response. -
If the number of results is greater than the number you specify in the
maxResults
field, the response contains anextToken
. Make the request again, but use this value in thenextToken
field to return the next batch of results.
If you are using ListUtteranceMetrics
, you can specify attributes to return in the attributes
field.
This field maps to a list containing a single AnalyticsUtteranceAttribute
object. Specify LastUsedIntent
in the name
field to return the intent that Amazon Lex V2 is using at the time of the utterance.
In the response, the results
field maps to a list of AnalyticsSessionResult, AnalyticsIntentResult, AnalyticsIntentStageResult, or AnalyticsUtteranceResult objects. Each object contains a
metrics
field which returns the value of a summary statistic for a
metric that you requested, in addition to any bins or groups created from the
methods you specified.
Retrieving metadata for sessions and utterances in a bot
Use the ListSessionAnalyticsData and ListUtteranceAnalyticsData operations to retrieve metadata about individual sessions and utterances.
Fill in the required startTime
and endTime
fields to define a time range for which you want to retrieve results.
The remaining fields in the request are optional. To filter and sort results:
-
Filtering results – Use the
filters
field to filter the results. See Filtering results for more details. -
Sorting results – Sort the results with the
sortBy
field, which contains a SessionDataSortBy or UtteranceDataSortBy object. Specify the value you want to sort by in thename
field and whether to sort inAscending
orDescending
order in theorder
field.
Use the following fields to handle the display of the response:
-
Specify a number between 1 and 1,000 in the
maxResults
field to limit the number of results to return in a single response. -
If the number of results is greater than the number you specify in the
maxResults
field, the response contains anextToken
. Make the request again, but use this value in thenextToken
field to return the next batch of results.
In the response, the sessions
or utterances
field maps to a list of SessionSpecification or UtteranceSpecification objects. Each object contains metadata for a single session or utterance.
Retrieving metadata for sessions and utterances in a bot
Use the ListIntentPaths operation to retrieve metrics about an order of intents that customers take in conversation with a bot.
For this operation, fill in the following required fields:
-
Provide a
startTime
andendTime
to define a time range for which you want to retrieve results. -
Provide an
intentPath
to define an order of intents for which you want to retrieve metrics. Separate intents in the path with a forward slash. For example, populate theintentPath
field with/BookCar/BookHotel
to see details about how many times users invoked theBookCar
andBookHotel
intents in that order.
Use the optional filters
field to filter the results. For more
details, see Filtering results.
Viewing utterance statistics from Lex V2 conversations
You can use utterance statistics to determine the utterances that your users are sending to your bot. You can see both the utterances that Amazon Lex V2 successfully detects and the utterances that it doesn't. You can use this information to help tune your bot.
For example, if you find that your users are sending an utterance that Amazon Lex V2 is missing, you can add the utterance to an intent. The Draft version of the intent is updated with the new utterance and you can test it before deploying it to your bot.
An utterance is detected when Amazon Lex V2 recognizes the utterance as an
attempt to invoke an intent configured for a bot. An utterance is missed
when Amazon Lex V2 doesn't recognize the utterance and invokes the
AMAZON.FallbackIntent
instead.
Utterance statistics can be viewed using the ListUtteranceMetrics
API and the ListAggregatedUtterance
API.
Utterance statistics are not generated using ListUtteranceMetrics
API
under the following conditions:
-
The Child Online Privacy Protection Act setting was set to Yes when the bot was created with the console, or the
childDirected
field was set to true when the bot was created withe theCreateBot
operation.
The ListUtteranceMetrics
API provides additonal features including:
-
More information available, such as mapped intent for detected utterances.
-
More filtering capability (including channel and mode).
-
Longer retention date range (30 days).
-
You can use the API even if you have opted out of data storage. The console functionality for missed and detected utterances will rely on
ListUtteranceMetrics
API.
Utterance statistics are not generated using ListAggregatedUtterance
API
under the following conditions:
-
The Child Online Privacy Protection Act setting was set to Yes when the bot was created with the console, or the
childDirected
field was set to true when the bot was created withe theCreateBot
operation. -
You are using slot obfuscation with one or more slots.
-
You opted out of participating in improving Amazon Lex.
The ListAggregatedUtterance
API provides features including:
-
Less detailed information available (no mapped intent for utterances).
-
Limited filtering capability (not including channel and mode).
-
Short retention date range (15 days).
Using utterance statistics, you can see whether a specific utterance was detected or missed, alongside the last time that the utterance was used in a bot interaction.
Amazon Lex V2 stores utterances continuously while users interact with your bot. You can query the
statistics using the console or the ListAggregatedUtterances
operation. It has a
data retention of 15 days and it is not available if the user has opted out of data storage. You
can delete utterances using the DeleteUtterances
operation or by opting out of data
storage. All utterances are deleted if you close your AWS account. Stored utterances are
encrypted with a server-managed key.
When you delete a bot version, utterance statistics are available for the version for up to
30 days with ListUtteranceMetrics
, and 15 days using ListAggregatedUtterances
.
You can't see statistics for deleted version in the Amazon Lex V2 console. To see the
statistics for deleted versions, you can use both ListAggregatedUtterances
and ListUtteranceMetrics
operations.
With both the ListAggregatedUtterances
and ListUtteranceMetrics
APIs, utterances are aggregated by the text of the utterance. For example, all
instances where the customer used the phrase "I want to order a pizza" are
aggregated into the same line in a response. When you use the
RecognizeUtterance operation, the text used
is the input transcript.
To use the ListAggregatedUtterances
and ListUtteranceMetrics
APIs, apply the following policy to a
role.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ListAggregatedUtterancesPolicy", "Effect": "Allow", "Action": "lex:ListAggregatedUtterances", "Resource": "*" } ] }