String.prototype.getHostname = function() { var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im'); re = this.match(re); return re && re.length ? re[1].toString() : ''; } var referring_url = ""; var referrer_host = ""; if (document.referrer){ referring_url = document.referrer; } else if (window.opener && window.opener.location && typeof(window.opener.location.href) !='unknown' ){ referring_url = window.opener.location.href; } if (referring_url) { referrer_host = referring_url.getHostname(); referrer_host = referrer_host.toLowerCase(); } if (referrer_host != window.location.hostname) { // Create the cookie we'll use to save state for this web page. var first_referrer = new Cookie("f_ref"); //first referrer var recent_referrer = new Cookie("mr_ref"); //most recent referrer var landing_url = window.location.href; var current_time = 1542743741; var refresh_interval = 5*60; // 5 minutes; if (first_referrer.date_time && (parseInt(current_time) - parseInt(first_referrer.date_time))<=refresh_interval && first_referrer.ref_url==referring_url && first_referrer.ld_url==landing_url) { //alert('first referrer refresh!'); } else if (recent_referrer.date_time && (parseInt(current_time) - parseInt(recent_referrer.date_time))<=refresh_interval && recent_referrer.ref_url==referring_url && recent_referrer.ld_url==landing_url) { //alert('most recent referrer refresh!'); } else if (!first_referrer.date_time) { if (recent_referrer.date_time) { first_referrer.ref_url = recent_referrer.ref_url; first_referrer.ld_url = recent_referrer.ld_url; first_referrer.date_time = recent_referrer.date_time; recent_referrer.remove(); if (referring_url != recent_referrer.ref_url) { recent_referrer.ref_url = referring_url; recent_referrer.ld_url = landing_url; recent_referrer.date_time = "1542743741"; recent_referrer.store(2,'years', '/'); } } else { first_referrer.ref_url = referring_url; first_referrer.ld_url = landing_url; first_referrer.date_time = "1542743741"; } first_referrer.store(2, 'years', '/'); } else { recent_referrer.ref_url = referring_url; recent_referrer.ld_url = landing_url; recent_referrer.date_time = "1542743741"; recent_referrer.store(2,'years', '/'); } }