Event tracking with google analytics on form block?

hi there I wanted to add the event tracking code to the submission of a form so I copied the form block from /concrete to the root level /blocks folder and changed the view.php to the following:

NB I do have analytics installed - and I am outputting the analytics code in the header so that shouldn't be the problem

<form enctype="multipart/form-data" id="miniSurveyView<?php echo intval($bID)?>" class="miniSurveyView" method="post" action="<?php echo $this->action('submit_form').'#'.$survey->questionSetId?>" onSubmit="_gaq.push(['_trackEvent', 'Forms', 'Submitted']);">

It works in so far as
a) when you view source on the form it is outputting the call
b) The form data is being processed (appearing in the reports)

BUT when you actually submit the form the 'thank you' message does not appear and the form remains on the page (with the details filled in)

Can anyone think what I have done wrong here?

View Replies:
SignallHill replied on at Permalink Reply
Did you ever figure this out? I am also looking for this solution.

Thanks in advance
cherrycake replied on at Permalink Reply
sounds like a javascript error to me.

there is no need to copy an entire block just to get an onsubmit event going.

it should work just by doing this in jquery.

$('.miniSurverView').submit(function() {
  _gaq.push(['_trackEvent', 'Forms', 'Submitted', $(this).attr('action')]);
SignallHill replied on at Permalink Reply

Could you please detail the process for me from the beginning to the end?
cherrycake replied on at Permalink Reply
sure, though it would help to know exactly what you're having issues with.

but in general, this should work.
0. make sure you load your gs.js and everything else needed for google analytics like tracking code etc.
1. add a javascript file to your page, inside the <head> tag like so: (and make sure the url is correct so that it actually loads)
<script type="text/javascript" src="/js/somejsfile.js"></script>

2. write this in your js file:
$(function() {
  $('.miniSurveyView').submit(function() {
    _gaq.push(['_trackEvent', 'Forms', 'Submitted', $(this).attr('action')]);

that is a function that's defined to run when the page content has loaded. once it runs, it looks for all elements with the class "miniSurveyView" (change this name if your <form> has a different class="" value). for every found element it registers a submit event handler, meaning, when the element (form) is submitted, the function passed into it will run.

the function passed into it had the _gaq.push etc code. if that code runs, you should be home free.

but i haven't tested this of course :) so at your own risk of wasting time!