-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalytics_cookie.js
51 lines (40 loc) · 1.23 KB
/
analytics_cookie.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
setAnalytics = (function(){
var setAnalytics = {};
setAnalytics.getCookie = function(){
var cookies = document.cookie.split('; '),
cookieLists = {},
cookieText,
cookie,
expire;
for(var i=0;i<cookies.length;i++){
cookie = cookies[i].split('=');
cookieLists[cookie[0]]=cookie[1];
if(cookie[0] === 'setAnalytics' ){break;}
}
if(!cookieLists['setAnalytics']){
expire = new Date();
expire.setTime( expire.getTime() + 60*60*24*365 );
cookieText = Math.random().toString(36).slice(-8)+Math.random().toString(36).slice(-8);
document.cookie = 'setAnalytics=' + cookieText + ';path=/; expires=' + expire.toUTCString();
}else{
cookieText = cookieLists['setAnalytics'];
}
return cookieText;
};
function addZero(num){
return ('0' + num).slice(-2);
}
setAnalytics.getAccessTime = function(){
var dates = new Date();
var year = dates.getFullYear();
var month = dates.getMonth()+1;
var date = dates.getDate();
var hour = dates.getHours();
var minute = dates.getMinutes();
var second = dates.getSeconds();
date = year+'/'+addZero(month)+'/'+addZero(date)+' '+addZero(hour)+':'+addZero(minute)+':'+addZero(second);
return date;
};
setAnalytics.getCookie();
return setAnalytics;
})();