hbuilder埋点过程中 requestHeaders 无法获取字段Referer的值的解决方案

时间:2022-07-02 20:19:32

 

跳转过程前手动存取当前页面信息

$(function(){
var aList = document.querySelectorAll("a");
for (var i=0;i<aList.length;i++) {
aEvent(i)
}

function aEvent(i){
$(aList[i]).click(function(){
window.localStorage.Referer=document.URL.split("/www/wap/")[1];
})
}
})

新页面ajax 手动设置

...

params.beforeSend = function(request) {
request.setRequestHeader("From", "App");
// console.log(window.localStorage.Referer);
request.setRequestHeader("Lysource", window.localStorage.Referer);

...

 百度统计

var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?f9f63abe1b3f7c5882ca575ed9fa85e3";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();