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

send-analytics

v1.0.0

Published

A js Library for sending analytics and diagnostics data to a server with page transition and visibility

Downloads

13

Readme

Send Analytics and Diagnostics to Server Asynchronously

sendAnalytics.js is use to schedule asynchronous and non-blocking delivery of data that minimizes resource contention with other time-critical operations, while ensuring that such requests are still processed and delivered to destination. This means:

  • The data is sent reliably
  • It's sent asynchronously
  • It doesn't impact the loading of the next page
  • this library also support transition

Transition happens when a user navigates to a new page, switches tabs, closes the tab, minimizes or closes the browser, or, on mobile, switches from the browser to a different app.

#Supported HTTP Verb

  • POST

#Installation

include sendAnalytics.js to your html, you can grab it from npm

    npm install send-analytics

or from a cdn

    https://cdn.jsdelivr.net/npm/send-analytics

#Usage

send data on DOMdocumentLoad

    
    const obj = { text: 'Hello world' };
    
    const url = "http://localhost/api/hello";
    
    const analytics = sendAnalytics.config()
                      .send(url, obj);

See Examples

React.js Example

#API

config([ transitionObject ])

  • transitionObject < Object > ==> { when: ['visible', 'hidden'] }
    • if no params is passed the once() and repeat() will be ignored
    • data will be sent immediately the DOMdocumentLoad
  • Return < instance of sendAnalytics > which allows you to chain other methods

The Page Transition and Visibility is especially useful for saving resources and improving performance by letting a page avoid performing unnecessary tasks when the document isn't visible

send([ url, data ])

  • url < URL String > ===> The URL that will receive the data. Can be relative or absolute.
  • data < Object > ===> object containing the data to send.
  • Return < instance of sendAnalytics >

once()

  • send data to server once on First visibility state change

repeat()

  • send data on Every visibility state change

onSuccess( [ callback ] )

  • callback < Function >

Note: for you to receive a success Event the onSuccess method must come before the send([ url, data]) method. see example onSuccess

Ref developer.mozilla.org - sendBeacon

#License

the Lamb of God