I need the javascript to load after the user scrolls. Right now I have a .phtml file that just has this,
<div id="razoyo-gtm-user-code" style="display:none;" data-mage-init='{ "razoyoGlobalUserCode": { "pageType": "<?= $block->escapeJs($block->getPageType()); ?>"} }'>
Which loads razoyoGlobalUserCode as soon as the page is done loading. But I need the file to load after the user scrolls. So I've tried this:
<script>
var razoyo = document.createElement('div');
razoyo.id = 'razoyo-gtm-user-code';
razoyo.style = 'display:none';
razoyo.setAttribute("data-mage-init", '{ "razoyoTest": { "pageType": "<?= $block->escapeJs($block->getPageType()); ?>"} }');
document.addEventListener('scroll', function(e) {
document.head.appendChild(razoyo);
});
</script>
However this doesnt fix the issue at all. If someone has any advice on what I can do I would appreciate it a lot. Thanks.