Analytics Event Tracking Without a Thank You Page
Anyone who has used Google Analytics for form-based Goal Tracking has probably been pleasantly surprised by how easy it is to set up. Simply enter the URL of your “Thank You” and click save – done. It even includes the option to match only the first part of a URL, meaning no tricky regular expressions if you need to ignore query string parameters!
But what if you want to track something a little more difficult than a form submission, for example, button clicks? Or what if you have a form without a “Thank You” page (eg: most AJAX forms)? This is slightly more difficult using Goal tracking. You could do something tricky, like dynamically load an invisible IFrame – but isn’t that just a little convoluted to achieve something that should be trivial? Shouldn’t there be an easier way?… There is, and it’s called “Event Tracking”.
Event Tracking allows us to specify when we want a certain behaviour (such as form submission, button press, etc) to be logged via JavaScript. The call is made on a page with your Google Analytics code on it. You use the “pageTracker” object and the “_trackEvent” function, as described below.
_trackEvent(category, action, label, value);
Where:
- category : the name you want to use for a group of events (ie: “Contact form”)
- action : the name of the action you are tracking (ie: “Form submit”)
- label : (optional) string to provide additional information about the particular event instance
- value : (optional) an integer value for the event (default = 1)
We can use this function anywhere we can call it from JavaScript. For example, to track button presses we can use the following:
<button onclick="pageTracker._trackEvent('Button','Press');">Track event</button>
… or to track a form submit:
<form onsubmit="pageTracker._trackEvent('Details form','Form submit'); return true;">
...
… or to do something more complex, possibly even with conditional logic. For example, we could track
<script type="text/javascript">
function validateNumber (inputVar) {
if (!isNaN(inputVar)) {
pageTracker._trackEvent('Data field','data saved');
return true;
}
return false;
}
</script>
Great stuff. You’ll probably notice, however, that your tracked Events don’t appear under the “Goals” heading in Google Analytics. Instead you’ll find your Event Tracking stats under, “Content” and then “Event Tracking” (see image below). Happy tracking!

