Thursday, May 10, 2007

Add additional search engines to GA to track

As of writing this Google Analytics tracks just 24 search engines (from 0 to 23). You can see the full list inside this file at the line #33.

The other SEs are reflected as referrals in GA reports. You can track them as "organic" just adding additional lines in the GA code on your site.

How to:

1. Go to the SE you want to track and type any query:
"The quick brown fox jumps over the lazy dog"

2. When you got the search results, look at the current URL and find the words you just typed. You will see something like this:
http://www.bloodysearchengine.com/dir?query=The+quick+brown+fox+jumps+ over+the+lazy+dog&sourceid=navclient-ff&ie=UTF-8&aq=t
3. Prior to the search phrase you will see the query variable. It may be "query", "q", "s" or whatever. Remember it.

4. Hack: insert the following line right before urchinTracker function:

_uOsr[_uOsr.length]='bloodysearchengine'; _uOkw[_uOkw.length]='query';

If you want to add several SEs it should look like this:

"< src="http://www.google-analytics.com/urchin.js" type="text/javascript"> < /script>
< type="text/javascript">
_uacct = 'UA-xxxx-x';
_uOsr[_uOsr.length]='bloodysearchengine'; _uOkw[_uOkw.length]='query';
_uOsr[_uOsr.length]='bloodysearchengine2'; _uOkw[_uOkw.length]='queryvariable';
_uOsr[_uOsr.length]='bloodysearchengine3'; _uOkw[_uOkw.length]='
queryvariable';
urchinTracker();
< /script>"


* Note that queryvariable may be different for every search engine. You should repeat steps 1-3 each time you want to add new SE.

The benefit of use of _uOsr.length and _uOkw.length instead of just numbers is your independence from the quantity of SEs in the urchin.js file. When Google increase the quantity of items in the list your SEs will be above them anyway.

Since you updated the code your google analytics will treat all traffic from bloodysearchengine.com as organic not referral.

Your thoughts?

2 comments:

Peter said...

Any ideas on the value of _uOsr? Is the referrer identified just by _uOkw (on a first in, first served base) and _uOsr just used for display, or does _uOsr have to match part of the referral URL, or even match the full domain name...

Results I am getting are not always understandable, including getting labels for traffic sources that I disabled weeks ago...

Also, comparing those statistics with actual server logs always shows up many discrepancies.

Peter said...

Ok, analyzing the urchin script taught me some interesting bits.

The following code (in the _uOrg function) trims the referring URL to just the hostname, this will be checked against the _uOsr array:

h=_ur.substring(i+3,_ur.length);
if (h.indexOf("/") > -1) {
h=h.substring(0,h.indexOf("/"));
}

So, all _uOsr values have to be substrings of the referring hostname.