Skip to content

arkokoley/actively

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Actively

Actively track user engagement and know when they move away from your page.

npm version

Install

npm install --save actively

Example - basic

import Actively from 'actively';
const active = new Actively({
  timeIntervalEllapsedCallbacks: [],
  absoluteTimeEllapsedCallbacks: [],
  browserTabInactiveCallbacks: [],
  browserTabActiveCallbacks: [],
  idleTimeoutMs: 3000,
  checkCallbacksIntervalMs: 250
})

window.addEventListener('mousemove', active.startTimer)
window.addEventListener('beforeunload', active.stopTimer)

Example - Advanced

import Actively from 'actively';
const active = new Actively({
  timeIntervalEllapsedCallbacks: [],
  absoluteTimeEllapsedCallbacks: [],
  browserTabInactiveCallbacks: [],
  browserTabActiveCallbacks: [],
  idleTimeoutMs: 3000,
  checkCallbacksIntervalMs: 250
})

window.addEventListener('mousemove', active.startTimer)
window.addEventListener('beforeunload', active.stopTimer)

const cb = {
  multiplier: time => time + (60 * 5 * 1000), // Every 5 minutes
  timeInMilliseconds: 0,
  callback: () => {
    console.log("Doing Something every 5 minutes")
  }
}
active.addTimeIntervalEllapsedCallback(cb)

const callback = () => console.log('Browser going inactive');
active.addBrowserTabInactiveCallback(callback)

var ActiveTimeIntervals = active.times; // array of time periods with user activity

API

Public methods

running Bool

Shows is user is active on current webpage and the timer is running.

times Array

Array of timeDurations when the user was active.

Each time duration is

 Object({
      start: Date,
      stop: Date
    })

idle Bool

True when the user is inactive on current webpage and the timer is stopped.

currentIdleTimeMs Integer

Time elapsed(in miliseconds) since the user was last active.

idleTimeoutMs Integer

The idle time for a user after which timer stops and user is marked as inactive.

Public Demo

Demo coming soon!

Used in production by Gratia

License

MIT © Gaurav Koley, 2020

About

Actively track user engagement and know when they move away from your page.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published