Reputation: 1
I have a page with a order form. I want to track the onSubmit click in google analytics. This is the format I used. I have also added the correct information into google analytics in the admin/ goals panel.
<form method='post' id='form_catalogrequest' name='CatalogRequest' value='CatalogRequest' onSubmit ="return valid(this);_gaq.push(['_trackEvent', 'catalogRequest', 'Submit']);">
Is this correct way of setting this up? is there a better way to do this? because it is not tracking in GA when I process the form.
http://www.positivepromotions.com/catalogrequest.aspx
Upvotes: 0
Views: 884
Reputation: 32532
The problem is that before your GA code you have return valid(this);
Since you are returning something, all code after that is ignored. You need to restructure your onSubmit code to allow the GA code to be triggered. Looking at your valid()
function from your link, it looks like it ultimately returns true
if form fields are valid, false
if not.
So there are two ways you can go about this:
Method A: wrap the onSubmit code in a condition
<form method='post' id='form_catalogrequest' name='CatalogRequest' value='CatalogRequest' onSubmit ="if (valid(this)){_gaq.push(['_trackEvent', 'catalogRequest', 'Submit']); return true;} else { return false; }">
Method B: move your GA code to within your valid()
function:
function valid(form){
// lots of form validation stuff that I didn't c/p to save space
_gaq.push(['_trackEvent', 'catalogRequest', 'Submit']);
return true;
}
Personally I'd go for Method B as it is IMO cleaner.
Upvotes: 2