1(function (){ 2 3 if (typeof BX === 'undefined' || typeof BX.ajax === 'undefined' || window.ymecInited) { 4 return; 5 } 6 7 window.ymecInited = true; 8 9 let hasActiveRequest = false; 10 11 12 BX.ready(function(){ 13 requestEcommerceActions(true); 14 15 if (typeof jQuery === 'function') { 16 jQuery(document).on('ajaxSuccess', function(r){ 17 if (hasActions()) { 18 requestEcommerceActions(); 19 } 20 }); 21 } 22 23 24 25 BX.addCustomEvent('onAjaxSuccess', function(oResponse, r2, r3){ 26 //if (typeof oResponse !== 'undefined' && oResponse && !oResponse.ecActions && oResponse.status !== 'error') { 27 if (hasActions()) { 28 requestEcommerceActions(); 29 } 30 //} 31 }); 32 33 document.addEventListener("DOMContentLoaded", function() { 34 if (typeof jQuery === 'function') { 35 jQuery(document).on('shown.bs.modal', function (e) { 36 let form = e.target.querySelector('form'); 37 38 if ((form !== undefined) && (form !== null)) { 39 let counters = window.counters; 40 for (var key in counters) { 41 ym(counters[key], 'reachGoal', 'ym-open-leadform'); 42 } 43 } 44 }); 45 } 46 47 if (typeof $.magnificPopup === "object") { 48 $.magnificPopup.instance.open = function (data) { 49 $.magnificPopup.proto.open.call(this, data); 50 51 let form = $.magnificPopup.instance.wrap[0].querySelector('form'); 52 if ((form !== undefined) && (form !== null)) { 53 let counters = window.counters; 54 for (var key in counters) { 55 ym(counters[key], 'reachGoal', 'ym-open-leadform'); 56 } 57 } 58 }; 59 } 60 61 if (typeof $.fancybox === 'object') { 62 $.fancybox.defaults.afterShow = function (fancy) { 63 let form = fancy.$refs.container[0].querySelector('form'); 64 65 if ((form !== undefined) && (form !== null)) { 66 let counters = window.counters; 67 for (var key in counters) { 68 ym(counters[key], 'reachGoal', 'ym-open-leadform'); 69 } 70 } 71 }; 72 } 73 74 if (typeof Fancybox === 'function') { 75 Fancybox.bind('[data-fancybox]', { 76 on: { 77 done: (fancybox, slide) => { 78 let form = slide.$content.querySelector('form'); 79 80 if ((form !== undefined) && (form !== null)) { 81 let counters = window.counters; 82 for (var key in counters) { 83 ym(counters[key], 'reachGoal', 'ym-open-leadform'); 84 } 85 } 86 } 87 } 88 } 89 ); 90 }; 91 92 }); 93 }); 94 95 function requestEcommerceActions(processInstant){ 96 if (hasActiveRequest) { 97 return; 98 } 99 100 hasActiveRequest = true; 101 BX.ajax.runAction('yandex:metrika.yandex_metrika.Ajax.getEcommerceActions') 102 .then(function(oResponse) { 103 if (oResponse.status === 'success') { 104 if (typeof oResponse.data.actions !== 'undefined') { 105 const actions = oResponse.data.actions; 106 const actionsIds = Object.keys(actions); 107 if (processInstant) { 108 processActions(actions); 109 removeSentActions(actionsIds); 110 hasActiveRequest = false; 111 } else { 112 setTimeout(function () { 113 processActions(actions); 114 removeSentActions(actionsIds); 115 hasActiveRequest = false; 116 }, 2000); 117 } 118 } 119 } 120 121 oResponse.ecActions = true; 122 return oResponse; 123 }, function (oResponse) { 124 oResponse.ecActions = true; 125 hasActiveRequest = false; 126 return oResponse; 127 }); 128 } 129 130 function processActions(actions){ 131 let formSended = false; 132 133 for (let id in actions) { 134 135 let action = actions[id]; 136 if(Object.hasOwn(action, 'ecommerce')) 137 window[window.dataLayerName].push(action); 138 else { 139 if(formSended == false) { 140 let counters = window.counters; 141 for (var key in counters) { 142 ym(counters[key], 'reachGoal', actions[id][0]); 143 } 144 formSended = true; 145 } 146 } 147 } 148 } 149 150 function removeSentActions(actionsIds){ 151 BX.ajax.runAction('yandex:metrika.yandex_metrika.Ajax.removeEcommerceActions', { 152 data: { 153 'actionsIds': actionsIds 154 } 155 }) 156 .then(function(oResponse) { 157 oResponse.ecActions = true; 158 return oResponse; 159 }, function (oResponse) { 160 oResponse.ecActions = true; 161 return oResponse; 162 }); 163 164 BX.setCookie('ym_has_actions', '', { 165 expires: -1000, 166 path: '/' 167 }); 168 } 169 170 function addAction(type){ 171 BX.ajax.runAction('yandex:metrika.yandex_metrika.Ajax.addEcommerceActions', { 172 data: { 173 'type': type 174 } 175 }) 176 .then(function(oResponse) { 177 oResponse.ecActions = true; 178 return oResponse; 179 }, function (oResponse) { 180 oResponse.ecActions = true; 181 return oResponse; 182 }); 183 } 184 185 function hasActions(){ 186 return BX.getCookie('ym_has_actions'); 187 } 188 189})();
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.