Categories: Web Analytics

Code Update: Optimize Form Length with Input Analysis

Back in August 2008, I wrote a post on how to optimize form length with input analysis with Google Analytics. This is still a very relevant topic, as forms are still essential to collecting data from visitors.  I still cringe when I see a form that has a ton of fields, and I know many of you do as well.  This post will show you how to take action to shorten your forms and remove unneeded fields, which usually results in higher conversion rates for your forms.

The old post referenced the traditional/syncronous version of the Google Analytics tracking code. This new post features the newest release by Google, which is the asynchronous code execution.

Please note that I am not going to re-do the entire post, just the code portion.

So here is the code update:

Traditional Snippet (Synchronous):

function validate()
{
isEntered(document.getElementById('name'),'name');
isEntered(document.getElementById('email'),'email');
isEntered(document.getElementById('phone'),'phone');
isEntered(document.getElementById('company'),'company');
isEntered(document.getElementById('comments'),'comments');

frm.action='/thankyou.aspx?src=contact_us.htm';
} 

function isEntered(el, field_name)
{
     if((el.value=="") || (el.value==null))
     {
     pageTracker._trackPageview('/contact_us.htm/empty/'+field_name);
     }

     else
     {
     return false;
     }
}

Asynchronous Snippet (NEW):

function validate()
{
isEntered(document.getElementById('name'),'name');
isEntered(document.getElementById('email'),'email');
isEntered(document.getElementById('phone'),'phone');
isEntered(document.getElementById('company'),'company');
isEntered(document.getElementById('comments'),'comments');

frm.action='/thankyou.aspx?src=contact_us.htm';
} 

function isEntered(el, field_name)
{
     if((el.value=="") || (el.value==null))
     {
  _gaq.push(['_trackPageview', '/contact_us.htm/empty/'+field_name]);
     }

     else
     {
     return false;
     }
}

 

Related Posts:

Allaedin Ezzedin

VP Analytics Engineering Allaedin wisely guides friends, family and colleagues with honesty and care. He is a long time digital analytics industry veteran leading Cardinal Path’s analytics team with over a decade of experience as a digital marketing and senior analytics consultant.

Share
Published by
Allaedin Ezzedin

Recent Posts

Google Delays Third-Party Cookie Deprecation to 2025

Google announced on April 23 that it will again delay third-party cookie deprecation (3PCD) in…

6 days ago

Understanding Funnel Reports in GA4

Funnel reports have long been one of the most actionable reports in a marketing analyst’s…

1 week ago

GA4 Monetization Reports: An Overview

GA4’s Monetization reports provide organizations with simple but actionable views into the revenue-generating aspects of…

2 weeks ago

This website uses cookies.