84 lines
2.3 KiB
JavaScript
84 lines
2.3 KiB
JavaScript
/**
|
|
* 获取访问者IP
|
|
*/
|
|
getVisitorIp = function () {
|
|
let ip = '127.0.0.1'
|
|
$.ajax({
|
|
type: 'get',
|
|
url: 'https://get.geojs.io/v1/ip.json',
|
|
data: {},
|
|
dataType: 'json',
|
|
async:false,
|
|
}).done(function (responseData) {
|
|
// console.log(responseData)
|
|
if (responseData.ip) {
|
|
ip = responseData.ip
|
|
} else {
|
|
ip = '127.0.0.1'
|
|
}
|
|
});
|
|
return ip;
|
|
}
|
|
|
|
const visitIp = getVisitorIp()
|
|
|
|
/**
|
|
* 请求开始
|
|
*/
|
|
const RequestUrl = "/index/base/submitActionLog"
|
|
|
|
// 图片选择器,记录图片点击的
|
|
const imgAction = $("[log='img']");
|
|
const aAction = $("[log='a']");
|
|
|
|
imgAction.click(function ($this){
|
|
// console.log('click-img',$this)
|
|
// console.log(window.location.href)
|
|
const content = $this.target.outerHTML
|
|
// console.log(content)
|
|
actionSub($this,1,content,visitIp)
|
|
});
|
|
|
|
imgAction.dblclick(function ($this){
|
|
const content = $this.target.outerHTML
|
|
actionSub($this,2,content,visitIp)
|
|
});
|
|
// a标签行为监控
|
|
aAction.click(function ($this){
|
|
const content = $this.target.parentElement.outerHTML
|
|
actionSub($this,1,content,visitIp)
|
|
});
|
|
|
|
// a标签行为监控
|
|
aAction.dblclick(function ($this){
|
|
const content = $this.target.parentElement.outerHTML
|
|
actionSub($this,2,content,visitIp)
|
|
});
|
|
|
|
/**
|
|
* 日志请求提交
|
|
*/
|
|
function actionSub(obj,clickNum,content,visitIp) {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: RequestUrl,
|
|
data: {
|
|
'url' : window.location.href, /*访问页*/
|
|
'refer' : obj.src, /*访问来源*/
|
|
'click' : clickNum, /*点击次数*/
|
|
'content' : content, /*访问内容*/
|
|
'ip' : visitIp, /*访客IP*/
|
|
'start_time' : obj.timeStamp, /*点击时间*/
|
|
'drive' : window.navigator.userAgent.toLowerCase(), /*PC OR 移动端*/
|
|
// 'system' : window.navigator.userAgent.toLowerCase(), /*设备系统*/
|
|
// 'brower' : window.navigator.userAgent.toLowerCase(), /*浏览器*/
|
|
// 'models' : window.navigator.userAgent.toLowerCase(), /*设备型号*/
|
|
'date_time' : (new Date()).valueOf() /*生成时间*/
|
|
},
|
|
dataType: 'json',
|
|
// success: function (json) {
|
|
// console.log(json);
|
|
// }
|
|
});
|
|
}
|