Skip to content

Instantly share code, notes, and snippets.

@lamp
Last active December 30, 2015 03:29
Show Gist options
  • Save lamp/7769533 to your computer and use it in GitHub Desktop.
Save lamp/7769533 to your computer and use it in GitHub Desktop.
Javascript Snippet to allow third parties to attach tracking events.
(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'http://cdn.mark.reevoo.com/assets/reevoo_mark.js';
var s = document.getElementById('reevoomark-loader');
s.parentNode.insertBefore(script, s);
})();
afterReevooMarkLoaded = [function(){
ReevooApi.load('YOUR_TRKREF_HERE', function(retailer){
var unrendered_badge_count = document.getElementsByClassName('reevoomark').length;
//include reputation badges
unrendered_badge_count += document.getElementsByClassName('reevoo_reputation').length;
retailer.init_badges();
retailer.init_reevoo_reputation_badges();
var interval = window.setInterval(function(){
var rendered_badges = document.getElementsByClassName('reevoomark_badge');
if(rendered_badges.length == unrendered_badge_count){
// attach tracking to each of the new elements
// each badge has a data-sku and a data-score to help
// you identify the correct badge.
window.clearInterval(interval);
}
}, 200);
});
}];
@mikekr1
Copy link

mikekr1 commented Dec 3, 2013

var unrendered_badge_length = document.getElementsByClassName('reevoomark').length;

That's a count of unrendered badges right? So maybe unrendered_badge_count?

Also, could there not be other elements on the page with the class name of reevoomark which could offset the count and mean that the tracking never gets added?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment