【问题标题】:Event tracking form submissions - why do i have to click twice?事件跟踪表单提交 - 为什么我必须点击两次?
【发布时间】:2014-04-16 15:36:12
【问题描述】:

我是 jQuery 和分析事件跟踪的新手。我正在寻找跟踪表单提交。我的逻辑是用户将点击“提交”,然后表单等待提交,直到有时间发送到 Google 的服务器。
跟踪工作正常,但您必须单击提交两次。有什么建议吗?提前感谢一堆。

   jQuery("form").submit(function(e){
    e.preventDefault();
    ga('send', 'event', 'form', 'submission',location.pathname);
  jQuery(this).unbind('submit');
    setTimeout(function(){
    jQuery(this).submit();
}, 200);

});

我的印象是,您必须阻止提交几秒钟才能让“gif”发送到 Google。

如果有帮助,这里是 URL: http://salisburyrugby.com/recruit-contact/

【问题讨论】:

    标签: jquery forms google-analytics


    【解决方案1】:

    不使用 setTimeout,而是使用 Google 的内置回调函数 hitCallback

    jQuery("form").submit(function(e){
      e.preventDefault();
      ga('send', 'event', 'form', 'submission', location.pathname,{
        'hitCallback' : function(){
           jQuery(this).submit(); 
         }
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      • 2015-07-02
      • 1970-01-01
      • 1970-01-01
      • 2014-09-26
      相关资源
      最近更新 更多