How dangerous is e.preventDefault();, and can it be replaced by keydown/mousedown tracking?

前端 未结 7 1834
隐瞒了意图╮
隐瞒了意图╮ 2021-02-04 17:51

I\'m working on a tracking script for a fairly sophisticated CRM for tracking form actions in Google Analytics. I\'m trying to balance the desire to track form actions accuratel

7条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 18:44

    Them fellers over at that there Googleplex are awful bright and they figgered some day somethin' like this was bound to happen and now, sure enough, it has. Why don't you give this a good try:

    $('form').submit(function(e){
      e.preventDefault();
      var form = this; 
      _gaq.push(['_trackEvent', 'Form', 'Submit', $(this).attr('action')]);
      //...do some other tracking stuff...
      _gaq.push(function(){
         form.submit();
        });
      });
    

    That _gaq.push thigamajigger executes its elements sequentially, so you should be jest fine.

    And no, I don't know why I suddenly started talking like this.

提交回复
热议问题