开发者

Loop elements with Jquery and call Omniture s.tl() function to track

i have a page with a list of items. Each item has a print now link (a.printMe) to print each item. At the end of the list, there's a print all link (a.printAll) to print all items.

I want to track number of times an item was printed. If a.printAll link is clicked, then i will send all the item's tracking value to Omniture. I added tracking string into individual item's a.printMe href attribute and track with the following functions:

$('a.printMe').click(function() {
   var value = $(this).attr('href');
   track(value);
});

$('a.printAll').click(function() {
   $('a.printMe').each(function() {
      this.click();
   }); // works in IE only. IE 6-8
}); 

function track(value) {
   var s = s_gi('account');
   s.prop10 = value;
   s.linkTrackVars = 'prop10';
   s.tl(true, 'o');
}

In 开发者_如何学PythonIE 6-8, all the values are posting fine when i clicked on a.printAll. I understand that in Firefox, click event is only for input elements. So i implemented the below:

$('a.printMe').each(function() {
   var trackingCode = $(this).attr('href').replace('#','');
   track(trackingCode);
});

But only the last item's value is sent to Omniture. Has anyone implemented something like this and work?


If there is no third argument, the function tries to read the href, but since this fails it doesn't work as intended.

As a side note, I would like to point out that simply adding a custom link value of "all" instead of sending one hit for each link would be preferred. With that many server calls you just cause extra traffic (which could be used better) and might end up with unreliable data (some requests might fail).


FIXED: s.tl(true, 'o'); should include value as the last param.

So end result should be s.tl(true, 'o', value);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜