1. Never use window.onevent, the reasons behind it, is that if using this method it will overwrite any code already defined for this event.
2. Use window.addEventListener instead as you can add one or more event listener for same one
3. To fire a rule, it needs to have event configured as direct call rule and you need to call in your custom code _satellite.track('directCallRuleId')
I have done a similar exercise where we needed to send analytics call when customer scrolled to specific section of page
- Create page load rule at PAGE TOP
- In action select custom code and enter code similar to following:
function initScrollingDetails() {
window.scrolling: {
"to25": false,
"to50": false,
"to75": false,
"to100": false
};
}
function updateScrollingDetails() {
try {
var scrollTop = window.scrollY;
var docHeight = document.body.offsetHeight;
var winHeight = window.innerHeight;
var scrollPercent = scrollTop / (docHeight - winHeight);
var scrollPercentRounded = Math.round(scrollPercent * 100);
var updated = [];
if (scrollPercentRounded <= 25 && !scrolling.to25) {
updated.push(25);
scrolling.to25 = true;
}
if (scrollPercentRounded > 25 && scrollPercentRounded <= 50 && !scrolling.to50) {
updated.push(50);
scrolling.to50 = true;
}
if (scrollPercentRounded > 50 && scrollPercentRounded <= 75 && !scrolling.to75) {
updated.push(75);
scrolling.to75 = true;
}
if (scrollPercentRounded > 75 && scrollPercentRounded <= 100 && !scrolling.to100) {
updated.push(100);
scrolling.to100 = true;
}
//we only want to send an anlytics call if scrolling has been updated
if (updated.length > 0) {
_satellite.track('scrollingUpdate', updated)
}
} catch (e) {
_satellite.logger.error('Failed while updating scolling errors', e);
}
}
try {
initScrollingDetails();
updateScrollingDetails();
window.addEventListener("scroll", updateScrollingDetails);
} catch (e) {
_satellite.logger.error('Failed while tracking scrolling', e);
}Now each time user reaches specific percentage then fire the DCR scrollingUpdate
hope this helps