This method is intended for analytics and diagnostics code to send data to a server.
A problem with sending analytics is that a site often wants to send analytics when the user has finished with a page: for example, when the user navigates to another page. In this situation the browser may be about to unload the page, and in that case the browser may choose not to send asynchronous XMLHttpRequest requests.
XMLHttpRequest
In the past, web pages have tried to delay page unload long enough to send data. To do this they have used workarounds such as:
<img>
src
All these methods block unloading the document, which slows down navigation to the next page. There's nothing the next page can do to avoid this, so the new page seems slow, even though it's the fault of the previous page.
With the SendBeaconJSON method, the data is transmitted asynchronously when the user agent has an opportunity to do so, without delaying unload or the next navigation. This means:
endBeaconJSON
SendBeaconJSON - The navigator.sendBeacon() method asynchronously sends a small amount of data over HTTP to a web server using POST. It’s intended to be used for sending analytics data to a web server, and avoids some of the problems with legacy techniques for sending analytics, such as the use of XMLHttpRequest. This JSON variant includes the 'application/json' header so you can ping OutSystems Platform REST entry points.
See unit tests for implementation details.