The Case Of The Misplaced Site Search Data

December 22, 2011 | Dorcas Alexander

What does it mean when “search/organic” turns up as Source/Medium in your Google Analytics reports? It could mean some of your visitors are using the search engine Search.com (yes, there really is a search engine called that), but it could also be bad data because Google Analytics mistakenly attributed visits to Search.com even though they came from somewhere else.

Data Investigating Bad Data

How could that happen? Suppose your site www.anything.com has a search box (of course it does!) so visitors can search the entire site. Unfortunately, the site search engine returns search results pages with URLs like this:

search.anything.com?q=anything

I say, “unfortunately,” because that’s exactly the kind of URL that Google Analytics mistakes for the search engine Search.com.

How Site Search Gets Mistaken for Organic Search

Google Analytics keeps a list of search engines, and it recognizes them by looking for certain items in the referring domain and referring page query string. If the domain contains “search” and the query string contains “q” then GA thinks the referrer is Search.com.

There’s even more bad news. Suppose this visitor originally came to your site from an email campaign, which you cleverly tagged with cool campaign info (newsletter/email), as you should. As soon as the visitor uses your site search, GA mistakenly sees a new traffic source (search/organic)… and starts a brand new session.

This scenario played out recently for one of our clients. The previously documented solution, using _addIgnoredRef, did not work. So we reported it to Google engineers, who reproduced and confirmed the issue and promised to get back to us with an update.

In the meantime, we devised a simple workaround that immediately improved the data. If your data has been compromised by this issue, it can help you, too.

How To Fix It

Our solution is a little script that we include on every page on search.anything.com. The script looks at all the links on the page and if a link goes to anything.com, it appends a parameter to the URL that tells GA not to change the source/medium to search/organic.

jQuery.noConflict();

jQuery(function() {
  jQuery("a").each(function(index) {
    var link = jQuery(this);
    var href = link.attr('href');

    if (href.indexOf('www.anything.com') != -1 && window.location.href.indexOf("search.anything.com") != -1)
      {
        jQuery(link).bind("click", function(l) {
          location.href = href + (href.indexOf('?') != -1 ? "&utm_nooverride=1" : "?utm_nooverride=1");
          return false;
        });
      }
  });
});

If you’re already familiar with GA parameters you’ll see the key to the script is the parameter utm_nooverride=1, which is more typically used when visitors return to your site from third-party shopping carts, or for ad campaigns where you don’t want to overwrite existing referral data.

In this case, utm_nooverride=1 means GA won’t write a new traffic source (and mistakenly start a new session) just because a visitor uses site search.

Remember you also need to refer to the jQuery library before you call the script, like this:

script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js">

Have you come across this issue on your own site or a client’s? If so, how did you handle it? Please share in the comments.

Update: Google rolled out a fix in February 2012 so that this is no longer an issue. See the official changelog – scroll down to the entry for February 1, 2012.