var _paq = window._paq = window._paq || []; /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ _paq.push(["disableCookies"]); _paq.push(['enableLinkTracking']); _paq.push(['enableHeartBeatTimer', 5]); _paq.push(['trackPageView']); _paq.push(['trackAllContentImpressions']); _paq.push(['trackVisibleContentImpressions', true, 250]); (function() { var u="//example.com"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); })(); var allTracks = document.getElementsByClassName("matomoTrackContent"); var executed = false; window.addEventListener("scroll", function() { if(executed) return; console.log("scrolled"); console.log(isVisible(allTracks[0]) + allTracks[0].getAttribute("data-content-name") + allTracks[0].getAttribute("data-content-piece")); if(isVisible(allTracks[0])) { _paq.push(['trackContentImpression', allTracks[0].getAttribute("data-content-name"), allTracks[0].getAttribute("data-content-piece"), ""]); _paq.push(['trackEvent', 'eCommerce', 'Add to Wishlist', 'Smartphone', 1000]); executed = true; } }); function isVisible(elem) { if (!(elem instanceof Element)) throw Error('DomUtil: elem is not an element.'); const style = getComputedStyle(elem); if (style.display === 'none') return false; if (style.visibility !== 'visible') return false; if (style.opacity < 0.1) return false; if (elem.offsetWidth + elem.offsetHeight + elem.getBoundingClientRect().height + elem.getBoundingClientRect().width === 0) { return false; } const elemCenter = { x: elem.getBoundingClientRect().left + elem.offsetWidth / 2, y: elem.getBoundingClientRect().top + elem.offsetHeight / 2 }; if (elemCenter.x < 0) return false; if (elemCenter.x > (document.documentElement.clientWidth || window.innerWidth)) return false; if (elemCenter.y < 0) return false; if (elemCenter.y > (document.documentElement.clientHeight || window.innerHeight)) return false; let pointContainer = document.elementFromPoint(elemCenter.x, elemCenter.y); do { if (pointContainer === elem) return true; } while (pointContainer = pointContainer.parentNode); return false; }