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 console.log(action); 139 } else { 140 if(formSended == false) { 141 let counters = window.counters; 142 for (var key in counters) { 143 ym(counters[key], 'reachGoal', actions[id][0]); 144 } 145 formSended = true; 146 } 147 } 148 } 149 } 150 151 function removeSentActions(actionsIds){ 152 BX.ajax.runAction('yandex:metrika.yandex_metrika.Ajax.removeEcommerceActions', { 153 data: { 154 'actionsIds': actionsIds 155 } 156 }) 157 .then(function(oResponse) { 158 oResponse.ecActions = true; 159 return oResponse; 160 }, function (oResponse) { 161 oResponse.ecActions = true; 162 return oResponse; 163 }); 164 165 BX.setCookie('ym_has_actions', '', { 166 expires: -1000, 167 path: '/' 168 }); 169 } 170 171 function addAction(type){ 172 BX.ajax.runAction('yandex:metrika.yandex_metrika.Ajax.addEcommerceActions', { 173 data: { 174 'type': type 175 } 176 }) 177 .then(function(oResponse) { 178 oResponse.ecActions = true; 179 return oResponse; 180 }, function (oResponse) { 181 oResponse.ecActions = true; 182 return oResponse; 183 }); 184 } 185 186 function hasActions(){ 187 return BX.getCookie('ym_has_actions'); 188 } 189 190})();
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.