1document.addEventListener("DOMContentLoaded", function() { 2 // Parameters to capture 3 const utmParameters = ['eid', 'utm_medium', 'utm_source', 'utm_term', 'utm_content', 'utm_campaign']; 4 5 // Function to extract URL parameters 6 function getURLParameters() { 7 const params = new URLSearchParams(window.location.search); 8 const capturedParams = {}; 9 10 utmParameters.forEach(param => { 11 if (params.has(param)) { 12 capturedParams[param] = params.get(param); 13 } 14 }); 15 16 return capturedParams; 17 } 18 19 // Function to append parameters to the URL 20 function appendParamsToURL(url, params) { 21 let urlObj = new URL(url, window.location.origin); 22 const urlSearchParams = new URLSearchParams(urlObj.search); 23 24 // Add only non-duplicate parameters 25 for (let key in params) { 26 if (!urlSearchParams.has(key)) { 27 urlSearchParams.append(key, params[key]); 28 } 29 } 30 31 urlObj.search = urlSearchParams.toString(); 32 return urlObj.toString(); 33 } 34 35 // Get the captured parameters from the current URL 36 const capturedParams = getURLParameters(); 37 if (Object.keys(capturedParams).length === 0) return; // Exit if no relevant UTM parameters 38 39 // Find all anchor tags and update their href attributes 40 const anchorTags = document.querySelectorAll("a"); 41 42 anchorTags.forEach(anchor => { 43 let href = anchor.getAttribute("href"); 44 45 // Ignore empty, anchor-only, or javascript links 46 if (!href || href.startsWith("#") || href.startsWith("javascript")) return; 47 48 // Append parameters to the URL 49 const updatedHref = appendParamsToURL(href, capturedParams); 50 51 // Update the href attribute 52 anchor.setAttribute("href", updatedHref); 53 }); 54});
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.