谷歌分析异步:事件跟踪回调? [英] Google Analytics Async: Events Tracking Callback?
问题描述
我希望使用事件跟踪来记录对另一个网站的特定类型链接的点击次数。我使用的是jQuery,而我现在使用的代码是:
$ b $ $ p $ $('a.website')。click(function(事件){
var href = $(this).attr('href');
try {
_gaq.push(['_ trackEvent','website','click',href ]);
} catch(err){}
});
然而,在看到其他网站的引用信息后,我不相信这是准确地跟踪可能是因为 _gaq.push
是异步的,并且在浏览器导航到url之前并未收到请求,并终止当前页面上运行的任何JavaScript。 p>
有没有办法检测 _gaq.push
函数是否已成功完成,因此可以使用 event.preventDefault()
和 document.location
在事件被记录之后导航到链接。
如何解决此问题 answer ?
//将一个网页浏览记录到GA进行转换
_gaq.push(['_ trackPageview',url]);
//推动重定向以确保它在我们追踪pageview
_gaq.push(function(){document.location = url;})后发生;
I wish to use event tracking to record clicks on a specific type of link to another website. I am using jQuery, and the code I currently have is:
$('a.website').click(function(event) {
var href = $(this).attr('href');
try {
_gaq.push(['_trackEvent', 'website', 'click', href]);
} catch(err) {}
});
However, after seeing referrer information from the other site, I don't belive this is accurately tracking the clicks, probably because _gaq.push
is asynchronous, and the request has not been received before the browser navigates to the url, and terminates any javascript running on the current page.
Is there any way to detect that the _gaq.push
function has completed successfully, so I can use event.preventDefault()
and document.location
to navigate to the link after the event has been recorded?
How about solution from this answer?
// Log a pageview to GA for a conversion
_gaq.push(['_trackPageview', url]);
// Push the redirect to make sure it happens AFTER we track the pageview
_gaq.push(function() { document.location = url; });
这篇关于谷歌分析异步:事件跟踪回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!