I have this snippet of tracking (below) I was looking at why it's possibly making 4 calls each time you click "addToCart.gif". i added "console.log()" to each if case - and noticed it's looping.
Is this because it's calling the same function before the function has ended? is there a better way of doing this that you can advise?
Thank you so much!
<script type="text/javascript">// <![CDATA[
var href = location.href
if(href != "" && href.indexOf("/product/") > 0){
mboxDefine("clicked-addToCart","clicked-addToCart")
var count=0;
function addToCartClickTracking(){
if(typeof jQuery == 'function' && jQuery(".add-to-cart[src*='addToCart.gif']").length > 0 && count < 10){
console.log("adding click tracking")
jQuery(".add-to-cart[src*='addToCart.gif']").click(function(){
mboxUpdate("clicked-addToCart")
});
count=10;
} else {
console.log("trying again")
count++;
setTimeout(addToCartClickTracking,400);
}
}
addToCartClickTracking();
}
// ]]>
</script>

