1function crumbleCookie(a) { 2 for (var d = document.cookie.split(";"), c = {}, b = 0; b < d.length; b++) { 3 var e = d[b].substring(0, d[b].indexOf("=")).trim(), 4 i = d[b].substring(d[b].indexOf("=") + 1, d[b].length).trim(); 5 c[e] = i 6 } 7 if (a) return c[a] ? c[a] : null; 8 return c 9} 10 11function bakeCookie(a, d, c, b, e, i) { 12 var j = new Date; 13 j.setTime(j.getTime()); 14 c && (c *= 864E5); 15 j = new Date(j.getTime() + c); 16 document.cookie = a + "=" + escape(d) + (c ? ";expires=" + j.toGMTString() : "") + (b ? ";path=" + b : "") + (e ? ";domain=" + e : "") + (i ? ";secure" : "") 17} 18 19function writeLogic(n) { 20 var a = getTrafficSource(n, '.example.com'); //Insert your domain here 21 22 a = a.replace(/\|{2,}/g, "|"); 23 a = a.replace(/^\|/, ""); 24 a = unescape(a); 25 bakeCookie(n, a, 182, "/", "", "") //Cookie expiration sets to 182 days 26}; 27 28function getParam(s, q) { 29 try { 30 var match = s.match('[?&]' + q + '=([^&]+)'); 31 return match ? match[1] : ''; 32 // return s.match(RegExp('(^|&)'+q+'=([^&]*)'))[2]; 33 } catch (e) { 34 return ''; 35 } 36} 37 38function calculateTrafficSource() { 39 var source = '', medium = '', campaign = '', term = '', content = ''; 40 var search_engines = [['bing', 'q'], ['google', 'q'], ['yahoo', 'q'], ['baidu', 'q'], ['yandex', 'q'], ['ask', 'q']]; //List of search engines 41 var ref = document.referrer; 42 ref = ref.substr(ref.indexOf('//') + 2); 43 ref_domain = ref; 44 ref_path = '/'; 45 ref_search = ''; 46 47 // Checks for campaign parameters 48 var url_search = document.location.search; 49 50 // console.log(url_search.indexOf('utm_source')); 51 // console.log(getParam(url_search, 'gclid')); 52 // console.log(url_search); 53 54 if (url_search.indexOf('utm_source') > -1) { 55 source = getParam(url_search, 'utm_source'); 56 medium = getParam(url_search, 'utm_medium'); 57 campaign = getParam(url_search, 'utm_campaign'); 58 term = getParam(url_search, 'utm_term'); 59 content = getParam(url_search, 'utm_content'); 60 } 61 else if (getParam(url_search, 'gclid')) { 62 source = 'google'; 63 medium = 'cpc'; 64 campaign = '(not set)'; 65 } 66 else if (ref) { 67 68 // separate domain, path and query parameters 69 if (ref.indexOf('/') > -1) { 70 ref_domain = ref.substr(0, ref.indexOf('/')); 71 ref_path = ref.substr(ref.indexOf('/')); 72 if (ref_path.indexOf('?') > -1) { 73 ref_search = ref_path.substr(ref_path.indexOf('?') + 1); 74 ref_path = ref_path.substr(0, ref_path.indexOf('?')); 75 } 76 } 77 medium = 'referral'; 78 source = ref_domain; 79 // Extract term for organic source 80 for (var i = 0; i < search_engines.length; i++) { 81 if (ref_domain.indexOf(search_engines[i][0]) > -1) { 82 medium = 'organic'; 83 source = search_engines[i][0]; 84 term = getParam(ref_search, search_engines[i][1]) || '(not provided)'; 85 break; 86 } 87 } 88 } 89 90 return { 91 'source': source, 92 'medium': medium, 93 'campaign': campaign, 94 'term': term, 95 'content': content 96 }; 97} 98 99function getTrafficSource(cookieName, hostname) { 100 var trafficSources = calculateTrafficSource(); 101 var source = trafficSources.source.length === 0 ? 'direct' : trafficSources.source; 102 var medium = trafficSources.medium.length === 0 ? 'none' : trafficSources.medium; 103 var campaign = trafficSources.campaign.length === 0 ? 'direct' : trafficSources.campaign; 104 var height = window.screen.availHeight; 105 var width = window.screen.availWidth 106 // exception 107 if (medium === 'referral') { 108 campaign = ''; 109 } 110 var rightNow = new Date(); 111 var value = 'source=' + source + 112 '&medium=' + medium + 113 '&campaign=' + campaign + 114 '&term=' + trafficSources.term + 115 '&content=' + trafficSources.content + 116 '&date=' + rightNow.toISOString().slice(0, 10).replace(/-/g, "") + 117 '&language=' + navigator.language + 118 '&url=' + window.location.href + 119 '&title=' + document.title + 120 '&pathName=' + window.location.pathname + 121 '&resolution=' + `${width}x${height}`; 122 123 return value; 124} 125 126// Self-invoking function 127(function () { 128 var date = new Date(); 129 var fr_date = date.getUTCFullYear().toString() + ((date.getUTCMonth() < 9) ? '0' + (date.getUTCMonth() + 1).toString() : (d
129ate.getUTCMonth() + 1).toString()) + ((date.getUTCDate() < 10) ? '0' + date.getUTCDate().toString() : date.getUTCDate().toString()); 130 var session = crumbleCookie()['FirstSession']; 131 132 // if (typeof session == 'undefined') // First time session 133 // { 134 writeLogic('FirstSession'); 135 // } 136 // else { 137 // writeLogic('ReturningSession'); 138 // } 139})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.