开发者

How to track Ajax actions via analytics function

I need to track a number of ajax-actions on my site and I have a re开发者_JAVA百科achGoal(TARGET_NAME) analytics function that I need insert to every function I want to track:

function handler_func() {
   reachGoal(TARGET_NAME);
   // Other code
   ... 
}

$(document).ready(function() {
    $('#target_id').click(handler_func);
});

What I would like to have is to be able to manage all targets from one place, something like this:

handler_func.before(function() {
    reachGoal(TARGET_NAME);
}

How can I achieve this?


You could create a decorator function:

var goalReacher = function (targetName, func) { 
    return function () {
        reachGoal(targetName);
        func.apply(this, arguments);
    };
};

var myCoolFunction = goalReacher("myTarget", function () {
    // your code here
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜