Tracking regional Search Engines in Google Analytics
GA Hacks, GA specific September 14th, 2008Last time I checked, Google Analytics recognised 41 search engines by default. Although this is constantly being added to, there are of course a great many other search engines in the world - language and region specific, as well as price comparison and vertical portals. Actually, it is straight forward to add your own search engine by reading the following Help Centre article - my original post for urchin.js is here.
However, the purpose of this hack, is to be able to differentiate regional variations of search engines. For example, instead of just reporting Google, Yahoo, MSN etc. as Google Analytics will by default, I wanted to have Google.pl, Google.co.uk, MSN.co.uk, MSN.fr, MSN.jp etc., so that I can compare my SEM efforts in different countries. The Help Centre article cannot do this for you, as the order of the defined search engines becomes important. That is, appending google.co.uk to the list of recognised search engines is too late - “google/organic” as a whole has already been defined. So this hack was written to enable you to do this.
Some further background…
I discuss this hack in Chapter 9 of the book and show the script to do this. However recent changes in the Google Analytics Tracking Code (GATC) has meant that the code no longer works written as it was.
Fortunately after some experimenting (a pseudonym for trial and error!), and help from Tomas Remortigue from Mountain View (all round nice guy and Google Analytics technical wiz), the hack is now fixed and back working
How to track regional search engines
From the book, this is a simple update with respect to the placement of code - the call to the custom_se-ga.gs. Get the file from my scripts directory and place it in /scripts on your web server (or modify the src path to your own personal directory).
The JavaScript file first clears the default list of search engines in Google Analytics and then defines 100 regional specific ones. Below is the layout you need to use for GATC:
Schematically, change your standard GATC:
<script type="text/javascript">// call ga.js file form Google</script>
<script type="text/javascript">// set account number & track pageview URL</script>
to:
<script type="text/javascript">// call ga.js file form Google</script>
<script type="text/javascript">// set account number</script>
<script src="/scripts/custom_se-ga.js" type="text/javascript"></script>
<script type="text/javascript">// track pageview URL</script>
Notice the bold line inserted between setting the GA account number and tracking the pageview.
So a full GATC will look as below (remember to replace the account number, beginning with “UA-” with your own):
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'
type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-123456-1");
</script>
<script src="/scripts/custom_se-ga.js" type="text/javascript"></script>
<script type="text/javascript">
pageTracker._trackPageview();
</script>
Note: The syntax of the GATC has to be exact for this to work. When in place, your Traffic Sources > Search Engine report will look something like the one below:
If you use this hack, I would be interested to hear want you think, so please add your comments.
Email This Post
Print This Post






September 15th, 2008 at 3:26 pm
Thanks for the update.
We are currently working on migrating to the new GA code and I just couldn’t get this script working - now I know why?
I have an off topic but related question about the ga.js code and it’s implementation:
- if you have multiple GA profiles you want to send the stats to can you ‘break-up’ the js code i.e. does the following work:
var gaJsHost = ((”https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(”%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’
type=’text/javascript’%3E%3C/script%3E”));
var firstTracker = _gat._getTracker(”UA-123456-1″);
firstTracker._trackPageview();
var secondTracker = _gat._getTracker(”UA-123456-2″);
secondTracker._trackPageview();
var thirdTracker = _gat._getTracker(”UA-123456-3″);
thirdTracker._trackPageview();
?
Steve
September 15th, 2008 at 10:39 pm
Quick update, this hack will no longer work with Yahoo.
At some point earlier in the year, Yahoo changed its sub domain nomenclature from a third level domain structure such as uk.yahoo.com, se.yahoo.com (which could tracked with this hack) to a fourth level domain structure e.g. uk.search.yahoo.com, se.search.yahoo.com etc, which cannot be tracked…
There is no way round this at present
September 16th, 2008 at 9:43 am
Last post made no sense!
Should have read:
Thanks for the update.
We are currently working on migrating to the new GA code and I just couldn’t get this script working - now I know why!
I have an off topic but related question about the ga.js code and it’s implementation:
- if you have multiple GA profiles you want to send the stats to can you ‘break-up’ the js code i.e. does the following work:
var gaJsHost = ((”https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(”%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’
type=’text/javascript’%3E%3C/script%3E”));
var firstTracker = _gat._getTracker(”UA-123456-1″);
firstTracker._trackPageview();
var secondTracker = _gat._getTracker(”UA-123456-2″);
secondTracker._trackPageview();
var thirdTracker = _gat._getTracker(”UA-123456-3″);
thirdTracker._trackPageview();
?
Steve
November 3rd, 2008 at 2:17 pm
[...] My standard word of caution - This is a tech tip and requires you to have a knowledge of html and javascript to implement and use it… [Update 03-Nov-2008: This hack is for the legacy urchin.js tracking code. For the ga.js version read: Customising the list of search engines in Google Analytics.] [...]
November 17th, 2008 at 2:26 pm
In a similar vein to what steve has posted, the site we are trying to install the custom search engine script on, has four Trackers.
It is currently not working, but I believe this is to do with the code on custom_se-ga.js
At the moment it is “pageTracker._clearOrganic()”
Should this be changed to reflet the fact there are four trackers?
And if so should it be
firstTracker._clearOrganic();
secondTracker._clearOrganic();
thirdTracker._clearOrganic();
forthTracker._clearOrganic();
Thanks
Kevin