Did you know you can collect web stats for any site - not just sites you 'own' - using Google Analytics? Well with a little bit of Greasemonkey magic (or a suitable browser extension) it seems you can.
Idly wondering whether I could set up my own shadow research project to study OpenLearn user behaviour, I knocked up a very simple Greasemonkey script to add a Google Analytics tracking script onto the bottom of any OpenLearn pages I visited:
// ==UserScript==
// @name Openlearn tracker
// @namespace http://ouseful.open.ac.uk/blog
// @description Adds tracking to openlearn pages
// @include http://openlearn.open.ac.uk/*// ==/UserScript==
(function() {
var b=document.getElementsByTagName('body');
var s=document.createElement('script');
s.setAttribute('src','');
s.setAttribute('type','text/javascript');
b[0].appendChild(s);
s=document.createElement('script');
s.setAttribute('type','text/javascript');
var t=document.createTextNode('_uacct = "UA-******-*";');
s.appendChild(t);
b[0].appendChild(s);
})();
It's easy enough to put this script into an extension format - for example using a Greasemonkey compiler.
Setting up the tracking on Google Analytics was easy enough too:
... as you can see:
For example, the first few stats:
I did wonder whether I was getting away with this almost legitimately because I have properly installed tracking on the OUseful blog, which lives on the open.ac.uk domain.
So I tried on a domain I have absolutely no formal relationship with (except for a handful of search API developer tokens!) - Yahoo.
A very minor tweak to the Greasemonkey script allows the Google tracking script to be added to the bottom of any page on the yahoo.com domain:
Setting up the Google Analytics account - and obtaining a tracking code - is easy enough:
And as you can see, tracking is working:
Here are some results:
You can see from the results above - and the header below - how the Google tracker script even manages to capture dynamic (search query) content:
[The search queries in the graphical view over multiple sites (p=plone+(site:www... etc.) are actually generated using the searchfeedr search intermediary, which is rapidly becoming my search interface of choice.]
What this means - among other things - is that if I can get you to install my extension, I can track your behaviour over my competitors' websites.
I can't really understand why Google Analytics doesn't at least check that you have installed the script on at least one particular page on the domain being tracked and which Google can poll when it feels like to check that the tracking is still officially sanctioned. I wonder if this is mentioned at all in the Google Analytics book?
Because it seems to me that there is no such check.
Now it may well be that I am in breach of Google Analytics Terms and Conditions, but people will play...
Just a couple of other things to note in passing - when the Google tracker script fires, it also seems to tell Google blogsearch what's going on:
And for OU internal readers, you can see a glimpse of the sorts of results that the Site Intelligence VBIS web analytics package gives for OpenLearn visitors here. [Background: OU adopts Site Intelligence web analytics tool]
Posted by ajh59 at November 19, 2006 01:18 PM