0

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?

1
  • Are you able to edit the code for this web form? Jul 2, 2010 at 16:38

3 Answers 3

0

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.

3
  • Actually it's the additional URL that's the issue, I can see your solution working nicely
    – Chris
    Jul 2, 2010 at 17:00
  • You don't necessarily need an additional URL. You can pass any URL you want to the tracking function. see this
    – casablanca
    Jul 2, 2010 at 17:06
  • 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
    Jul 7, 2010 at 14:19
0

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.

2
  • 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
    Jul 2, 2010 at 16:54
  • That what I would do but since submitting a form is not a page view but an Event you should just track the event. code.google.com/intl/el/apis/analytics/docs/tracking/…
    – PanosJee
    Jul 4, 2010 at 21:25
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.