Skip to content

A Javascript API for tracking website visits and returning a count of visits from X minutes ago in constant time

Notifications You must be signed in to change notification settings

wangytangy/visit_tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Website Visit Tracker

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.

Initialize a Tracker

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.

logHit()

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.

getHits()

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();

About

A Javascript API for tracking website visits and returning a count of visits from X minutes ago in constant time

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published