1/* 2 Tramplin Studio - development of modules for OpenCart 3 Yandex Metrika v1.3 4*/ 5 6var yaCounterInited = false; 7var yaEcommerceInited = false; 8var TSdataLayer = []; 9 10$.fn.extend({ 11 TSYandexMetrika: function(options) { 12 var options = $.extend({ 13 counter: { 14 counter_id: 0, 15 counter_data: { 16 webvisor: true, 17 clickmap: true, 18 trackLinks: true, 19 trackHash: false, 20 accurateTrackBounce: 15000, 21 ecommerce: false, 22 triggerEvent: true, 23 }, 24 userParams: false, 25 ecommerce: false, 26 goals: false, 27 replacePhones: false, 28 cdn: false, 29 }, 30 }, options); 31 32 33 34 if (options.counter && options.ecommerce === undefined) { 35 36 // enable trigger of init 37 options.counter.counter_data.triggerEvent = true; 38 39 40 // yaCounter init 41 initCounter(options.counter); 42 43 44 // yaCounter inited 45 $(document).on('yacounter' + options.counter.counter_id + 'inited', function () { 46 console.log('yaCounter: Counter inited'); 47 yaCounterInited = true; 48 49 // send User Params 50 if (options.counter.userParams) { 51 sendUserParams(); 52 } 53 54 // replace Phones 55 if (options.counter.replacePhones) { 56 replacePhones(); 57 } 58 59 // tracking eCommerce 60 if (options.counter.ecommerce) { 61 initEcommerce(options.counter.ecommerce); 62 } 63 64 // init Goals 65 if (options.counter.goals) { 66 initGoals(); 67 } 68 69 }); 70 71 } else if (options.ecommerce) { 72 73 // send eCommerce data after reload 74 sendEcommerceAfterReload(options.ecommerce); 75 76 } else { 77 78 console.log('yaCounter: Error - not Params'); 79 80 } 81 82 83 84 function initCounter(counter) { 85 console.log('yaCounter: Counter init'); 86 87 var counter_url = (!options.counter.cdn) ? 'https://mc.yandex.ru/metrika/tag.js' : 'https://cdn.jsdelivr.net/npm/yandex-metrica-watch/tag.js'; 88 89 $('head').append('<noscript><div><img src="https://mc.yandex.ru/watch/' + counter.counter_id + '" style="position:absolute; left:-9999px;" alt="" /></div></noscript>'); 90 91 (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; 92 m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) 93 (window, document, "script", counter_url, "ym"); 94 95 ym(counter.counter_id, "init", counter.counter_data); 96 } 97 98 99 function sendUserParams() { 100 $.ajax({ 101 url: 'index.php?route=extension/analytics/ts_yandex_metrika/getUserParams', 102 method: 'post', 103 dataType: 'json', 104 data: {data: ''}, 105 cache: false, 106 success: function(json) { 107 if (!json.error) { 108 //console.log(json.userParams); 109 ym(options.counter.counter_id, 'setUserID', json.userParams.UserID); 110 ym(options.counter.counter_id, 'userParams', json.userParams); 111 112 console.log('yaCounter: userParams sended'); 113 } 114 } 115 }); 116 } 117 118 119 function replacePhones() { 120 ym(options.counter.counter_id, 'replacePhones'); 121 122 console.log('yaCounter: Phones replaced'); 123 } 124 125 126 function initGoals() { 127 $.ajax({ 128 url: 'index.php?route=extension/analytics/ts_yandex_metrika/getGoals', 129 method: 'post', 130 dataType: 'json', 131 data: {data: ''}, 132 cache: false, 133 success: function(json) { 134 if (!json.error) { 135 $.each( json.goals, function(key, goal) { 136 $(document).on(goal.event, goal.element, function () { 137 ym(options.counter.counter_id, 'reachGoal', goal.target_name, goal.goalParams); 138 console.log('yaCounter: Goal "' + goal.target_name + '" achieved'); 139 }); 140 }); 141 142 console.log('yaCounter: Goals inited'); 143 } 144 } 145 }); 146 } 147 148 var initEcommerceTimer; 149 function initEcommerce(mode) { 150 initEcommerceTimer = setTimeout(function() { 151 if (!yaCounterInited) { 152 initEcommerce(mode); 153 } else { 154 yaEcommerceInited = true; 155 console.log('yaCounter: eCommerce inited'); 156 checkEcommerce(mode); 157 clearTimeout(initEcommerceTimer); 158 } 159 }, 100); 160 } 161 162 var sendEcommerceAfterReloadTimer; 163 function sendEcommerceAfterReload(ecommerce) { 164 sendEcommerceAfterReloadTimer = setTimeout(function() { 165 if (!yaCounterInited || !yaEcommerceInited) { 166 sendEcommerceAfterReload(ecommerce); 167 } else { 168 sendEcommerceData(ecommerce); 169 clearTimeout(sendEcommerceAfterReloadTimer); 170 } 171 }, 100); 172 } 173 174 function checkEcommerce(mode) { 175 if (parseInt(mode.timer.status)) { 176 var eCommerceModeTimerInterval = parseInt(mode.timer.interval) * 1000; 177 setInterval(function() { 178 $.ajax({ 179 url: 'index.php?route=extension/analytics/ts_yandex_metrika/checkEcommerce', 180 method: 'get', 181 dataType: 'json', 182 success: function(json) { 183 if (json.success) { 184 $.each( json.ecommerce, function(key, value) { 185 sendEcommerceData(value.ecommerce); 186 }); 187 $.ajax({ url: 'index.php?route=extension/analytics/ts_yandex_metrika/ecommerceSended', method: 'get' }); 188 } 189 } 190 }); 191 }, eCommerceModeTimerInterval); 192 } 193 } 194 195 function sendEcommerceData(data) { 196 //console.log({ecommerce: data}); 197 window.TSdataLayer.push({ecommerce: data}); 198 console.log('yaCounter: eCommerce sended'); 199 } 200 201 } 202});
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.