问题描述
我想,当用户使用Omniture的自定义链接跟踪提交表单跟踪。此功能利用内置的功能 s.tl()
。一个典型的设置是这样的:
I want to track when a user submits a form using Omniture's "Custom Link Tracking". This feature utilizes the built-in function s.tl()
. A typical setup looks like this:
$('a#submit').click(function () {
s.trackExternalLinks = false;
s.linkTrackVars = 'events,prop1';
s.linkTrackEvents = s.events = 'event1';
s.prop1 = s.pageName;
s.tl(this, 'o', 'Form Submitted');
});
这code正常工作时,例如链接(<一个ID =提交>
)被点击。再说了,相反,我们要调用一个函数来触发该链接跟踪:
This code works fine when the example link (<a id="submit">
) is clicked. Say, instead, we want to call a function to trigger the link tracking:
// function to track custom link
var trackLink = function() {
s.trackExternalLinks = false;
s.linkTrackVars = 'events,prop1';
s.linkTrackEvents = s.events = 'event1';
s.prop1 = s.pageName;
s.tl(this, 'o', 'Form Submitted');
};
// Form Submission code calls trackLink()
$.ajax({
type: 'POST',
url: submit.php,
data: [data],
success: trackLink()
});
调用 trackLink()
的结果未定义
,presumably因为此
在 s.tl()
不再指向一个DOM对象?更换这
的东西,如 $('A#提交')[0]
(试图将对象传递给它而不是这个
)也导致未定义
。我究竟做错了什么?
Calling trackLink()
results in undefined
, presumably because the this
in s.tl()
no longer points to a DOM object? Replacing this
with something like $('a#submit')[0]
(trying to pass an object to it instead of this
) also results in undefined
. What am I doing wrong?
推荐答案
有关s.tl的第一个参数只能有两个值中的一个。
The first parameter for s.tl can only have one of two values.
如果该功能被称为的onclick处理程序的元件,则它需要的值 - 这 - ,而在这种情况下,解决了在元件的href属性的值。如果这是通过为第一参数,然后加载新页面之前的功能将创建500ms的延迟,这是为了保证有足够的时间用于跟踪呼叫的发送。
If the function is being called as the onclick handler for an element, then it takes the value - this -, which in this case resolves to the value of the href attribute of the element. If this is passed as the first parameter, then the function will create a 500ms delay before the new page is loaded, this is to ensure there is enough time for the tracking call to be sent.
如果该功能被称为在任何其他情况下,包括作为形式或AJAX的成功处理程序的一部分,那么第一个参数必须是文字 - 真的 - 。在这种情况下,该函数不添加延迟,但仍会发送跟踪呼叫
If the function is being called in any other context, including as part of a form or ajax success handler, then the first parameter has to be a literal - true -. In this case, the function doesn't add the delay, but will still send the tracking call.
在你的情况下,正确的签名是这样的:
In your case the correct signature is this:
s.tl(true, 'o', 'Form Submitted');
这篇关于Omniture的SiteCatlayst跟踪:错误从调用使用jQuery在函数中s.tl()时不绑定到单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!