1(function ($) { 2 $(function () { 3 // check if any utm parameters are set in the query string. 4 var utm_params = [ 5 'utm_id', 6 'utm_source', 7 'utm_medium', 8 'utm_campaign', 9 'utm_term', 10 'utm_content', 11 ]; 12 13 var utm_values = {}; 14 var utm_values_set = false; 15 16 // read the querystring and see if any of utm_params exist. 17 var querystring = window.location.search.substring(1); 18 var querystring_params = querystring.split('&'); 19 for (var i = 0; i < querystring_params.length; i++) { 20 var param = querystring_params[i].split('='); 21 if (utm_params.indexOf(param[0]) > -1) { 22 utm_values[param[0]] = param[1]; 23 utm_values_set = true; 24 } 25 } 26 27 // If no utm values found, get them from localstorage 28 if (!utm_values_set) { 29 var storedUtmValues = localStorage.getItem('kisaco_utm_values'); 30 if (storedUtmValues) { 31 try { 32 utm_values = JSON.parse(storedUtmValues); 33 utm_values_set = Object.keys(utm_values).some((key) => 34 utm_params.includes(key) 35 ); 36 } catch (e) { 37 console.error('Error parsing stored UTM values: ', e); 38 } 39 } 40 } 41 42 // store the utm_values into localstorage. 43 // we don't care if the values are already set, we want to overwrite them. 44 if (utm_values_set) { 45 localStorage.setItem('kisaco_utm_values', JSON.stringify(utm_values)); 46 // Check if kisaco_utm_ft_values already exists, if not, set it. 47 if (!localStorage.getItem('kisaco_utm_ft_values')) { 48 localStorage.setItem( 49 'kisaco_utm_ft_values', 50 JSON.stringify(utm_values) 51 ); 52 } 53 } 54 55 // Read UTM params from local storage 56 var utmParamsFromLocalStorage = localStorage.getItem('kisaco_utm_values'); 57 var utmFtParamsFromLocalStorage = localStorage.getItem( 58 'kisaco_utm_ft_values' 59 ); 60 61 // If UTM params are set in local storage, use them 62 if (utmParamsFromLocalStorage !== null) { 63 utm_values = JSON.parse(utmParamsFromLocalStorage); 64 } 65 66 // Prepare first-touch UTM values for appending 67 var utm_ft_values = {}; 68 if (utmFtParamsFromLocalStorage !== null) { 69 utm_ft_values = JSON.parse(utmFtParamsFromLocalStorage); 70 } 71 72 // Prefix all first-touch keys with 'utm_ft_' 73 var utm_ft_values_prefixed = {}; 74 for (var key in utm_ft_values) { 75 // Ensure the prefix is added correctly without duplicating 'utm_' 76 var newKey = key.replace('utm_', 'utm_ft_'); 77 utm_ft_values_prefixed[newKey] = utm_ft_values[key]; 78 } 79 80 // Apply UTM params to all relevant links 81 $('a').each(function () { 82 var href = this.href; 83 84 // Check if href matches the platforms. 85 if (href.match(/events\.kisacoresearch\.com|hubspot|swoogo/)) { 86 // Build UTM param string for both current and first-touch values 87 var utmStr = 88 $.param(utm_values) + '&' + $.param(utm_ft_values_prefixed); 89 90 // Attach UTM params to href 91 if (href.includes('?')) { 92 this.href = href + '&' + utmStr; 93 } else { 94 this.href = href + '?' + utmStr; 95 } 96 } 97 }); 98 }); 99})(jQuery); 100;
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.