views:

41

answers:

3

Hi all,

We have a client unable to switch a form from POST to GET, at the moment we're tracking form submissions via an event tied to the 'Submit' button.

However, this tracks as a 'completed' form, someone who clicks submit but who might get the form returned with errors.

Normally I'd either AJAXify the form and prevent submission of the form until JS validation is complete, or alternatively use an unique 'Form Complete' URL and track as a goal (and an event with on DOM load JS triggering the event tracking), but that's not an option in this case.

How can I tie an event to the 'form success' content in this scenario? I know I can tie an event to an image load, but I'd need to dynamically generate the image name to prevent caching affecting the analytics.

Can I tie an event to text that's in POST robustly?

A: 

Once you validate the form on the server-side, you can simply output JavaScript along with the next response that tells Google Analytics to track the submission event.

Edit: I just noticed that you said this isn't an option.

casablanca
Actually it's the additional URL that's the issue, I can see your solution working nicely
Chris
You don't necessarily need an additional URL. You can pass any URL you want to the tracking function. [see this](http://www.google.com/support/googleanalytics/bin/answer.py?answer=55521)
casablanca
I've gone with a variation on this approach using jQuery to bind to an ID in the success HTML content which triggers the Google event trackign code. Works a treat - thanks for all the suggestions!
Chris
A: 

Could you output a hidden field that contains a value meaning that the form was successfully submitted, and then use jQuery watch for that field to come back with a success value? Then javascript a redirect to another page?

So on document ready do this:

jQuery

if ($("#MyHiddenField").val() == 'success') {
    document.location = "SOME SUCCESS URL THAT ANALYITICS CAN TRACK";
}

Alternatively, just have jQuery watch for some success indicator (like "thank you" or another phrase) in the page content and then redirect.

Tim Santeford
Makes sens in theory, though the reason we can't use a success URL in the form would also rule this one out. I know - it's a peculiar restriction!
Chris
That what I would do but since submitting a form is not a page view but an Event you should just track the event. http://code.google.com/intl/el/apis/analytics/docs/tracking/eventTrackerGuide.html
PanosJee
A: 

You can also conditionally invoke the Google Analytics tracker code based on javascript events. See this article

Include this javascript on your page only when the form submit is successful or call it with jQuery using the example in my other awnser:

pageTracker._trackPageview("/homepage/link1");

the page will not get redirected but Analytics will record it as if the user actually visited that page.

Tim Santeford