-
Notifications
You must be signed in to change notification settings - Fork 0
/
$$$$report.js
106 lines (86 loc) · 3.54 KB
/
$$$$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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(function (window, document) {
var $$$ = window.PingClientsSource ? window.PingClientsSource : {};
// 生成随机字符串
$$$.randomString = function (len) {
var len = len || 32;
var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
var maxPos = chars.length;
var pwd = '';
for (var i = 0; i < len; i++) {
pwd += chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
};
//拉取名为 name 的 cookie 值
$$$._getCookie = function (name) {
var ret = document.cookie.match(new RegExp('(?:^|;\\s)' + name + '=(.*?)(?:;\\s|$)'));
return ret ? ret[1] : "";
};
//设置 cookie
$$$._setCookie = function (name, value, expires, domain, path, secure) {
var path = '/';
var domain = domain || 'pingxx.com';
var cookieText = encodeURIComponent(name) + '=' + encodeURIComponent(value);
expires && (expires instanceof Date) && (cookieText += "; expires=" + expires.toGMTString());
path && (cookieText += "; path=" + path);
domain && (cookieText += "; domain=" + domain);
secure && (cookieText += "; secure");
document.cookie = cookieText;
return $$$;
};
//读取当前 url 中名为 name 的参数值
$$$.getUrlParam = function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return null;
};
//发送数据日志
$$$.report = function (options) {
var xmlhttp = new XMLHttpRequest();
var url = options.url;
var data = options.data;
var success = options.success;
var paramsArray = [];
for (key in data) {
paramsArray.push(key + '=' + data[key])
}
var paramsStr = paramsArray.join('&');
xmlhttp.open('POST', url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send(paramsStr);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.status >= 200 && xmlhttp.status < 300) {
success(xmlhttp.responseText);
} else {
(xmlhttp.responseText) && console.error(xmlhttp.responseText);
}
}
};
window.PingClientsSource = window.$$$ = $$$;
var from = $$$.getUrlParam('from') || 2,
desc = $$$.getUrlParam('desc') || '',
sub_from = $$$.getUrlParam('sub_from') || '',
puid = $$$._getCookie('puid') || '';
//登入页面,检查是否存在 puid 的 cookie 如果已有,doNothing, 否则先生成cookie 再上报
if (!puid) {
puid = $$$.randomString();
var date = new Date(new Date().getTime() + 10 * 365 * 86400000);
var domain = /pingxx/.test(location.href) ? 'pingxx.com' : 'pinpula.com';
$$$._setCookie('puid', puid, date, domain)
._setCookie('from', from, date, domain)
._setCookie('desc', desc, date, domain)
._setCookie('sub_from', sub_from, date, domain);
$$$.report({
url: /pingxx/.test(location.href) ? 'https://dashboard.pingxx.com/page/auto/register_stat' : 'https://dashboard.pinpula.com/page/auto/register_stat',
data: {
"puid": puid,
"desc": desc,
"from": from,
"sub_from": sub_from,
},
success: function (data) {
}
})
}
})(window, document);