This Javascript API tracks the number of visits to an app in a given time frame and returns the number of visits in constant O(1) time.
To initialize a tracker, call the constructor function passing in an integer that represents how many minutes ago you want to track:
let tracker = Tracker.new(1;)
// tracker will track number of visits 1 minute ago
let trackerThreeMinAgo = Tracker.new(3);
// tracker will track number of visits 3 minutes ago
let trackerFiveMinAgo = Tracker.new();
// Default: will track number of visits 5 minutes ago
By default, a tracker will track number of visits 5 minutes ago.
The function logHit()
increments a count of total visits every time a user visits the app.
logHit()
must be invoked automatically when a hit on our app is detected.
The function getHits()
returns the total number of visits
from a given number of minutes ago.
let tracker = Tracker.new(1);
let numberOfVisits = tracker.getHits();