0

I have a search form throughout my website which submits to a results page (via POST)

In order to track what people are searching for, I've added a line of event tracking code like so to the submit() event:

$("#search").submit(function(){
    var query = $('#search input[type="text"]').val().toLowerCase();
    _gaq.push(['_trackEvent', 'search', 'submit', query]);
});

At first, I tried used preventDefault and then called form submit() after the analytics call but this was slow, I presume because it was waiting to hear back from that request.

The above seems to be working but is there a chance that some requests won't be recorded because the form will submit (off to my results page) before the that push request is done?

  • Take a look at this SO post [Track event in google analytics upon clicking form submit](http://stackoverflow.com/questions/4086587/track-event-in-google-analytics-upon-clicking-form-submit), but scroll down to the answer that says **Use Google Analytics hitCallback**. That should do exactly what you're looking for. – Blexy Dec 12 '13 at 21:36
  • Not an answer to your question, but it might be easier to set a virtual url with the tracking parameter in your search result page - that way you can use the standard site search report instead of event tracking. – Eike Pierstorff Dec 13 '13 at 08:50

0 Answers0