Skip to content

Commit

Permalink
feat(dev): lazy loading of the counter (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
eugena committed Apr 30, 2024
1 parent db5fe25 commit 182af87
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions acesta/templates/include/metrika.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
<script type="text/javascript" >
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
ym(79321300, "init", {clickmap:true, trackLinks:true,accurateTrackBounce:true,webvisor:true});
<script type="text/javascript">
( function () {
'use strict';

var loadedMetrica = false,
metricaId = 79321300,
timerId;
W
if ( navigator.userAgent.indexOf( 'YandexMetrika' ) > -1 ) {
loadMetrica();
} else {
window.addEventListener( 'scroll', loadMetrica, {passive: true} );
window.addEventListener( 'touchstart', loadMetrica );
document.addEventListener( 'mouseenter', loadMetrica );
document.addEventListener( 'click', loadMetrica );
document.addEventListener( 'DOMContentLoaded', loadFallback );
}

function loadFallback() {
timerId = setTimeout( loadMetrica, 1000 );
}

function loadMetrica( e ) {
if ( e && e.type ) {
console.log( e.type );
} else {
console.log( 'DOMContentLoaded' );
}
if ( loadedMetrica ) {
return;
}

(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; 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)}) (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
ym( metricaId, "init", { clickmap:true, trackLinks:true,accurateTrackBounce:true,webvisor:true });

loadedMetrica = true;

clearTimeout( timerId );
window.removeEventListener( 'scroll', loadMetrica );
window.removeEventListener( 'touchstart', loadMetrica );
document.removeEventListener( 'mouseenter', loadMetrica );
document.removeEventListener( 'click', loadMetrica );
document.removeEventListener( 'DOMContentLoaded', loadFallback );
}
} )()
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/79321300" style="position:absolute; left:-9999px;" alt="" /></div></noscript>

0 comments on commit 182af87

Please sign in to comment.