Giter Club home page Giter Club logo

browser-interaction-time's Introduction

browser-interaction-time

PRs Welcome license Build Status npm SemVer semantic-release Greenkeeper badge

BrowserInteractionTime lets you track the time a user is active on your webpage while ignoring time spent on a different tab or with a minimized window. It also ignores the time spent while the user is idle on a web page meaning after a certain amount of time (idleTimeoutMs) without any user interactions (scroll, mousemovement etc) the time will stop until the next user interaction.

Importing BrowserInteractionTime

You can import the generated bundle to use the whole library like this:

import BrowserInteractionTime from 'browser-interaction-time'

Additionally, you can import the transpiled modules from dist/lib:

import BrowserInteractionTime from 'browser-interaction-time/dist/lib/'

API

Initialize

import BrowserInteractionTime from 'browser-interaction-time'

const browserInteractionTime = new BrowserInteractiontime({
  timeIntervalEllapsedCallbacks: [],
  absoluteTimeEllapsedCallbacks: [],
  browserTabInactiveCallbacks: [],
  browserTabActiveCallbacks: [],
  idleTimeoutMs: 3000,
  checkCallbacksIntervalMs: 250
})

Start timer

browserInteractionTime.startTimer()

Stop timer

browserInteractionTime.stopTimer()

Adding a callback that is executed on interval

const cb = {
  multiplier: time => time * 2,
  timeInMilliseconds: 1000,
  callback: () => console.log('callback')
}
browserInteractionTime.addTimeIntervalEllapsedCallback(cb)

Adding a callback that is executed on absolute time

const callbackData = {
  timeInMilliseconds: 1000,
  callback: () => console.log('callback')
  pending: true
}
browserInteractionTime.addAbsoluteTimeEllapsedCallback(callbackData)

Adding callback executed when browser tab becomes inactive

const callback = () => console.log('some callback')
browserInteractionTime.addBrowserTabInactiveCallback(callback)

Adding callback executed when browser tab becomes active

const callback = () => console.log('some callback')
browserInteractionTime.addBrowserTabActiveCallback(callback)
browserInteractionTime.mark('a-mark')
browserInteractionTime.mark('b-mark')
browserInteractionTime.getMarks('a-mark')
browserInteractionTime.measure('a-measure', 'a-mark', 'b-mark')

Get measure by name

browserInteractionTime.getMeasures('a-measure') // Array of measures with name

Get Time in Milliseconds

browserInteractionTime.getTimeInMilliseconds() // number

Check if timer is running

browserInteractionTime.isRunning() // boolean

Reset all times

browserInteractionTime.reset()

Cleanup event listeners and timers

browserInteractionTime.destroy()

NPM scripts

  • npm t: Run test suite
  • npm start: Run npm run build in watch mode
  • npm run test:watch: Run test suite in interactive watch mode
  • npm run test:prod: Run linting and generate coverage
  • npm run build: Generate bundles and typings, create docs
  • npm run lint: Lints code
  • npm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't 😉)

Author

Maximilian Heinz @meandmax

Collaborators

❤️ Logo Design by Dominik Straka

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.