异步谷歌分析虚假综合浏览量跟踪不适用于指向网站外部的链接
我使用 jQuery 将 onClick 事件附加到网站上的某些元素,具体取决于该元素是否存在,例如:
$(document).ready(function() {
if ( $("#webform-client-form-15897").length ) {
$("#edit-submit")
.attr("onClick", "_gaq.push(['_trackPageview', '/feedback-submitted'])");
}
});
这对于表单上的“提交”按钮等内容非常有用,并且我能够通过假的跟踪目标pagevisit(事件不允许这样做,因此是假触发器)。
问题是,当我将类似的 onClick 事件设置为 Anchor HTML 元素(将用户带出网站)时,我在我们的分析中看不到任何内容,即使使用相同的代码附加例如警报(“foo ") 事件显示其明显有效,并且我收到一个弹出窗口。
这是使用 jQuery 处理后实际锚元素的样子:
<a href="http://www.example.com/foo" onclick="_gaq.push(['_trackPageview', '/ad-clicked'])">Anchor text</a>
我做错了什么,因为我已经在一些教程中看到了这个示例,并且代码正在执行,只要我可以使用断点和警报来跟踪它( )测试?
I'm using jQuery to attach onClick events to certain elements on the site, depending on whether the element exists, example:
$(document).ready(function() {
if ( $("#webform-client-form-15897").length ) {
$("#edit-submit")
.attr("onClick", "_gaq.push(['_trackPageview', '/feedback-submitted'])");
}
});
This works splendidly for things such as a Submit button on a form, and I'm able to track Goals via the fake pagevisit (Events don't allow this, hence the fake trigger).
Problem is, when I've set similar onClick events to Anchor HTML elements, that take the user out of the site, I'm not seeing anything appear on our analytics, even though using same code to attach for example an alert("foo") event shows its clearly working and I get a popup.
Here is how the actual anchor element looks like after being processed with jQuery:
<a href="http://www.example.com/foo" onclick="_gaq.push(['_trackPageview', '/ad-clicked'])">Anchor text</a>
What am I doing wrong, since I've seen this example used on a few tutorials and the code IS executing as far as I can track it with breakpoint and alert() tests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题通常总是因为在用户进入下一页之前没有足够的时间来执行 GA 代码。如果链接打开一个新窗口 (target="_blank"),这不是问题,因为原始页面仍然存在,并且代码可以完成加载。处理此问题的常用方法是使用 settimeout 稍微延迟重定向,以便为 GA 脚本的执行提供时间。您可以访问下面的链接了解实施的详细信息。
http://www.google.com/support /analytics/bin/answer.py?hl=zh-CN&answer=55527
The problem is usually always because there is not enough time for the GA code to execute before the user is taken to the next page. This isn't a problem if the link opens a new window (target="_blank") because the original page is still there and the code can finish loading. The common way to handle this is to use settimeout to delay the redirect a little, to give time for the GA script to execute. You can go to the link below for details on implementation.
http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55527