Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browser-interaction-time

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-interaction-time

[![license](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://raw.githubusercontent.com/atlassian/browser-interaction-time/master/LICENSE) [![Build Status](https://travis-ci.org/atlassian/browser-interaction-time.svg?branch=master)](ht

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
increased by4.16%
Maintainers
1
Weekly downloads
 
Created
Source

⏰ browser-interaction-time

license Build Status npm SemVer semantic-release

browser-interaction-time 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 also stop until the next user interaction.

Importing BrowserInteractionTime

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

import BrowserInteractionTime from 'browser-interaction-time'

Additionally, you can import the transpiled modules from dist/lib in case you have a modular library:

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

API

Initialize

import BrowserInteractionTime from 'browser-interaction-time'

const browserInteractionTime = new BrowserInteractiontime({
    {
        timeIntervalEllapsedCallbacks: [],
        absoluteTimeEllapsedCallbacks: [],
        userLeftCallbacks: [],
        userReturnCallbacks: [],
        pauseOnMouseMovement: false,
        pauseOnScroll: false,
        idleTimeoutMs: 3000,
        checkCallbacksIntervalMs: 250
    },
    {
        addEventListener: window.addEventListener,
        removeEventListener: window.addEventListener,
        setInterval: window.setInterval,
        clearInterval: window.clearInterval,
        hidden: document.hidden
    }
})

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: false
}
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)

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 :wink:)

FAQs

Package last updated on 10 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc