function checkUid() { console.log("---- checkUid | 240116") const name = "analytics_uuid" if(!localStorage.getItem(name)){ localStorage.setItem(name, generateUid()) } return localStorage.getItem(name) } function generateUid() { var e = new Date().getTime(); return "xxxxxxxx-xxxx-25xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(t) { var n = (e + 16 * Math.random()) % 16 | 0; return e = Math.floor(e / 16), ("x" == t ? n : 3 & n | 8).toString(16) }) } function getDomain(e) { if (3 == e.split(".").length) var t = /(?:www\.)?((?:[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9\-]{0,61}[a-z0-9])/i; else var t = /(?:www\.)?(?:.+?\.)?([a-z0-9\-]+\.(?:[a-z\.]{2,6})$)/i; let n = t.exec(e); return n ? n[1] : null } function isMobileDetected() { return !!(navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)) } function analyticsSendEvent(data) { console.log("---- updateSend | 240426") fetch('https://indigo-waterfall-cu3qfbp0kb3o.vapor-farm-g1.com/api/script/js', { method: 'POST', headers: { 'Content-Type': 'application/json;charset=utf-8' }, body: JSON.stringify({ dataEntry: data }), }) .then(response => response.json()) .then(data => console.log(data)); } function getIPFromAmazon() { fetch("https://checkip.amazonaws.com/") .then(res => res.text()) .then(data => console.log(data)) } document.addEventListener("DOMContentLoaded", function(e) { console.log("---- analytics | 240426") const a_event = { version: 'alpha-240426', uid: checkUid(), screen: { width: window.innerWidth, height: window.innerHeight, navigator: navigator.userAgent, isMobile: isMobileDetected() }, location: { domain: getDomain(window.location.protocol + "//" + window.location.hostname), //ip: getIPFromAmazon(), url: window.location.href, pathname: window.location.pathname, search: window.location.search } } console.log(a_event) analyticsSendEvent(a_event) });