Metric methods: define, query, watch
The Metric Verbs define, query, watch as typed SDK methods, with inputs, result, refusals and an example.
Reference for Metric, one group of Metric methods.
Metric.define
Define compiles a Metric’s query against the Startup’s Events and Entries and lists every Event it reads. Verb page.
interface MetricVerbs {
define(input: MetricDefineInput, options?: SB.CallOptions): SB.Call<Metric>
}Emits Metric.defined.
Inputs
| Input | Type | Required | Description |
|---|---|---|---|
name | string | required | The Metric’s name. |
query | text | required | The query, over Events and Entries. |
unit | string | required | What one unit of it is. |
Returns
| Output | Type | Required | Description |
|---|---|---|---|
metric | Metric | required | The defined Metric. |
Refuses when
| Check | Error | Fix | Then call |
|---|---|---|---|
| The key is valid, but its scopes do not allow this operation. | forbidden | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
Example
import { $ } from 'startup-builder'
const metric = await $.Metric.define({ name: 'Leaseline', query: 'Example query', unit: 'Example unit' })Metric.query
Query reads Metrics or Events as a trend, funnel, retention curve, path or lifecycle, broken down by any property. Verb page.
interface MetricVerbs {
query(input: MetricQueryInput, options?: SB.CallOptions): SB.Call<MetricQueryOutput>
}Emits Metric.queried.
Inputs
| Input | Type | Required | Description |
|---|---|---|---|
metric | Metric | The Metric to read; omitted, the query names Events directly. | |
shape | string | required | The analysis to run. |
breakdown | string | The property to split by, such as an Organization or a Motion. | |
window | string | The time range, such as 30d. |
Returns
| Output | Type | Required | Description |
|---|---|---|---|
rows | json | required | The result rows, each number with its readability. |
metric | Metric | required | The Metric read. |
Refuses when
| Check | Error | Fix | Then call |
|---|---|---|---|
| The key is valid, but its scopes do not allow this operation. | forbidden | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
Example
import { $ } from 'startup-builder'
const { rows, metric } = await $.Metric.query({ shape: 'trend' })Metric.watch
Watch alerts the owner of a Metric when it crosses a threshold, by a Task or a Message. Verb page.
interface MetricVerbs {
watch(input: MetricWatchInput, options?: SB.CallOptions): SB.Call<MetricWatchOutput>
}Emits Metric.watched.
Inputs
| Input | Type | Required | Description |
|---|---|---|---|
metric | Metric | required | The Metric to watch. |
threshold | number | required | The value that trips it. |
direction | string | required | Trip when the Metric goes above or below the threshold. |
Returns
| Output | Type | Required | Description |
|---|---|---|---|
watch | Watch | required | The Watch that checks it. |
metric | Metric | required | The Metric now watched. |
Refuses when
| Check | Error | Fix | Then call |
|---|---|---|---|
| The key is valid, but its scopes do not allow this operation. | forbidden | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |
Example
import { $ } from 'startup-builder'
const { watch, metric } = await $.Metric.watch({ metric: 'metric_GXFHAlK100', threshold: 1, direction: 'above' })