开发者

using javascript to track another javascript script?

I was just wondering whether there are any way (librarie开发者_Go百科s, frameworks, tutorials) to do javascript tracking with another script? Basically, i want to track as the user work with the site, which function gets executed with what parameters and so on, as detailed as possible.

thanks a lot!


The extent of detail you're expecting will be challenging for any solution to gather and report on without severely slowing down your scripts -- consider that, for every call, at least 1 other call would need to occur to gather this.

You'd be better to pick a few key events (mouse clicks, etc.) and track only a few details (such as time) for them. If you're using ajax, keep JavaScript and the browser oblivious and just track this on server-side.


There's a few options but I'm not sure if there are any "great" ones. I take it Firebug/IE Dev toolbar profiling won't work because you are trying to track remote user's actions.

So, one option (I'm not highly recommending for production purposes), will work in some but not all browsers.

Essentially you overwrite every function, with a wrapper that you then inject your logging. (I haven't tested this, trying to recall it from memory... hopefully in "pseudo code" you get the idea...)

//e.g. get all functions defined on the global window object
function logAll(){
  var funcs = [];
  var oldFunc;
  for(var i in window){
    try {
      if(typeof(window[i]) == 'function'){
        if(i != 'logAll'){
          funcs.push(i);
        }
      }
    } catch(ex){
      //handle as desired
    }
  }

  var x;
  for(var i in funcs){
    x = '_' + new Date().getTime();
    window[x] = window[i];//save the old function as new function
    //redefine original
    window[i] = function(){
      //do your logging here...
      //then call the real function (and pass all params along)
      call(window[x]);
    };

  }

};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜