在点击表单提交后,在谷歌分析中跟踪事件 [英] Track event in google analytics upon clicking form submit

查看:192
本文介绍了在点击表单提交后,在谷歌分析中跟踪事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有人填写表单并点击提交时,我需要在Google Analytics中跟踪事件。出现的结果页面是标准的仪表板类型页面,因此为了跟踪该页面上的事件,我必须在url中传递事件,然后阅读url并输出google analytics事件跟踪javascript代码基于它。这是一个经常被添加书签的页面,而页面被重新加载,点击回到等等。所以我真的不想在URL中传递跟踪事件并搞砸分析。



相反,我宁愿在页面上使用下面的jQuery代码来处理表单:

  $( '#form_id')。submit(function(){
_gaq.push('_ trackEvent','my category','my action');
});

我担心上面的问题是我会错过一些正在跟踪的事件,因为立即在调用JavaScript之后,浏览器将提交表单并转到另一个网页。如果utm.gif跟踪图像没有及时加载,我会错过这个事件:(。



我的恐惧是否合理?我如何确保我不会错过事件被跟踪?

解决方案

只有两种方法可以确保所有表单提交(包括JS启用和谁不阻止GA)如下:


  • 您可以做一个AJAX提交,然后不必担心页面更改,因此GA有足够的时间来处理和您的新页面加载到旧页面。

  • 您可以强制表单在其中打开其操作一个新窗口,从而使主页面上的所有后台进程都能正常工作,并防止出现您担心的竞争状况。
  • 原因在于Google Analytics没有回调函数,所以即使您将10秒内的所有提交都截获了,您也无法确定是否捕获了所有滞后。

    或者,您可以将GET值传递给提交的页面,并在该页面上设置该值的检查。如果设置了,您可以发送trackEvent调用。

    I need to track an event in google analytics when someone fills out a form and clicks submit. The resulting page that comes up is a standard dashboard-type page, so in order to track the event on that page I'd have to pass in the event in the url and then read the url and output the google analytics event tracking javascript code based on it. This is a frequently bookmarked page though and page that is reloaded, clicked back to, etc. So I'd really rather not pass tracking events in the URL and screw up the analytics.

    Instead, I'd much rather do something like the following jQuery code on the page with the form:

    $('#form_id').submit(function() {
      _gaq.push('_trackEvent', 'my category', 'my action');
    });
    

    The problem I fear with the above is that I'm going to miss some events being tracked because immediately after calling that javascript the browser is going to submit the form and go to another webpage. If the utm.gif tracking image isn't loaded in time, I miss the event :(.

    Is my fear justified? How do I ensure I don't miss events being tracked?

    解决方案

    There are only 2 ways to ensure, 100%, that all form submissions (amongst users who have JS enabled and who don't block GA) is as follows:

    • You can do an AJAX submit, and then not have to worry about the page changing, and thus have all the time in the world for GA to process AND your new page to load in place of the old one.
    • You can force the form to open its action in a new window, thus leaving all background processes on the main page working, and preventing the race condition you're worried about.

    The reason for this is that Google Analytics does not have a callback function, so you can't ever be certain you're capturing all of the submits, even if you put a 10 second lag.

    Alternately, you can just pass a GET value to the submitted page and setup a check on that page for the value. If its set, you can send a trackEvent call.

    这篇关于在点击表单提交后,在谷歌分析中跟踪事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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