var utm = 'yandex,yandex-rsy,search-yandex';(function(d, utm, c, t){ function getCookie(name) { let matches = document.cookie.match(new RegExp( "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" )); return matches ? decodeURIComponent(matches[1]) : undefined; } utm = utm ? utm : 'search'; c = c ? c : 'utm_promo'; t = t == null ? true : t; var arrUtm = [ 'search', 'yandex', 'yandex-rsy', 'google', 'mail', 'facebook', 'instagram', 'youtube', 'email', '', 'vk' ], arrUtmName = { 'search': 'Поиск', 'yandex': 'Яндекс поиск', 'yandex-rsy': 'Яндекс Рся', 'google': 'Гоогл поиск', // 'mail': 'Рассылка', // 'facebook', // 'instagram', // 'youtube', // 'email', // '', // 'vk' }, arrSearch = [ 'yandex', 'google' ], arrDop = [ 'target', 'smm', 'cpc', 'video' ], utm_promo = "10", refer = d.referrer, utm_source = utm_medium = '', url = d.documentURI.split('?')[1], start = utm.split(',').filter(function(a) { return url?.includes(a); }) if(start.length || refer) { if(url) { var utm_l = url.split('&'); utm_l.forEach(function(a,b) { if(a.includes('utm_source')) utm_source = utm_l[b].split('=')[1]; if(a.includes('utm_medium')) utm_medium = utm_l[b].split('=')[1]; }) arrUtm.forEach(function(a,b) { if(utm_source.includes(a) && a != '') { utm_promo = b+1 <= 9 ? '0'+(b+1).toString() : (b+1).toString(); } }) arrDop.forEach(function(a,b) { if(utm_medium.includes(a)) { utm_promo = utm_promo.toString() + b; } }) if(utm_promo !== "10") { d.cookie = '_utm_promo_plugin = '+utm_promo+'; max-age=-1; path=/;'; d.cookie = '_utm_promo_plugin = '+utm_promo+'; max-age=86400; path=/;'; } } if(refer && url == undefined && getCookie('_utm_promo_plugin') == undefined) { search = utm.split(',').filter(function(a) { return a.includes('search') }).shift(); if(search) search = search.split('-')[1]; // console.log(utm, search); // search = search[0].split('-')[1]; utm_promo = '9'; arrSearch.forEach(function(a,b){ if(refer.includes(a) && !search) utm_promo = utm_promo + b.toString(); if(refer.includes(a) && search == a) utm_promo = utm_promo + b.toString(); }); if(utm_promo !== "10") { d.cookie = '_utm_promo_plugin = '+utm_promo+'; max-age=-1; path=/;'; d.cookie = '_utm_promo_plugin = '+utm_promo+'; max-age=86400; path=/;'; } } } if(getCookie('_utm_promo_plugin')) { utm_promo = getCookie('_utm_promo_plugin'); } const obs = new MutationObserver(function(data) { var arr = Array.prototype.slice.call(d.forms) var newArr = arr.filter(function(a) { return a.querySelector('[name=utm_promo]') ? false : true; }) var input = d.createElement('input'); input.type = 'hidden', input.name = 'utm_promo', input.value = utm_promo; for (const i of newArr) { i.append(input.cloneNode(true)); addDopInput(i, input); } input = null; newArr = null; arr = null; }) obs.observe(d.body, { 'childList': true, 'subtree': true, 'attributeOldValue': true, }) if(d.forms.length > 0) { var input = d.createElement('input'); input.type = 'hidden', input.name = 'utm_promo', input.value = utm_promo; for (const i of d.forms) { i.append(input.cloneNode(true)); addDopInput(i, input); // i.addEventListener('submit',function(e) { // if(this.querySelectorAll('input')[0].value != '') { // this.querySelectorAll('input')[0].value = this.querySelectorAll('input')[0].value + " \n(Код клиента: "+utm_promo+")"; // } // }) } input = null; } function addDopInput(i, input) { var utm_num = utm_promo; if(utm_name = i.querySelector('[data-sid=utm_name]')) { utm_name.value = arrUtmName[arrUtm[utm_num]] ?? 'Прямой заход'; } else { inputName = input.cloneNode(true); inputName.name = 'utm_name'; inputName.value = arrUtmName[arrUtm[utm_num]] ?? 'Прямой заход'; i.append(inputName); } if(utm_value = i.querySelector('[data-sid=utm_value]')) { utm_value.value = arrUtm[utm_num]; } else { inputValue = input.cloneNode(true); inputValue.name = 'utm_value'; inputValue.value = arrUtm[utm_num]; i.append(inputValue); } if(refer.includes('yandex')) { if(utm_refer = i.querySelector('[data-sid=utm_refer]')) { utm_refer.value = arrUtm[utm_num]; } else { inputRefere = input.cloneNode(true); inputRefere.name = 'utm_refer'; inputRefere.value = 'Переход с поиска'; i.append(inputRefere); } } if(utms = i.querySelector('[name=ORDER_PROP_21]')) { var name = arrUtmName[arrUtm[utm_num]] ?? 'Прямой заход'; var referer = refer.includes('yandex') ? 'Переход с поиска' : ''; var value = arrUtm[utm_num]; var stringUtms = "Название метки: "+name+"\n | Значение метки: "+value+"\n | Заход: "+referer; utms.value = stringUtms; } } // var elem = ''; // elem = document.querySelector('.'+c); // if(!elem) { // elem = document.querySelector('#'+c); // } // if(elem && t) { // elem.innerHTML = 'Промокод: '+utm_promo+''; // } // if(elem && !t) { // elem.innerText = utm_promo; // } }(document, utm, el = '', vievText = ''))