var session = localStorage.getItem("analyze_session") if (session === null) { function UUID() { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { const r = Math.random() * 16 | 0; const v = c === "x" ? r : (r & 0x3 | 0x8); return v.toString(16); }); } session = UUID() localStorage.setItem("analyze_session", session) } const script = document.createElement("script"); script.src = 'https://unpkg.shop.jd.com/axios@1.13.2/dist/axios.min.js' document.head.appendChild(script); const engagedKey = `analyze_engaged_${session}`; let engagePosted = localStorage.getItem(engagedKey) === "1"; function postEngage() { if (engagePosted) return; if (!window.axios) { setTimeout(postEngage, 200); return; } engagePosted = true; localStorage.setItem(engagedKey, "1"); axios.post("/analyze/engage", { "link": location.href, "userAgent": navigator.userAgent, "profile": session, }); } function onFirstEngage() { postEngage(); window.removeEventListener('scroll', onScrollEngage); } let scrollEngagePending = false; function onScrollEngage() { if (scrollEngagePending) return; scrollEngagePending = true; setTimeout(() => { scrollEngagePending = false; onFirstEngage(); }, 200); } window.addEventListener('click', onFirstEngage, { once: true, passive: true }); window.addEventListener('keydown', onFirstEngage, { once: true, passive: true }); window.addEventListener('touchstart', onFirstEngage, { once: true, passive: true }); window.addEventListener('scroll', onScrollEngage, { passive: true }); const _historyWrap = function(type) { const orig = history[type]; const e = new Event(type); return function() { const rv = orig.apply(this, arguments); e.arguments = arguments; window.dispatchEvent(e); return rv; }; }; history.pushState = _historyWrap('pushState'); history.replaceState = _historyWrap('replaceState'); window.addEventListener('pushState', function(e) { axios.post("/analyze/view",{ "link":e.arguments[2], "userAgent":navigator.userAgent, "profile":session, }) }); window.addEventListener('replaceState', function(e) { //console.log('change replaceState'); }); function onEnter() { setTimeout(() => { axios.post("/analyze/enter",{ "referer":document.referrer, "link":location.href, "userAgent":navigator.userAgent, "profile":session, }) },200) } document.addEventListener("DOMContentLoaded", onEnter);