Reputation: 16501
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');
});
Upvotes: 1
Views: 129
Reputation: 30666
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');
});
Upvotes: 2