-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.js
46 lines (40 loc) · 954 Bytes
/
report.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
let ios = window.navigator.userAgent.match(/(iPhone\sOS)\s([\d_]+)/);
// u need to change !!!
let reportUrl = 'report.test.com';
let params = {
common: {
_os_version: ios[2].replace(/_/g, '.')||'',
_os: ios ? 'ios' : 'android'
},
items: [
{
_key: 'h5activity',
_opertime: Date.parse(new Date()) / 1000 + '',
}
]
}
export default function (extend) {
extend.forEach((item)=>{
for(let k in item){
item[k] = typeof item[k] == 'string' ? item[k].replace(/&/g,'%26') : item[k];
}
});
params.items = extend;
let useBeacon = true;
if (ios) {
useBeacon = false;
}
if(useBeacon && typeof navigator.sendBeacon == 'function') {
navigator.sendBeacon(reportUrl, JSON.stringify(params));
} else {
$.ajax({
type: 'POST',
url: reportUrl,
data: params,
dataType: 'json',
success: function(res) {
// do something
}
})
}
}