npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

activity-event-listener

v1.2.5

Published

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

Downloads

2

Readme

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'})