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.
- POST
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@1.0.0/sendAnalytics.min.js
send data on DOMdocumentLoad
const obj = { text: 'Hello world' };
const url = "http://localhost/api/hello";
const analytics = sendAnalytics.config()
.send(url, obj);
See Examples
this Lirary uses Fetching algorithm for handling http request
- 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
- 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 >
- send data to server once on First visibility state change
- send data on Every visibility state change
- callback < Function >
Note: for you to receive a success Event the onSuccess method must come before the send([ url, data]) method. see example onSuccess