javascript - Form validation and Analytics event tracking -
i using javascript validate form fields. if passes want send event google analytics. isn't sending event ga. in form have:
<form role="form" name="submit" method="post" onsubmit="return validateform();">
and validation code is:
function validateform() { // validate form , update section if there error var spamcheck = document.submit.inputspamcheck.value; if( document.submit.inputname.value == '' ){ document.submit.inputname.focus(); $( "#name-section" ).addclass( "has-error" ); return false; } else if( document.submit.inputemail.value == '' ){ document.submit.inputemail.focus(); $( "#email-section" ).addclass( "has-error" ); return false; } else if( document.submit.inputspam.value != spamcheck ){ document.submit.inputspam.focus(); $( "#spam-section" ).addclass( "has-error" ); return false; } else{ _gaq.push(['_trackevent', 'form', 'submitted', 'successful', 5]); return true; } }
i old question love answered in case needs helps.
the onsubmit="" form event if paste following script in <head>
section of form page this
<script language="javascript"> function checkcontval() { var fun = document.submit; if(fun.name.value == ""){ //do return false; } if(fun.email.value == ""){ //do return false; } if(f.securitycode.value == ""){ //do return false; } _gaq.push(['_trackevent', 'form', 'submitted', 'successful', 5]); //ga('send', 'event', 'category','submit','contact page enquiry'); or event if using universal ga. return true; } </script>
Comments
Post a Comment