javascript - Where to call _gaq.push Google Analyticss in MVC form? -


i have mvc form in razor view using html.beginform , in submit button adding code google analytics in onclick event this:

onclick="_gaq.push(['_trackevent', 'mystuff', 'aperturaform', 'veintemasled']);" 

but problem if forms submits gets error, click event fired , push made if form fail. question is, have perform _gaq.push in onsubmit form event @using (html.beginform("20mil", "product", null, formmethod.post, new { @class = "small", onsubmit = "_gaq.push(['_trackevent', 'mystuff', 'aperturaform', 'veintemasled']);" }))?

what choices?

i guess use default button onclick event , call function this:

$.ajax({url: '@url.action("myaction", "mycontroller")',      data: { field1 : $('#txtexample').val() },      type: 'post',      success: function (data) {      if (data.actioncompleted) {           _gaq.push(['_trackevent', 'mystuff', 'aperturaform', 'veintemasled']);      }      else {           alert('error');      }  } }); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -