Form tracking with JS and Google Analytics


/ Published in: jQuery
Save to your folder(s)

Track user interactions with html forms


Copy this code and paste it in your HTML
  1. var array1 = [];
  2. $(document).ready(function () {
  3. $('input').change(function () {
  4. var formbox = $(this).attr('id');
  5. array1.push(formbox);
  6. console.log("you filled out box " + array1);
  7. });
  8. $('#submit').click(function () {
  9. console.log('tracked ' + array1);
  10. //alert('this is the order of boxes you filled out: ' + array1);
  11. _gaq.push(['_trackEvent', 'Form', 'completed', '"' + array1 + '"']);
  12. });
  13. });

URL: http://jsfiddle.net/nicomiceli/WK5eN/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.