Отложенная загрузка метрики и скриптов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var loadedMetrica = false; | |
window.addEventListener('scroll', loadMetrica); | |
window.addEventListener('click', loadMetrica); | |
window.addEventListener('mousemove', loadMetrica); | |
function loadMetrica() { | |
if (!loadedMetrica) { | |
setTimeout(function() { | |
/* ТУТ ВАШ КОД И СКРИПТЫ, метрика например*/ | |
},500); | |
} | |
loadedMetrica = true; | |
window.removeEventListener('scroll', loadMetrica); | |
window.removeEventListener('click', loadMetrica); | |
window.removeEventListener('mousemove', loadMetrica); | |
}; | |
// Реагирует на события скролла, свайпа, движения мышкой и затем срабатывает. | |
var fired = false; | |
window.addEventListener('scroll', () => { | |
if (fired === false) { | |
fired = true; | |
setTimeout(() => { | |
// Сюда вставляете метрики без тегов <script> | |
}, 1000) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment