Skip to content

Instantly share code, notes, and snippets.

@koenpunt
Forked from arnklint/track-form-abandonment.md
Last active August 29, 2015 13:59
Show Gist options
  • Save koenpunt/10738408 to your computer and use it in GitHub Desktop.
Save koenpunt/10738408 to your computer and use it in GitHub Desktop.

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').on('blur', ':input', function(event){
    var input = $(this), form = $(event.delegateTarget);
    ga('send', 'event', (form.attr('name') || form.attr('id')), (input.val().length > 0 ? 'filled' : 'empty'), input.attr('name'));
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment