Measurements
A Measurement
is a data structure that contains all the information about a measurement that is sent to Polaris.
TypeScript
interface Measurement {
id: string;
appId: string;
eventName: string;
duration: number;
result: MeasurementResult;
timestamp: DateTime;
connectionQuality: ConnectionQuality | null;
deviceType: DeviceType;
location: Location | null;
userMetadata: object;
}
Let's take a look at each of these properties in more detail.
id
- A unique identifier for the measurement. This is generated by Polaris.appId
- The ID of the app that sent the measurement.eventName
- The name of the event that was measured.duration
- The duration of the measurement in milliseconds.result
- The result of the measurement.timestamp
- The timestamp of the measurement.connectionQuality
- The connection quality of the measurement.deviceType
- The type of device that sent the measurement.location
- The location of the device that sent the measurement.userMetadata
- Any additional metadata that was sent with the measurement.
MeasurementResult
The MeasurementResult
enum is used to indicate the result of a measurement.
TypeScript
enum MeasurementResult {
FAILURE = 'FAILURE',
SUCCESS = 'SUCCESS',
}
ConnectionQuality
The ConnectionQuality
enum is used to indicate the connection quality of a measurement.
TypeScript
enum ConnectionQuality {
FAST = 'FAST',
OK = 'OK',
SLOW = 'SLOW',
SLOWEST = 'SLOWEST',
}
DeviceType
The DeviceType
enum is used to indicate the type of device that sent the measurement.
TypeScript
enum DeviceType {
BOT = 'BOT',
CAR = 'CAR',
DESKTOP = 'DESKTOP',
PHONE = 'PHONE',
TABLET = 'TABLET',
TV = 'TV',
}
Location
The Location
interface is used to indicate the location of the device that sent the measurement.
TypeScript
interface Location {
country: string;
region: string;
city: string;
latitude: number;
longitude: number;
}
Filtering Measurements in Polaris
Let's learn how to filter measurements when defining indicators in Polaris.
- First, create a new indicator in Polaris. For this example, we'll create an indicator that tracks the average time it takes to authenticate a user that is using a mobile device in the United States.
- Next, provide a name for the indicator. For this example, we'll name the indicator
Auth / Duration
. Note the slash in the name. This is used to create a hierarchy of indicators. - Next, choose the indicator window. For this example, we'll choose 1 hour.
- Provide the predicate function for filtering measurements.
Indicator predicate function
function main (measurement) => {
return (
measurement.eventName === 'auth' &&
measurement.deviceType === 'PHONE' &&
measurement.location.country === 'US'
);
}