Counter
Every Metric can be visualized as a counter. This is the simplest visualization, because it returns a single value summarizing the Metric over the requested time range. For example, a counter could represent
- The sum of sales for the quarter,
- A count of signups for the week, or
- Error occurrences in the last hour.
Any time a single number will do, consider using a counter. For more complex visualizations that return multiple values, check out time series and leaderboard.
Usage
When building customer-facing analytics, you could place a counter inline next to some text, as an icon at the start of a <button>, or you could make it extra-large in a dashboard, to grab the customer's attention:
371An example of an extra-large counter you might present in a dashboard.
Arguments
You will pass a CounterInput
when querying the counter. The most important
arguments are
- The
timeRange
to query over, and - The
filters
to use.
Returns
The query returns a single value
inside a CounterResponse
. The value
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 CounterResponse
.
Example
Imagine we have a Data Pool syncing from a table of sales data. The sales data might look like the following:
We can create a Sum Metric named "sales" which sums up the sales data. By including "Salesperson" and "Product ID" as Dimensions, we can answer questions with our Metric. Follow along for worked examples.
1. How many sales did a salesperson make?
In order to answer the question, "How many sales did a salesperson make?",
we need to query our Sum Metric and filter by the "Salesperson" Dimension. In the GraphQL
query below, we use metricByName
to get the "sales" Metric, and then we pass
a variable, $salesperson
, to the filter.
- GraphQL Query
- GraphQL Variables
- JSON Response
query CounterExample1 (
$timeRange: RelativeTimeRange,
$salesperson: String!
) {
sales: metricByName (uniqueName: "sales") {
counter ({
timeRange: { relative: $timeRange }
filters: [{
column: "Salesperson"
operator: EQUALS
value: $salesperson
}]
}) {
value
}
}
}
{
"timeRange": "THIS_YEAR",
"salesperson": "Mike"
}
{
"data": {
"sales": {
"counter": {
"value": "100"
}
}
}
}
2. How many times did we sell a particular product?
In order to answer the question, "How many times did we sell a particular product?",
we need to query our Sum Metric and filter by the "Product ID" Dimension. In the GraphQL
query below, we use metricByName
to get the "sales" Metric, and then we pass
a variable, $productId
, to the filter.
- GraphQL Query
- GraphQL Variables
- JSON Response
query CounterExample2 (
$timeRange: RelativeTimeRange,
$productId: String!
) {
sales: metricByName (uniqueName: "sales") {
counter ({
timeRange: { relative: $timeRange }
filters: [{
column: "Product ID"
operator: EQUALS
value: $productId
}]
}) {
value
}
}
}
{
"timeRange": "THIS_YEAR",
"productId": "1001"
}
{
"data": {
"sales": {
"counter": {
"value": "100"
}
}
}
}