1function saveUTM() { 2 // Don't overwrite an existing UTM cookie (first-touch attribution) 3 if (document.cookie.indexOf('humanistsuk_utm=') !== -1) { 4 cleanUpURL(); 5 return; 6 } 7 8 if (!location.search) { 9 return; 10 } 11 12 var params = location.search.slice(1).split('&'); 13 var validTerms = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']; 14 var utm = {}; 15 16 params.forEach(function (param) { 17 var parts = param.split('='); 18 if (parts.length === 2 && validTerms.indexOf(parts[0]) !== -1) { 19 try { utm[parts[0].replace('utm_', '')] = decodeURIComponent(parts[1]); } 20 catch (e) { utm[parts[0].replace('utm_', '')] = parts[1]; } 21 } 22 }); 23 24 if (Object.keys(utm).length > 0) { 25 utm.landing_page = location.pathname; 26 var expires = new Date(Date.now() + 7776000000).toUTCString(); // 90 days 27 document.cookie = 'humanistsuk_utm=' + encodeURIComponent(JSON.stringify(utm)) + ';expires=' + expires + ';path=/;secure'; 28 } 29 30 cleanUpURL(); 31} 32 33function cleanUpURL() { 34 if (history && history.replaceState && location.search) { 35 var params = location.search.slice(1).split('&'); 36 var newParams = params.filter(function (param) { 37 return param.slice(0, 4) !== 'utm_'; 38 }); 39 if (newParams.length < params.length) { 40 var search = newParams.length ? '?' + newParams.join('&') : ''; 41 var url = location.pathname + search + location.hash; 42 history.replaceState(null, null, url); 43 } 44 } 45} 46 47saveUTM();
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.