Quantcast
Viewing all articles
Browse latest Browse all 31

Tracking Internal Search using POST request method in Google Analytics

Since Google Analytics is relying on query parameters in the URL to track Internal Site Search, Internal Site Search solutions that are using the HTTP POST method can't normally be tracked without some help from IT and server side implementation/programming. This because HTTP POST don't send any query parameters. And based on my experience, it can often take some time to get something like this implemented.

I needed a quicker solution for some friends that have slow opened their web shop Karma.no, and wrote a simple javascript/jQuery solution for them that also tracks Zero Result Searches.

Image may be NSFW.
Clik here to view.
Zero Search Results in Google Analytics

Some example HTML code

Imagine that the search result page is found at the location http://www.yourdomain.com/search.aspx, and that the HTML-code below is generated on this page when a user has searched for something that resulted in Zero Results.

Remove formatting from Code

  1. <form action="/search.aspx" method="post" name="intSearch">
  2. <input name="keywordFieldName" id="keywordFieldID" value="some search phrase" type="text" />
  3. <input name="searchButton" type="submit" value="Search" />
  4. </form>
  5. <div id="divName">
  6. <p>No posts found. Try a different search?</p>
  7. </div>

In the example HTML-code above, some part of the code have been highlighted with red text. We are going to use those values in the javascript/jQuery script.

The Javascript/jQuery solution for tracking Internal Site Search

To grab the search phrase, I'm using the jQuery .val() method. Replace values in red with your values.

Remove formatting from Code

Since we are using a virtual search result page name in the script above, we have to exclude the real search result page name (search.aspx) to avoid double counting of page views. The filter below will exclude search.aspx from the reports in Google Analytics.

Filter Name - Exclude Page: search.aspx

Filter Type
Custom filter
FilterExclude
Filter Field
Request URI
Filter Pattern \/search\.aspx
Case Sensitive
 No

Site Search Setting

The next thing you have to do is set your Site Search Settings.

Image may be NSFW.
Clik here to view.
Google Analytics Site Search Settings

Done! Happy tracking internal search phrases and zero result searches in Google Analytics from internal search using POST request method.

If you think the piece of code could be improved, feel fra to comment (I'm not a programmer).

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 31

Trending Articles