Entries for month: January 2011

Google Analytics Seach Term Tracking Via POST

Looking to use Google Analytics Site Search to track specific site search terms?  Follow the below link and set up/turn on site search.  If your search is submitted in POST format, then add the below JS code to create a "fake" trackPageView that has the entered search term.  Google's instructions are assuming the search term will be in the URL(GET).

Set up Gooogle Analytics Site Search HERE.

Google Analytics JS code.



$(document).ready(function(){
        /* Google analytics search term tracking */
        $('#searchbox').submit(function(){
            //get the search term
            var searchTerm = $('#search').val();
            var pageTracker = _gat._getTracker("YOUR_ANALYTICS_KEY");
            //IMPORTANT PART! - fake page track url, because our form is submitting search term via POST 
            pageTracker._trackPageview('/?e=search.list&searchString='+searchTerm);
    })


})


My CF search form code:



<form action="#commitEvent#" method="POST" accept-charset="utf-8" class="float-right" id="searchbox">
  <input type="text" name="searchString" value="#viewstate.getValue('searchString', '')#" id="search" class="search-textfield float" />
  <input type="submit" name="submit" value="" id="submit" class="search-button float" />
</form>


Bookmark and Share

No Comments