Google Analytics Hack Google Analytics recognises 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.

The purpose of this hack, is to be able to differentiate regional variations of search engines. For example, instead of just reporting search engines as their generic Google, Yahoo, MSN etc. (as Google Analytics will do by default), I want to be more regional specific in order to compare SEM efforts in different countries:

[ Last update Dec 2009: Now 100+ additional SEs + GA defaults (140+ domains). You no longer need to re-define the default set of search engines that Google Analytics uses as this hack now prepends new search engines to GA's list. For details on new prepend revision see: code.google.com ]

  • Google.com
  • Google.co.uk
  • MSN.co.uk
  • MSN.fr
  • eniro.se
  • eniro.no
  • maps.google.com (local search)
  • etc.

It is straight forward to add to Google’s list of recognised search engines – you simply add your own as described in the following Help Centre article . However, the Help Centre article cannot customise the list – only add new search engines. That is, "google" as a whole has already been defined so adding google.co.uk to the list won’t work as – it’s too late.

This hack was written to enable you to do this (original 2007 post here ).

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.js . You can host the script locally (get the file from my scripts directory and place it in /scripts on your web server), or simply link directly to my file as shown.

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

<script>
     // load the ga.js file
</script>
<script>
     // set account number
     // track pageview visit
</script>

to:

<script>
     // load the ga.js file
</script>
<script>
     // set account number
</script>
<script src="http://www.advanced-web-metrics.com/scripts/custom_se-ga.js" type="text/javascript"></script>
<script>
     // track pageview visit
</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="http://www.advanced-web-metrics.com/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 below or provide a rating by clicking the stars.

---
Possible related posts (auto generated):
  1. Customising the list of recognised search engines