Last Updated on: June 2, 2009
Last Updated: 3rd September 2021
The Google Analytics cookies have changed but the concept of capturing data this way is still possible. If you have any questions or can help with some insights, please leave a comment below.
In this article I will be looking at the raw data that Google Analytics records, picking apart the Google cookies and showing some examples of how to extract and use that data.
I personally find Google Analytics a great free tool and use it as default on most of my sites. There are, of course, data privacy concerns that follow Google around but I won’t get into those here.
On a recent project, I found myself wanting access to certain Google Analytics data from within my own custom admin dashboard. I had looked at recording my own information but it felt unnecessary to duplicate what Google Analytics is already doing.
Another option I considered was exporting data using the Google Analytics API but unfortunately the quota limits of 10,000 requests per 24 hours means I wouldn’t have the real time statistics I wanted.
I decided to use the Google Analytics cookies directly and record the data locally. This also gave the benefit of being able to link website actions (in this case adding a product to cart, removing it etc.) to a specific Google Analytics user and therefore giving me a bigger picture of my user habits.
So as an overview, this is how I did it:
3) The server side code run by the Ajax request deciphers the Google Analytics cookies and records all the information locally
Using Ajax also ensures that the details of the final page request are recorded.
Picking Apart the Google Analytics Cookies
The part that required the most figuring out was the data within the Google Analytics cookies.
There are actually three Cookies placed by Google Analytics:
__utma – A “long term” cookie containing the main details of the user
__utmb – A “current session” cookie containing details about the current website visit
__utmc – A “no expiration” cookie which is used only to determine if the user has closed their browser (therefore initiating a new session when they next visit)
__utmz – A “current session” cookie containing referral details about the current visit
Each cookie contains data separated by a period (.), with the
__utmz cookie further separating details with a pipe (|). The cookies break down as follows (the segments represent the data in the order as they appear in the string):
Segment 1: Unique number identifying the user. Useful for keeping track of return visits and as a primary key for storing locally.
Segment 2: Unix timestamp of this visitors first ever visit to the website.
Segment 3: Unix timestamp of this visitors previous visit to the website.
Segment 4: Unix timestamp of this visitors current visit to the website (the start of the current session).
Segment 5: Total number of sessions.
Segment 1: Pages viewed in the current session
Segment 2: Unknown (My notes say Responses…)
Segment 2: Referral Count
Segment 3: Source Count
Segment 4: This segment contains all the information about where the visitor came from. It is separated by pipes and then the label/value is separated again by an equals sign. An example for this segment: “utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=keywords”. The information is as follows:
utmcmd: Medium (e.g. for google it can be organic or Adwords)
utmctr: The keywords used
utmcct: Campaign content. Adwords information.
utmccn: Campaign name. Adwords information.
utmgclid: Click ID from Adwords.
Some other cookies you may also see are __utmv and __utmx which are related to customer user segments and the Website Optimizer respectively.
If you have any questions on this leave a comment and I will update the article so everyone can benefit. You may also be able to glean some information from (although they don’t spec the cookies in detail):
Get notified of new posts: