We love digital

Call 0845 485 1219

We love digital - Call and say hello - Mon - Fri, 9am - 5pm

Google Analytics and Cookies – The Complete Guide

Gemma Holloway

by Gemma Holloway on 20th June 2013

Cookie DataIt is likely, whether you are in the industry or not, you have heard the term ‘cookie’ thrown around here and there – And unfortunately I don’t mean the chocolate chip kind.  A cookie is a small text file which is stored in your browser as a means of giving memory to browsers and servers.

Originally created to help maintain customisation, the cookie contains data which is attached to the HTTP header of a page request, allowing the server to determine if you have any current customisations in place and whether or not you have the authority to view the page.

Google Analytics relies on cookies to ‘remember’ and record a users’ interaction on a website.   In this blog post I am going to look at each of the specific cookies Google Analytics uses, the potential customisations and a way of using Google Debugger to see the cookie data.

Google Analytics uses a set of up to up to 4 cookies; _utma, _utmb, _utmz and _utmv  via the ga.js library to record information about what a user has seen or done on a particular page.  It sets these cookies at the domain specified in the document.host browser property and with the root level path.

It is important to remember that cookies are browser specific when it comes to ga.js.  Therefore a user on Google Chrome on their work computer will have different cookies stored than if they are using Google Chrome on their home computer.

Google Analytics Cookie Types

_utma

This cookie is used to determine new and returning visitors.  It has an expiration time of 2 years.  If the ga.js library is executed and no _utma cookie exists, this will be recorded as the users’ first visit and a _utma cookie will be set.  If a _utma cookie is already in place, the expiration time is reset and the user is recorded as a return visitor.

_utmb

This cookie is used to determine a new session.  The cookie is set when the ga.js library executes and there is no _utmb cookie in place.  It has an expiration time of 30 minutes, therefore if a user is inactive for a period longer than this, a new cookie will be set when the library executes and the interaction will be recorded as a new session.

_utmz

This cookie is used to determine the traffic source, medium, campaign name and campaign term which delivered the user to your website.  It is created when the javascript library executes and expires after 6 months.  This helps Google collect the data which can then help them to determine which traffic sources assist conversions within the multi-channel section of Analytics.

_utmv

This cookie is used for storing visitor-level custom variable data.  It is created when the _setCustomVar method is used with a visitor level custom variable.  Like the _utma cookie, this cookie expires after 2 years and is reset each time the user visits your site before the expiration of the cookie.

Although each of these cookies has a set expiration time, each time the ga.js library is executed and the expiration time has not been met  the cookie is updated, resetting the expiration date to its original value.

For those of you who are already aware of cookies you may have noticed that I have left out _utmc.  This is because strictly speaking it is not used within the ga.js library.  This cookie expires when the browser is closed, therefore, for the purpose of this blog post I am going to overlook this cookie.

ga.js Cookie Customisations

There are 5 key customisations which can be carried out on ga.js cookies:

_setDomainName

By default domain name tracking will be set to the domain specified within the document.domain property.  However, you can set this to either a specified domain name or ‘none’ .  Setting the domain name allows you to implement cross domain tracking. For Example:

_gaq.push([‘_setDomainName’, ‘koozai.com’]);

Would allow traffic from all Koozai subdomains to be tracked.

Setting the domain name to ‘none’ does the opposite of this and allows only traffic to the top level domain to be tracked.

_gaq.push([‘_setDomainName’, ‘none']);

_setCookiePath

Typically Google Analytics sets the cookie path to the root of your domain which is appropriate in most situations.  However, you may wish to define the cookie path when you only have access to a sub-directory of a website.  Therefore, you would set the cookie path as this sub-directory.  For example:

_gaq.push([‘_setCookiePath’, ‘/Gemma’]);

Would only track interaction within the /Gemma folder of the website.

_setVisitorCookieTimeout

As mentioned above, the visitor cookie (_utma) has the expiration time of 2 years. _setVisitorCookieTimeout allows you to redefine this expiration period in milliseconds.  Therefore _gaq.push([‘_setVisitorCookieTimeout’, 31,557,600,000]); would change this expiration time to one year.

_setSessionCookieTimeout and _SetCampaignCookieTimeout are also ways of altering the expiration times of their corresponding cookies.  _setSessionCookieTimeout relates to the _utmb cookie and _SetCampaignCookieTimeout relates to the _utmz cookie.  Remember all expiration times are defined in milliseconds.

So Why Is This Important?

If your cookies aren’t working it could mean that the data you are collecting in Google Analytics is incorrect meaning any decisions you make off the back of this data are inaccurate.  Therefore it is important to check your cookies are tracking correctly.  You can do this using a method covered by Nikki Rae at this year’s Brighton SEO.

Using Google Debugger To Check They Are Tracking Correctly

So first of all you need to download the Google Analytics Debugger extension.  With the Debugger switched on, go to ‘Advanced Settings’ in Google Chrome and ‘clear browsing data’.

Clear Browsing Data

Next you need to delete your cookies from the beginning of time:

Delete Cookies

Go to your site via a specific medium.  In this instance I have visited Koozai via Google, therefore, the visit should be tracked as organic.

To see the information which would have been sent to Google Analytics press CTRL+SHIFT+J.

Google Analytics Cookie Data

As you can see this has been tracked as my first session (correct as the cookies had been cleared) and via organic source (Correct!).

Ok, now go back to the Advanced settings in Chrome. Click ‘Content Settings’.

Content Settings

And choose ‘All Cookies and Site Data’.

All Cookies and Site Data

Find your website and you can see which cookies are being stored on your browser.

Cookies Stored

For the purpose of this blog post we are going to ignore WRUID and _CT_Data.

So if we click on _utma we can identify whether or not we are being tracked as a unique user (this should be the case as all cookies had been cleared).

_utma Cookie 

_utma Cookie Data

So let’s go through a quick run through of what the string of numbers means.  The string starts with a domain hash, this defines which domain the cookie relates to and is unique for every domain.  The Unique Identifier is what defines the user/browser. The time stamp refers to the visits the user makes to your website and the number of sessions refers to how many times they have visited your website.  Therefore, in this case we can see that I have been recorded as a unique visitor because all three time stamps are the same.

_utmb Cookie

_utmb Cookie Data

The _utmb cookie contains the same domain hash as above.  This cookie records information about this particular session.  To check it is working we can review the number of page views (in this case one) – Correct!

Update: I have been informed the pageview counter actually refers to a hit counter.  Therefore, it is not recommended not to try and  and determine the pageview of a visit via the _utmb cookie value.

_utmz Cookie

_utmz Cookie Data

Again the domain is the same as the above cookies as it refers to the same domain.  From this cookie we are able to determine the campaign source, campaign name, campaign medium and campaign terms.  As I visited Koozai.com via organic traffic through Google and I am logged in to my Gmail account it would appear this cookie is working.  The source has been recorded as Google, the medium as Organic and the search term as (not provided).  Traffic source information can also include utm_source, utm_medium, utm_term etc.

So there you have it, a nice simple check to be sure your cookies are working as they should be.  When you do this check do you have any issues with your cookies?  Do you have another method for checking your cookies? I would be very interested to know in the comments.

Image Source

Data Mining Information via BigStock Photo

Gemma Holloway

Gemma Holloway

Gemma has amassed a broad range of marketing experience having worked in competitive sectors including leisure, computing and shipment. With a degree in Marketing with Psychology, she has enthusiasm for Digital Marketing and a strong understanding of user behaviour.

down arrow

Your Free Whitepaper

The Practical Guide To Google Analytics For Businesses (2nd Edition)

The Practical Guide To Google Analytics For Businesses (2nd Edition)

Download this whitepaper now and get a new one every month!

9 Comments

  • khaleel 20th June 2013

    Nice info

    Reply to this comment

  • Ryan Holdaway 20th June 2013

    Great post!

    Customising cookie lengths is something I’ve implemented recently. utmb lasting 6 months by default is excessive.

    Ryan.

    Reply to this comment

    • Gemma Holloway

      Gemma Holloway 20th June 2013

      Thanks for your comment Ryan – I would definitely agree that 6 months for _utmb is too long for a session.

      I would suggest considering the functionality of your website. Taking Facebook for example, many people have this running in the background all day long even if they do not touch it. Therefore they may wish to consider altering their session period to say 8 hours (to cover the majority of people’s working day).

      You need to consider how people interact with your website and then deem what is an appropriate session length from this.

      Reply to this comment

  • Yehoshua Coren 21st June 2013

    @ Gemma

    Great guide. Very clear to follow. One comment -> the “pageview” counter in UTMB is really a “hit” counter. That means that events, or ecommerce, or social hits will also impact this cookies values. The number of hits in a session is sent to GA via the utms parameter, which gets the value from the utmb cookie.

    The practical application of this is that people shouldn’t try to read utmb cookie values to understand which pageview in a visit a particular action happened on.

    @ Ryan

    utmb by default is 30 minutes.
    utmz (campaign cookie) by default is 6 months.

    Perhaps you meant utmz?

    Reply to this comment

  • Alex Davies 24th July 2013

    Excellent post, Gemma.

    I’ve read on different sources that the _utmc cookie is not being used to define sessions (browser close) any more, but I can’t find any official Google documentation to state this. It still appears to be referenced in the ga.js include file and created as standard with the sync/async tracking code.

    Do you have any documentation / official sources that state that _utmc is definitely deprecated?

    Many thanks,
    Alex.

    Reply to this comment

  • Alex Davies 25th July 2013

    Perfect.

    Thanks Gemma, really appreciate it!

    Reply to this comment

  • Pingback: Your Blog Needs Video Marketing | IdeaRocket

Subscribe To The Koozai Blog