Last 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:

custom search engine report

If you use this hack, I would be interested to hear want you think, so please add your comments.

1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 2.83 out of 5)
Loading ... Loading ...
Email This Post Email This Post     Print This Post Print This Post