// Cookie Functions // function Set_Cookie(name, value, expires, path, domain, secure) { // set time, it's in milliseconds var today = new Date(); today.setTime(today.getTime()); if (expires) { expires = expires * 60 * 1000; } var expires_date = new Date(today.getTime() + (expires)); document.cookie = name + "=" + escape(value) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" ); } function Get_Cookie(check_name) { // first we'll split this cookie up into name/value pairs // note: document.cookie only returns name=value, not the other components var a_all_cookies = document.cookie.split(';'); var a_temp_cookie = ''; var cookie_name = ''; var cookie_value = ''; var b_cookie_found = false; // set boolean t/f default f for (i = 0; i < a_all_cookies.length; i++) { // now we'll split apart each name=value pair a_temp_cookie = a_all_cookies[i].split('='); //alert(a_temp_cookie[0]); // and trim left/right whitespace while we're at it cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, ''); // if the extracted name matches passed check_name if (cookie_name == check_name) { b_cookie_found = true; // we need to handle case where cookie has no value but exists (no = sign, that is): if (a_temp_cookie.length > 1) { cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, '')); } // note that in cases where cookie is initialized but no value, null is returned return cookie_value; } a_temp_cookie = null; cookie_name = ''; } if (!b_cookie_found) { return; } } function Delete_Cookie(name, path, domain) { if (Get_Cookie(name)) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; } var entity = function (url, mode) { var m; m = url.match(/^https?:\/\/([^\/]+\.)?([a-z0-9\-_]+?)\.(co|org|net|com|gov|name|arpa|mil|edu|biz|mobi|aero|asia|cat|coop|info|int|jobs|museum|pro|tel|travel|xxx|[a-z][a-z]|(co|edu|gov|net|org|com)\.[a-z][a-z])(\/|$)/i); if (m === null) { return ''; } if (mode == 1) return m[2]; else if (mode == 2) return m[2] + "." + m[3]; }; var ajaxPost = function (action, postParams) { var xmlhttp; if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); var postVals = "action=" + action + "&" + postParams; var url = "//pixel.admedia.com/convVisitLib.php"; xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { var rObj = eval('(' + xmlhttp.responseText + ')'); if (action == "createNew") visit.updateVisit(rObj); } }; xmlhttp.open("POST", url, true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send(postVals); }; var updateLatestTime = function () { }; var getCurrentTime = function () { return Math.round((new Date()).getTime() / 1000); }; //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// var visit = { // IP, UA and OS // ip: "18.117.101.250", ua: "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)", user_os: 21, user_browser: 10, isMobile: 0, // Referer Info // pageUrl: document.location.href, pageRef: document.referrer, pageEntity: "", refEntity: "", isRefresh: 0, // Cookie Info // admCookie: 0, cookieKey: "admVisitorConvTrack", cookieVal: "", cookiesEnabled: 0, lsEnabled: 0, noCookieLS: 0, cookieDuration: 30, // 30 Minutes updateTSDuration: 5, // 5 seconds // Visit Info // isConversion: 0, unique_id: "", visit_id: 0, visit_ts: 0, adv_id: "20581", event_id: "", latestCheckTime: 15, // 15 minutes newVisit: 0, // Referer Functions // // Cookie Functions // updateVisit: function (rObj) { if (rObj && rObj.id > 0) { if (this.cookiesEnabled) this.updateCookie(rObj); else this.updateLocalStorage(rObj.id); } }, updateCookie: function (rObj) { if (rObj && rObj.id > 0) { this.visit_id = rObj.id; this.visit_ts = getCurrentTime(); this.cookieVal = this.visit_id + ":" + this.visit_ts; Set_Cookie(this.cookieKey, this.cookieVal, this.cookieDuration, '/', '', ''); updateLatestTime(); } }, updateLocalStorage: function (vid) { if (vid && vid > 0) { this.visit_id = vid; this.visit_ts = getCurrentTime(); this.cookieVal = this.visit_id + ":" + this.visit_ts; localStorage.setItem(this.cookieKey, this.cookieVal); updateLatestTime(); } }, isCookieEnabled: function () { Set_Cookie('adMCookieTest', 'test', 10, '/', '', ''); if (Get_Cookie('adMCookieTest')) return 1; else return 0; }, isLSEnabled: function () { var uid = new Date, result; try { localStorage.setItem('adMCookieTest', 'test'); result = localStorage.getItem('adMCookieTest') == 'test'; localStorage.removeItem(uid); if (result && localStorage) return 1; else return 0; } catch (e) { return 0; } }, // Referer Functions // Initialization Function init: function () { // Check if cookies are enabled if (!this.cookiesEnabled) this.cookiesEnabled = this.isCookieEnabled(); if (this.cookiesEnabled) { this.cookieVal = Get_Cookie(this.cookieKey); if (this.cookieVal && this.cookieVal != '') { var cookieSp = this.cookieVal.split(":"); if (cookieSp[0] && cookieSp[0] > 0) { this.admCookie = 1; this.visit_id = cookieSp[0]; this.visit_ts = cookieSp[1]; } } } // Get Entities if (this.pageUrl != '') this.pageEntity = entity(this.pageUrl, 1); if (this.pageRef != '') this.refEntity = entity(this.pageRef, 1); this.startVisit(); }, // Visit Functions // getPostParams: function () { var postParams = 'visit_id=' + this.visit_id; postParams += '&adv_id=' + this.adv_id; postParams += '&event_id=' + this.event_id; postParams += '&ip=' + this.ip; postParams += '&user_agent=' + this.user_browser; postParams += '&os=' + this.user_os; postParams += '&isConversion=' + this.isConversion; postParams += '&unique_id=' + this.unique_id; postParams += '&referer=' + encodeURIComponent(this.pageRef); postParams += '&pageUrl=' + encodeURIComponent(this.pageUrl); postParams += '&isMobile=' + this.isMobile; postParams += '&noCookieLS=' + this.noCookieLS; return postParams; }, createNew: function () { postParams = this.getPostParams(); ajaxPost("createNew", postParams); }, startVisit: function () { var postParams; // If Admedia Tracking Cookie does not exist if (!this.admCookie) { // Create new visit. Update conv. Store visit in cookie this.createNew(); } else // If Admedia TRacking Cookie exists { if (this.visit_id > 0) { // Update Conv postParams = this.getPostParams(); ajaxPost("updateConv", postParams); var cObj = {id: this.visit_id}; this.updateVisit(cObj); } else this.createNew(); } } }; visit.init();