Javascript Google Analytics Form Tracking

In my Google Analytics account I'm trying to track a form progression.  
I have the following code:
<input type="text" name="item_options[last_name]" value="" placeholder="Primary Operator Last Name" onBlur="if(document.testform.item_options[last_name].value != '');_gaq.push(['_trackPageview','/form/item_options[last_name]'])"/>

Open in new window

In this line::  
onBlur="if(document.testform.item_options[last_name].value != '');_gaq.push(['_trackPageview','/form/item_options[last_name]'])"
Chrome gives me an error:: Uncaught TypeError: Cannot read property 'item_options' of undefined
LVL 7
rgranlundAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
try:
document.testform['item_options[last_name]'].value != ''

onBlur="if(document.testform['item_options[last_name]'].value != '');_gaq.push(['_trackPageview','/form/item_options[last_name]'])"

Open in new window

0
rgranlundAuthor Commented:
When I make that change, the error message changes;
Updated Form Field:
<input type="text" name="item_options[insured_last_name]" value="" Placeholder="Last Name" onBlur="if(document.mail_info['item_options[insured_last_name]'].value != '');_gaq.push(['_trackPageview','/form/item_options[insured_last_name]'])"/>	

Open in new window

ERROR Message:  Uncaught ReferenceError: _gaq is not defined

Do I need a dot before items options?
0
hieloCommented:
That just means that _gaq does not exist anywhere.  The likely cause is that the google analytics file is not loaded.  Here's the code you should be using:
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

Open in new window

https://developers.google.com/analytics/devguides/collection/gajs/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
The code that I get from Google is a little different.  Also, I realized that the error only occurs when I change a value in the form field that includes the tracking code.  The error either:

Uncaught TypeError: ga.push is not a function
OR
Uncaught ReferenceError: product_liability is not defined

Here is all of the code:
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXX-X1', 'auto');
  ga('send', 'pageview');
</script>

<html>
<select name="item_options[product_liability]" onBlur="if(document.mail_info.item_options[product_liability].value != '');ga.push(['_trackPageview','/form/item_options[product_liability]'])">
							<option {selected} value="">None</option>
							{product_liability}
							<option {selected} value="{option_value}" data-liability_name="{option_name}">{option_name}</option>
							{/product_liability}
						</select>
</html>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.