Wednesday, 4 May 2011

Google Analytics easy-peasy-lemon-squeezy

Clever chaps & chapesses at Google. I've just put a website live for an Accountancy Outsourcing Company www.henryjamesoutsourcing.co.uk and added Google Analytics to the site.

Google Analytics is one of a number of tools Google provide for web developers. Essentially it captures statistics for pages on your web site. You have to have a Google account to use it so you have to sign up there first. Then you add Analytics to your suit of Google tools (sign up for an email address whilst you're at it and you can receive your stats reports pushed via email to the google email address)

Once you've signed up you'll get a little text window with some Java script in that'll look a bit like this

<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">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}
</script>

Copy this and paste it into your static web pages eg index.html … before the tag (keeps things tidy) and that's it hit your site a few times and check your Analytics pages a bit later (takes a while for the stats to filter through) I hit the verify

Now for some techie stuff: This is downloading some javascript code from google that actually does the monitoring. It uses cross site scripting to do this but adding the javascript dynamically

document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

gets round the browser security issues (see my earlier posts on cross site scripting and Ajax) Activity is reported back to google in most cases. One thing to watch out for is that any activity from China won't be reported on in full because of Chinese Government security limitations on internet information. Not that that's a problem for Henry James Outsourcing, maybe for when we're a little nearer world domination.