Put this code on the page where the form you want to track resides. Some other examples are currently passed around the web with varying quality. This is one that will work as long as your form tag has an id=
or name
attribute.
You don´t have to change this code to be able to track form abandonment in your shopping cart, order form or whatever form you want.
This sends events to Google Analytics when a user focuses somewhere not in a field after having focused on a input field. You won´t know for how long users focused on respective fields, or the actual conversion rate in the form using this, but it might be a start.
A tool that provides more insight both over time and per field, is Form Analytics wich helps you optimize your online forms. For instance, it measures dropout rate, average field input length, conversion rate and average time per field. All which provides great insights in the most overlooked, yet important part of you site.
Anyway, here´s the code:
$(function(){
$('form input').blur(function( e ){
var me = $(this), form = me.parents('form');
_gaq.push(['_trackEvent', (me.attr('name') || me.attr('id')), (me.val().length > 0 ? 'filled' : 'empty'), $(this).attr('name')]);
});
});
I suggest using
This will capture selects and textareas as well