使用 Jquery 循环元素并调用 Omniture s.tl() 函数进行跟踪
我有一个包含项目列表的页面。每个项目都有一个立即打印链接 (a.printMe
) 来打印每个项目。在列表的末尾,有一个打印所有链接 (a.printAll
),用于打印所有项目。
我想跟踪某个项目的打印次数。如果点击 a.printAll
链接,那么我会将所有项目的跟踪值发送到 Omniture。我将跟踪字符串添加到单个项目的 a.printMe
href 属性中,并使用以下函数进行跟踪:
$('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');
}
在 IE 6-8 中,当我单击 a.printAll.据我了解,在 Firefox 中,
click
事件仅适用于 input
元素。所以我实现了以下内容:
$('a.printMe').each(function() {
var trackingCode = $(this).attr('href').replace('#','');
track(trackingCode);
});
但只有最后一个项目的值被发送到 Omniture。有没有人实施过类似的事情并工作?
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 IE 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有第三个参数,该函数会尝试读取 href,但由于失败,因此无法按预期工作。
作为旁注,我想指出的是,最好只添加一个自定义链接值“all”,而不是为每个链接发送一个点击。如此多的服务器调用只会导致额外的流量(可以更好地利用),并且最终可能会得到不可靠的数据(某些请求可能会失败)。
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).
修复:
s.tl(true, 'o');
应包含value
作为最后一个参数。所以最终结果应该是
s.tl(true, 'o', value);
FIXED:
s.tl(true, 'o');
should includevalue
as the last param.So end result should be
s.tl(true, 'o', value);