Tracking Form Posts
The recommended way to track form posts is to send an event from the page the form posts to. For example:
Contact entry page:
<form action="contactPosted" id="contactForm" method="post">
FirstName: <input name="firstName" id="firstName" />
<input type="submit" />
</form>
"contactPosted" page:
<head>
<script>
gator.logEvent('Contact');
</script>
</head>
Tracking form posts on the submit event
Tracking directly from the form submission requires a litte more effort. When a user clicks on a submit button, the standard way to track the event will not work consistently. This is because browsers will sometimes abort all processing before
the event can be recorded.
In order to prevent this problem, intercept the onclick event on the form submit button and call the gator.logOutbound function. For example, to track a form post and
collect form data (using jQuery):
<form id="contactForm" method="post">
FirstName: <input name="firstName" id="firstName" />
<input type="submit" onclick="gator.logOutbound('First Contact',
function() { $('#contactForm').submit() }, { firstName: $('#firstName').val() } ); return false" value="Submit" />
</form>
Parameters:
First Contact | The name of the event you wish to track. This is the same as the gator.logEvent event name |
$('#contactForm') | The form element (jQuery syntax). |
data | Data to attach to the event. This is the same as the gator.logEvent data parameter. |