setInterval in a Condition?
Hey All,
I sometimes need to tell my rules to wait for a certain object to pop into existence (either a JS object or something of that nature). I can normally do this using setInterval in a Rule Event, and then the rule fires when needed Yay!
Can I do something similar in a Condition, but say with DOM Loaded as the Rule Event? I can't seem to get it to work right - I'm not a dev by trade so if I'm using something basic incorrectly here feel free to yell at me:
var IntervalIterator = 0;
var MyInterval = setInterval(
function(){
var DataLayer = window.pageData;
if(typeof DataLayer !== "undefined" && DataLayer !== null && DataLayer !==""){
clearInterval(MyInterval);
return true //Tell the condition that it is true now
}else if (IntervalIterator == 5){ //ensure we don't have a runaway function
clearInterval(MyInterval);
return false // The condition fails because object never loaded
}else{
IntervalIterator++;
}
}, 1000); //end setInterval