Google Analytics (GA) is a great tool for all who like to measure the effects of their websites, but can we also use it for our own website as an on-site-tracking system? GA does seem to know quite a lot about our vistors, but how do we get that data from GA into our website? And even better, is it possible to link the data to the person who is visiting your website?

The moment somebody crawls your website quite a lot of things happen with regards to GA. First of all a lot of JavaScript is being executed but what is more interesting, the results are stored inside the GA cookie. In theory this means that your website can access the cookie if the cookie is stored under the same domain of your website which is the case.

This is quite a different approach than the old-fashioned way to hook into the GA API (which is too slow anyway), do complicated programming, use jobs to pull all the data together in the background (because of the slowness of the API), etc… it’s works fast, reliable and it gives you the same data as stored in GA!

Contents of the GA cookie

Although the cookie consists of more parts than listed below there are three cookies of importance, the full article on GA cookies is described by Google here: http://code.google.com/intl/nl/apis/analytics/docs/concepts/gaConceptsCookies.html

__utma

Also known as the cookie to identify unique vistors, it holds basic information about your visitor. The most important part is the visitor ID (which is unique) and links all different GA cookies together.

  • Visitor ID
  • Date of first visit
  • Date of previous visit
  • Date of current visit
  • Times visited

__utmv

If you are not familiar with GA, please skip this part. The __utmv cookie stores information which you set as custom variables. Custom variables are pieces of custom information that you can relay to GA. Commonly they are used to segment your visitors in other ways than the standard GA segments.

  • Custom variable slot 1
  • Custom variable slot 2
  • Custom variable slot 3
  • Custom variable slot 4
  • Custom variable slot 5

__utmz

My personal favourite part of the GA cookie set, it stores all the GA utm codes. These codes are used by many web people to track the effectiveness of their campaigns and therefore very useful to be able to reuse on your website and if possible to link it to an individual visitor.

  • Campaign source
  • Campaign name
  • Campaign medium
  • Campaign content
  • Campaign term

Retrieve the Google Analytics cookie

My personal favourite tools to retrieve the cookies are the Web Developer Toolbar (https://addons.mozilla.org/en-US/firefox/addon/web-developer/) and Firecookie (https://addons.mozilla.org/en-US/firefox/addon/firecookie/) as a plugin of (https://addons.mozilla.org/en-US/firefox/addon/firebug/). Below are example images of this blog showing the __utma and __utmz cookies.

The first number equals the ID of the visitor and the numbers starting with 133 are the dates of visits in a linux format, the number of seconds since epoch (http://en.wikipedia.org/wiki/Unix_time).

Again, the number on the left is the ID and the other values are readable by humans as well, umtcsr is the campaign source, utmccn the campaign name, utmcmd the medium. If the campaign term and content are also filled you will see here variables named utmctr and utmcct.

If you search Google for “Google Analytics cookie parser” you will find some nice coding examples on how to retrieve the cookie.

Linking to an individual

As shown above the basics are met, the cookies are stored on the domain path (host is part of the domain, ie. www.eppenga.com is part of .www.eppenga.com (notice the peroid in front of the hostname)) and it’s clear that the cookies contain valuable readable information.

Multiple scenario’s are now thinkable, you could retrieve cookie when a webform is submitted and then add the utm variables to the original post data. Another possibility might be more tempting, based on the contents of the cookie you could instruct your CMS to serve different webpages. For example, if somebody visited your website more than 100 times (readable from the __utma cookie) show that person a voucher for a freemium? The possibilities and ideas are endless!

Wonder why I called this article (ab)using the cookie? Of course you are not really abusing the cookie, after you read this I think you will understand that this is nice, fast and unintended approach on how to implement a quick and efficient on-site tracking system for an extremely low price, GA is free people.

If you are curious how this works in practise a multi-million web visitor environment, please leave a comment!