Skip to content

Instantly share code, notes, and snippets.

@codylindley
Created March 15, 2012 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codylindley/2047418 to your computer and use it in GitHub Desktop.
Save codylindley/2047418 to your computer and use it in GitHub Desktop.
Track Clicks
trackIt: function(p,callback,evil){
//mpg window.mpq.track(label,params{ });
//gaq window._gaq.push('_trackEvent',category,action,label,value);
var g = false, m = false;
var yesCallback = arguments[1] !== undefined && typeof arguments[1] === 'function';
//window._gaq.push('_trackEvent',p.category,p.action,p.label,p.value);
window._gaq.push(['_trackEvent',p.category,p.action,p.label,p.value]);
window._gaq.push(function(){ g = true; });
window.mpq.track(p.category,p,function(){ m = true; });
//only call... callback if its actually set
if(yesCallback && arguments[2] === undefined){
var check = setInterval (function(){
if(g == true && m == true){
clearInterval(check);
callback();
}
},10);
window.setTimeout(callback,1000);
}else if(yesCallback && arguments[2] === 'evil'){
var sleep = function(d){var s = new Date().getTime();while (new Date().getTime() < s + d);};
sleep(1000);
callback();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment