作者:admin,发布日期:2020-05-09
阅读:1272;评论:0

写在开头

服务器使用InstantClick.js预加载网页后,会出现百度统计无法统计请求的情况,这时就需要自己监听重载事件,手动发送用户的请求给百度统计服务器。

解决方法

InstantClick.on('change', function() {
	_hmt.push(['_trackPageview', document.location.pathname + document.location.search + document.location.hash]);
});

修改代码,增加事件监听,当页面改变时手动调用百度统计js api请求百度统计服务器即可。

API调用参考:https://tongji.baidu.com/open/api/more?p=guide_trackPageview

_hmt.push(['_trackPageview', pageURL]);

pageURL:指定要统计PV的页面URL。此项必选。

document.location.pathname:请求的网页地址,不包括?后面的内容

document.location.search:请求的网页参数,包含?符号

document.location.hash:请求的网页#后面的内容,包含#号


如果只需要记录访问的网页,直接使用document.location.pathname即可

修改代码后刷新缓存,即可发现切换页面也会触发请求,此时修复成功。

Snipaste_2020-05-09_23-15-31.png

评论区

发表评论

必填

选填

选填

必填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。