Google Analytics Async:事件跟踪回调? [英] Google Analytics Async: Events Tracking Callback?

查看:24
本文介绍了Google Analytics Async:事件跟踪回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用事件跟踪来记录对指向另一个网站的特定类型链接的点击.我正在使用 jQuery,我目前拥有的代码是:

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) {}
});

但是,在看到其他站点的referrer信息后,我不相信这是准确跟踪点击次数,可能是因为_gaq.push是异步的,并且在请求之前没有收到请求浏览器导航到该 url,并终止在当前页面上运行的任何 javascript.

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.

有什么办法可以检测到_gaq.push函数已经成功完成,所以我可以使用event.preventDefault()document.location 在事件被记录后导航到链接?

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?

推荐答案

如何解决这个问题 答案?

  // 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; });

这篇关于Google Analytics Async:事件跟踪回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆