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

activity-event-listener

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

activity-event-listener

Listen to a web application unhandle exceptions/errors, http success and failure request, user navigation, promise resolve and reject activity

  • 1.2.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Activity Event Listener

Using this package allows you to listen for browser events like unhandle exceptions/errors, http success and failure, unhandle promises, etc.

You can use this package to monitor for user activities and sending the events to a server for logging purposes.

Installation

npm install activity-event-listener --save

Usage

Event Listener

import {subscribe} from 'activity-event-listener';

const options = {
  promiseCatch: true,
  httpFailure: true
}

subscribe(function(events){
  // This function is called whenever an event is triggered
}, options)

Event Listener Options

You can also specify which event you want to listen by altering the options property

const options = {
  promiseCatch: true, // Trigger when promise catch is invoked. default true
  httpSuccess: true, // Triggered when an http request is completed successfully. default true
  httpFailure: true, // Triggered an event when an http request failed. default true
  unhandleRejection: true, // Triggered when an unhandle Rejection error is thrown. default true
  linkClick: true, // Triggered when any html anchor tag (a link) is clicked. default false
  buttonClick: true // Triggered when any html button is clicked. default false,
  ignoreUrl: 'https://example.com/logging-endpont' // Provide the url link that should be ignored (not tracked) if you plan to be sending the events to a server.
}

Trigger Events

You can also listen for frontend framework specific events and trigger an event.

import {subscribe, options, trigger} from 'activity-event-listener';

// file1.js
subscribe(function(event){
  // log the event or send it to server for storage
})

// file2.js
Vue.config.errorHandler = function(error) {
  let customEvent = {
    ...error,
    message: error && error.message,
    stack: error && error.stack,
    isError: true
  }

  trigger(customEvent, options.unhandleRejection);
}

Sample work

import {subscribe} from 'activity-event-listener';

subscribe(function(events){
  // Push the events to a logging server
  const xhttp = new XMLHttpRequest();
  xhttp.onload = function() {
    console.log('Activity Sent')
  };
  
  xhttp.open("POST", "/activity-event-log/", true);
  xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

  xhttp.send(JSON.stringify(events));

}, {ignoreUrl: 'https://myserver.com/logging-endpont'})

Keywords

FAQs

Package last updated on 18 Nov 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