Skip to content

Instantly share code, notes, and snippets.

@codylindley
Created March 15, 2012 22:40
Show Gist options
  • Select an option

  • Save codylindley/2047418 to your computer and use it in GitHub Desktop.

Select an option

Save codylindley/2047418 to your computer and use it in GitHub Desktop.

Revisions

  1. codylindley created this gist Mar 15, 2012.
    34 changes: 34 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    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();

    }

    }