// uvpv数据上报
var pvuvReport = (function(window, undefined){
var uploadUrl = '';
var init = function(config) {
uploadUrl = config.url;
pvReport();
uvReport();
};
var getCookie = function(name) {
var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
arr = document.cookie.match(reg);
return arr && arr.length > 0 ? arr[2] : null;
};
var setCookie = function(name, value) {
var Days = 1;
var exp = new Date();
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
};
var pvReport = function() {
$.ajax({
url: 'statistic/insStatistic.do?type=pv&connect='+uploadUrl,
type: 'get',
dataType: 'json',
success: function(data) {
//location.href=uploadUrl;
}
});
};
var uvReport = function() {
!getCookie('iddUVReport') && $.ajax({
url: 'statistic/insStatistic.do?type=uv&connect='+uploadUrl,
type: 'get',
dataType: 'json',
success: function(data) {
//location.href=uploadUrl;
setCookie('iddUVReport', 'true');
}
});
};
return {
init: init
}
})(window);
var pvuvReport = (function(window, undefined){
return {
init: init
}
})(window);
返回一个对象,里面有一个init方法
init 方法执行 pvReport和uvReport方法。pvReport 每次都上报。
这段代码只能在浏览器中执行。