One of the most important things about Search engine optimisation and any sort of on-line marketing is being able to measure our success. Enter Google Analytics a free service from Google which
generates detailed statistics about the visitors to a website. Its main highlight is that a webmaster can optimize their AdWords advertisement and marketing campaigns through the use of GA’s analysis of where the visitors came from, how long they stayed on the website, and their geographical position.
- Wikipedia
It first appeared in 2005 after Google bought its parent company who’s software was called Urchin (indeed the script is still referred to as Urchin as we will see later) and is now used on literally thousands of blogs and sites across the world. Unlike many tracking software that your web host may provide you Google Analytics uses Javascript as its mean of tracking by placing a cookie on your visitors system. The pro’s of this includes the ability to find out far more about visitors, but also leads to privacy issues, and because javascript can be turned off and cookies disabled visitors can “avoid” tracking. Even with these limitations its still a great system and one we use on all our sites where possible.
Getting it up and running is simple so lets get started!
Setting up the Urchin Cookie
If you haven’t already done so go sign up for Google Analytics its free and takes about a minute as part of the process you will need to create a profile of the site (domain) you wish to track. you will also be given some code that looks like
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct="UA-xxxx-x";
urchinTracker();
</script>
Your urchin tracker code will be UA-XXXX-X obviously replace XXX’s with what ever your code is, if you placed the above into your html page, within the body tag’s it will start tracking your page “that was easy wasn’t it”. We can obviously do more with this but that’s the basic add that code and it will track your pages
Secure site tracking
If you use SSL (secure socket layer) or another Secure site system you could have a potential security hole in that the Google analytics data is being sent to a “non secure” server and so errors may occur. There is a simple solution provided by Google simple use the following script on Secure pages
<script src=" https://ssl.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-XXXXX-X";
urchinTracker();
</script>
Note the URL of the script is the only thing to have changed, if you have a site that has SSL and non SSL or where people can access the site from either SSL or non then it’s worth looking at ways to make sure your site is showing the correct script, the simplest method is to use the Secure socket layer version through out the site as it works for both Secure and non secure pages but it does take a longer time to return and so slows your page loads down. However there are several alternate methods which do include small amount of scripting The unofficial Google Analytic Blog goes into details but I would just like to post one of the 2 methods they describe.
This route does involve PHP but has the least load time of all 3 methods in my opinion and is seamless
if($_SERVER['HTTPS'])
{
$google_analytics_url = "https://ssl.google-analytics.com/urchin.js";
}
else
{
$google_analytics_url = "http://www.google-analytics.com/urchin.js";
}
echo "
<script src='$google_analytics_url' type='text/javascript'>
</script>
<script type='text/javascript'>
_uacct = 'UA-XXXXX-X';
urchinTracker();
</script>
";
This code checks to see if you are using a secure or non secure version of the site and then simply produces the correct code.
Setting up Urchin Cookie on Drupal
For Drupal users their are several ways to install the analytic’s code via the Google Analytics module, directly into their template files or via a block which is my preference.
The Analytics module adds the code for you and offers some basic options like ignoring admins etc, its simple and very easy to implement. Similarly if you wish to add the code to every page and the same code to every page then this can be done through the template simply open page.tpl and place the code within the page. However a more flexible system is to use a block. You can either use a an existing region (such as footer) or define a new region specific to your site, and then create a block setting the formatting to either full html if you are adding the javascript or PHP if your site uses SSL and you wish to use the above code. The nice theing about a block is it can be assigned which pages to appear on by default I don’t track /admin visits and so exclude the analytic cookie from these pages. You can also stop the cookie from diplaying based on user groups again I simply select that the staff usergroup is not tracked (staff was created and individuals added).
This method means we can apply more complex tracking which we will go into later by allowing individual and groups of pages to have unique codes.
That’s it for part 1 in part 2 we shall start to look at clicks and inbound links and why are clever use of Blocks with Drupal may be our undoing…
Subscribe to The Venture Skills Blog by Email
All our Posts are audio subscribed for more information see here, and to access the podcast feed here
This blog is moving soon, make sure you move with us by using our Feedburner RSS feed, if you have used the autodiscovery button in your browser you may need to swap feeds, simply delete the old feed and add, http://feeds.feedburner.com/VentureSkills For a more detailed explanation on feeds and recieving our content in various formats click here

Subscribe to our Odiogo Audio Feed


