Metric Report
The Metric Report query gives you an easy way to build reports based on one or many Metrics grouped by a common dimension. For example, a report that shows the revenue and volume for the top products. The revenue and volume would be the Metrics, and the product name would be the dimension.
Metric Reports can be visualized as tables. They have sortable columns and built-in pagination that make their implementation quick and simple.
Prerequisites:
At least one Metric with at least one dimension is required in order to return a Metric Report.
Usage
Any time you need to show tabular data with multiple Metrics broken down by dimension and sorted, consider using Metric Report. Along with time series, Metric Reports can provide significant insight when included in in-product analytics. Metric Reports are typically rendered as tables.
Arguments
You will pass a MetricReportInput
when querying. The most important
arguments when querying a metric report are
- The
timeRange
to query over. - The
dimensions
to break down by. - The
metrics
you wish to display. orderByColumn
- which column, specified by number starting at 1 inclusive of dimensions and metrics you wish to order by.first
refers to the number of rows to return.
Read more about MetricReportInput
.
Returns
The query returns an array of headers
and an array of rows
inside a
MetricReportConnection
:
- The
headers
array is an array of header names for the report table: the first header names correspond to the dimensions you passed to thedimensions
argument when querying the report; the final header name is always "value". - The
rows
array is an array of rows for the metric report table. Each row is itself an array of columns. The column order matches theheaders
order.
The final column of each row is a number wrapped in a string. Using a string ensures we can support values greater than 32-bits in the GraphQL API.
Read more about MetricReportConnection
.
Example
In the below query, we are grouping by Channel and then Product Name and then returning Sales and Sales Volume metrics for each row. We have a filter on the Sales Volume metric ensuring we are only seeing "DIRECT" channel results. OrderByColumn:3
means we are ordering by the Sales metric, and first
means we are retrieving the first 5 rows.
- GraphQL Query
- JSON Response
query {
metricReport(
input: {
timeRange: { start: "2022-01-01T00:00:00Z", stop: "2023-02-01T00:00:00Z" }
dimensions: [
{ columnName: "CHANNEL", displayName: "Channel" }
{ columnName: "PRODUCT_NAME", displayName: "Product Name" }
]
metrics: [
{ id: "METxxx", displayName: "Sales", sort: ASC }
{
id: "METxxx"
displayName: "Sales Volume"
filters: [{ column: "CHANNEL", operator: EQUALS, value: "DIRECT" }]
}
]
orderByColumn: 3
first: 5
}
) {
headers
rows
query {
durationInMilliseconds
recordsProcessed
bytesProcessed
}
pageInfo {
startCursor
endCursor
hasNextPage
hasPreviousPage
}
}
}
{
"data": {
"metricReport": {
"headers": ["Channel", "Product Name", "Sales", "Sales Volume"],
"rows": [
[
"DIRECT",
"CUBS 100 12/15/2016 - by Dan Campana (Paperback)",
"0",
"660153"
],
["DIRECT", "Elf Pets: An Arctic Fox Tradition", "0", "660153"],
[
"DIRECT",
"Lieutenant's Nurse - by Sara Ackerman (Paperback)",
"0",
"660153"
],
[
"DIRECT",
"Ready for Romance (Paperback) by Debbie Macomber",
"0",
"660153"
],
[
"DIRECT",
"The Langoliers - by Stephen King (Paperback)",
"0",
"660153"
]
],
"query": {
"durationInMilliseconds": 4035,
"recordsProcessed": "3978256",
"bytesProcessed": "289865756"
},
"pageInfo": {
"startCursor": "eyJvZmZzZXQiOjB9",
"endCursor": "eyJvZmZzZXQiOjR9",
"hasNextPage": true,
"hasPreviousPage": false
}
}
}
}