1(function (Drupal) { 2 Drupal.behaviors.setUTMReferralFields = { 3 attach: function (context, settings) { 4 5 // Helper to get a cookie by name 6 function getCookie(name) { 7 const value = `; ${document.cookie}`; 8 const parts = value.split(`; ${name}=`); 9 if (parts.length === 2) return parts.pop().split(';').shift(); 10 } 11 12 // Get cookies once 13 const referral = getCookie('nemetschek_referral') || ''; 14 const utmSource = getCookie('nemetschek_utm_source') || ''; 15 const utmMedium = getCookie('nemetschek_utm_medium') || ''; 16 const utmCampaign = getCookie('nemetschek_utm_campaign') || ''; 17 18 // Function to set a field if it exists in current context 19 function setFieldValue(name, value) { 20 const input = context.querySelector(`input[name="${name}"]`); 21 if (input && !input.dataset.utmSet) { 22 input.value = value; 23 input.dataset.utmSet = 'true'; 24 console.log(`â Set ${name} to: "${value}"`); 25 return true; 26 } 27 return false; 28 } 29 30 // Try to set all fields in current context 31 setFieldValue('referral', referral); 32 setFieldValue('utm_source', utmSource); 33 setFieldValue('utm_medium', utmMedium); 34 setFieldValue('utm_campaign', utmCampaign); 35 } 36 }; 37})(Drupal);
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.