1

I have 4 click events that use nearly the same tracking code so I am thinking that this code would be better residing in a function, what I would like to know though is how do I set certain values that are different from event to event? Do I need to pass parameters into the new function that take on the value?

My click event code is:

$('a.close', '#contents').on('click', function(){
    s=s_gi('myapp');
    s.linkTrackVars="None"; 
    s.linkTrackEvents="None";
    s.tl(this,'o','myapp_fb:new_story:a');
});

$('a.next', '#contents').on('click', function(){
    s=s_gi('myapp');
    s.linkTrackVars="None"; 
    s.linkTrackEvents="None";
    s.tl(this,'o','myapp_fb:new_story:b');
});

$('a.prev', '#contents').on('click', function(){
    s=s_gi('myapp');
    s.linkTrackVars="None"; 
    s.linkTrackEvents="None";
    s.tl(this,'o','myapp_fb:new_story:c');
}):

$('a.share', '#contents').on('click', function(){
    s=s_gi('myapp');
    s.linkTrackVars="None"; 
    s.linkTrackEvents="None";
    s.tl(this,'o','myapp_fb:new_story:d');
});
2
  • Where's s coming from? Commented Feb 15, 2012 at 14:29
  • s is coming from a separate js file supplied by omniture Commented Feb 15, 2012 at 14:34

1 Answer 1

2

You could do something like that:

var clickHandler = function(value) {
    s=s_gi('myapp');
    s.linkTrackVars="None"; 
    s.linkTrackEvents="None";
    s.tl(this,'o',value);
}

$('a.close', '#contents').on('click', function(){
    clickHandler('myapp_fb:new_story:a');
});
Sign up to request clarification or add additional context in comments.

1 Comment

I was going to go the jQuery plugin route, but that's a perfectly reasonable refactor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.