Last active
December 30, 2015 03:29
-
-
Save lamp/7769533 to your computer and use it in GitHub Desktop.
Javascript Snippet to allow third parties to attach tracking events.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); | |
}); | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?