|
<script async> |
|
(function (endpoint) { |
|
// SessionID |
|
var sessionId = getCookie("simpletag-sessionid"); |
|
if (sessionId === null) { |
|
sessionId = getUniqueStr(); |
|
} |
|
var sessionExpire = new Date(); |
|
sessionExpire.setTime(sessionExpire.getTime() + 1000 * 60 * 30); // 30分 |
|
document.cookie = 'simpletag-sessionid=' + sessionId + '; expires=' + sessionExpire.toUTCString(); |
|
|
|
// UserID |
|
var userId = getCookie("simpletag-userid"); |
|
if (userId === null) { |
|
userId = getUniqueStr(); |
|
} |
|
var userExpire = new Date(); |
|
userExpire.setTime(userExpire.getTime() + 1000 * 3600 * 24 * 30); // 30日 |
|
document.cookie = 'simpletag-userid=' + userId + '; expires=' + userExpire.toUTCString(); |
|
|
|
// Send Logs |
|
var req = new XMLHttpRequest(); |
|
var query = "?"; |
|
query += "userid=" + userId; |
|
query += "&sessionid=" + sessionId; |
|
query += "&url=" + location.href; |
|
req.open("HEAD", endpoint + query, true); |
|
req.send(); |
|
console.log("ログを送信しました:"+ endpoint + query); |
|
|
|
function getCookie(name) { |
|
var result = null; |
|
var cookieName = name + '='; |
|
var allcookies = document.cookie; |
|
var position = allcookies.indexOf(cookieName); |
|
if (position != -1) { |
|
var startIndex = position + cookieName.length; |
|
var endIndex = allcookies.indexOf(';', startIndex); |
|
if (endIndex == -1) { |
|
endIndex = allcookies.length; |
|
} |
|
result = decodeURIComponent(allcookies.substring(startIndex, endIndex)); |
|
} |
|
return result; |
|
} |
|
function getUniqueStr(myStrong) { |
|
var strong = 1000; |
|
if (myStrong) strong = myStrong; |
|
return new Date().getTime().toString(16) + Math.floor(strong * Math.random()).toString(16) |
|
} |
|
}("//localhost:8080/endpoint.html")); |
|
</script> |