|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
const getUtmParameter = (sParam) => { const url = window.location.search.substring(1); const urlVariables = url.split('&'); for (let i = 0; i < urlVariables.length; i++) { const variables = urlVariables[i].split('='); if (variables[0] === sParam) { return variables[1]; } } }; const $utmArr = [ "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_referrer", ]; $utmArr.forEach(function (el, index, array) { let inp = document.querySelector(`[name="${el}"]`); if (inp) { try { inp.setAttribute(el, getUtmParameter(el)); } catch(e){ console.log(e); } } }); |
