How to report page behavior/performance/error monitoring

When the page is unloaded, if the current data needs to be reported, the synchronous reporting method of xhr will block the jump of the current page; using new Image may encounter aborted, which will result in failure to send successfully.

 

There are two main ways of reporting:

    1. (new Image()).src = "xxxxxxx.do?xxx=aaaa&....." (GET method, data size needs to be considered, so even if the page is cross-domain)
    2.navigator.sendBeacon (POST method, even if page switching can be done in the background, you need to consider browser compatibility and buffer size)
    

It is recommended to optimize the use of navigator.sendBeacon without cross-domain to prevent data loss. Use new Image to send if it is not supported.

If the page jumps during the reporting process, the request is likely to be terminated. In this case, it is recommended to cache a copy of the event first. If a successful response is not received, continue to send it on the next page. 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326109623&siteId=291194637