Skip to content

Tracking rate

Trackers.rate is useful for measuring the rate of some event.

For example, if you want to measure the rate of clicking:

import { rate } from 'ixfx/trackers.js';
const clicks = rate();
button.addEventListener(`click`, () => {
rate.mark(); // Note that an event happened
})

To get computed values from the tracker:

clicks.perSecond; // Clicks per second
clicks.perMinute; // Clicks per minute

You can call reset() if you want to manually reset the tracker.

It has some useful options for limiting how many events to track, and to automatically reset if there hasn’t been an event for a while.

// Only use most recent 5 samples,
// and reset the tracker after 5 secs of inactivity
const clicks = rate({
samplesLimit: 5,
timeoutInterval: { secs: 5 }
})

computeIntervals() calculates the minimum, maximum and average interval between events.

Demo