Functions for storing data from application events in metric points. These functions are utilized in the definition of metrics.
To perform custom treatment of a certain data point (aka a reducer) you can
implement the value
function with the following signature:
function(data: Object?, context: Any?): Any
Inside such a reducer you have access to both the application event's data as well as the current context so that you can refine or compute the data any way you wish.
Always return the specified value regardless of the application event data.
For example, let's assume we have a UI interaction that can be triggered using either the mouse or the keyboard and that each kind of interaction triggers a distinct event, but we want the metric point to store information anyway:
const metrics = [
{
name: 'Search box opened',
events: [ 'search-box/opened-using-mouse' ],
dataPoints: [
{
name: 'usingMouse',
DataPoint.always(true)
}
]
},
{
name: 'Search box opened',
events: [ 'search-box/opened-using-keyboard' ],
dataPoints: [
{
name: 'usingKeyboard',
DataPoint.always(true)
}
]
}
]
Store whether a value in the application event data was present at all,
regardless of its value (it has to evaluate to true
.)
This coercion is useful in cases when you're interested only in whether a certain value is set. For example, let's assume we have a UI filtering control that lets the user filter results by Name and Date of Birth. What we want the metric point to convey is whether they are using the name filter, the date of birth filter, or both. The values are irrelevant.
const metrics = [
{
name: 'Filtered results',
events: [ 'results-filtered' ],
dataPoints: [
{
name: 'byName',
value: DataPoint.flag('name')
},
{
name: 'byDateOfBirth',
value: DataPoint.flag('dateOfBirth')
}
]
}
]
const event1 = { name: 'results-filtered', data: { name: 'a' } }
// => { byName: true, byDateOfBirth: false }
const event2 = { name: 'results-filtered', data: { name: null } }
// => { byName: false, byDateOfBirth: false }
key | String The property key of the value to test. |