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
Post a Comment