关闭页面上报数据

引文:

https://mp.weixin.qq.com/s/3taWHBu0vxRXP7WDax5M-Q

 

1、有几种方式发送数据,xhr/jsonp/new Image()/sendBeacon

参考链接:

https://www.cnblogs.com/aaronjs/archive/2012/06/30/2570810.html

2、推荐:sendBeacon

参考链接:

http://kaifage.com/notes/76/navigator-sendBeacon.html

https://www.thyngster.com/google-analytics-added-sendbeacon-functionality-universal-analytics-javascript-api/

 

window.addEventListener('unload', trackUnload, false);
function logData() {
 navigator.sendBeacon("/log", JSON.stringify({'unload': location.pathname}));
}

posted @ 2019-01-18 14:38  土豆zhang  阅读(251)  评论(0编辑  收藏  举报