We love digital

Call 0845 485 1219

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

Universal Analytics and Cookies – The Complete Guide

Gemma Holloway

by Gemma Holloway on 23rd July 2013

Universal AnalyticsUniversal Analytics uses cookies as a means for collecting data and customising these cookies can allow you to collect the exact data you require for your project.  In this blog post I am going to look at the cookies used by Universal Analytics and the potential customisations of those cookies.  Finally, I am going to look at some specific cookie data and decipher what the different data refers to.

For the purpose of this blog post, when referring to ‘Universal Analytics’ I mean the new technologies recently introduced by Google Analytics.  When referring to ‘Google Analytics’ this means the technology which uses the previous ga.js JavaScript library and finally, when referring to just ‘Analytics’ on its own, this refers to the technology used by both for the purposes of reporting data.

What’s Different?

So, let’s start with the differences between the cookies used by Google Analytics and those used by Universal Analytics.  Firstly, unlike Google Analytics which uses 4 different cookie types for the collection of data, Universal Analytics only requires the use of one; the _ga cookie.  This minimises first party cookie storage within the JavaScript library.  Whilst Google Analytics is reliant upon the use of cookies to track data, Universal Analytics uses two collection methods which can collect visitor data without the use of any cookies altogether; analytics.js and the measurement protocol.

If you wish to find out more information on the cookies used by Google Analytics, please see my previous blog post.

Universal Analytics Tracking

So for those of you who haven’t seen it, the entire Universal Analytics code looks like this:

Universal Analytics Tracking Code

This code consists of two parts.  Firstly the request to Analytics servers using the code library analytics.js:

Universal Analytics Tracking Part 1

And secondly a list of two actions:

Universal Analytics Tracking Part 2

It is this second part we are going to focus on today.  Predominately the tracking object, which by default looks like this:

Tracking Object

The tracking object generates a new cookie; the _ga cookie.  By default the _ga cookie is set on the top level domain with the root level path and an expiration time of 2 years.  As with Google Analytics cookies, the _ga cookie is reset each time it is fired.

Using the analytics.js library, this cookie distinguishes between users by assigning two randomly generated 32-bit numbers which are unique to the user they are assigned; This is known as a client identifier (clientID).  The _ga cookie is included in each hit which is then sent to Google Analytics allowing the collection of data within your Analytics account.  This data is then used by Analytics servers to calculate visitors, session, campaign data, etc.

Customising _ga Cookies

As with the various cookies used by Google Analytics, the _ga cookie can also be customised.  This is done by adding a configuration object as the last parameter within the tracking object.  Within this parameter you simply refer to the property name you wish to customise and add the value you wish to customise it to.  For example:

UA Custom Tracking Code

So let’s take a look at each of these customisations in a bit more detail:

Customising cookieDomain

It is likely the cookieDomain is going to refer to the root level of your domain.  However, in some instances you may wish to customise this to only track interaction within one subdomain of your website.  In this instance, you would set the cookieDomain to this subdomain, as below:

cookieDomain Customisation

To implement cross domain tracking within Google Analytics it was necessary to customise your cookies so that the cookie value is passed from one site to the other.  This is not necessary within Universal Analytics.  As long as your cookieDomain is set to the highest domain possible, then the cookie will track traffic across all subdomains.

For example, let’s say we have the following three sub domains blog.gemmaholloway.com, directory.gemmaholloway.com and forum.gemmaholloway.com.  As long as the cookieDomain is set to gemmaholloway.com this will track traffic across all three.  For example:

Cross Domain Tracking

Customising cookieExpires

As mentioned above the standard cookie expiration time for the _ga cookie is 24 months; however, this may not be appropriate for your application and therefore, you may need to change this expiration period.  You can do this by setting cookieExpires to a customised value.  Please remember all time is measured in seconds.

For example, this cookie would expire after 3 minutes:

cookieExpires Customisation

Setting cookieExpires to 0 allows the cookie to become session based meaning it will expire once the current browser session is terminated.  However, it is unlikely this is something you are going to want to do with Universal Analytics as one of the biggest benefits is to track users across multiple browsers and devices.

Please note, this is not the same as configuring the timeout period.  Unlike Google Analytics, changing the timeout period in Universal Analytics does not require the customisation of cookies.  Instead, this is carried out within the Admin section of your Analytics account.

Customising cookiePath

Finally, as with ga.js cookie you can customise the cookiePath, however this is strongly discouraged.  To do this you simply add ‘cookiePath’: ‘/new_cookie_path/’ within the last parameter.

Seeing the Cookie Data

So using the method explained within my previous blog post I have brought up the _ga cookie from my test site.  So let’s look at what separate parts of the cookie refer to:

_ga Cookie Example

Let’s start simple.  We have two strings of numbers.  The first refers to the clientId which has been mentioned numerously above and definies the specific user.  The second string of numbers is a timestamp which refers to when the cookie was set.  Finally, at the beginning of the cookie, we have the number ’2′.  This number determines which is the correct cookie to use in the case of multiple cookies setup in different paths or domains.

As mentioned above, by default the _ga cookie is setup up with the cookiePath ‘/’.  However, you may have a _ga cookie setup for sub.example.com and another at example.com.  The identifier number refers to the number of components separated by dots within the domain.  So the example above would refer to gemmaholloway.com, whereas blog.gemmaholloway.com could have begun with the identifier number ’3′.

Customising the cookiePath, although discouraged, would change the identifier number to two numbers separated by a slash; The first number refers to the components within the domain separated by a dot and the second refers to the number of slashes within the path.  So changing the cookiePath to ‘/analytics/’ and the cookieDomain to ‘blog.gemmaholloway.com’ would mean your tracking code would need to read as follows:

cookiePath Customisation

And as a result the cookie would appear as:

_ga cookie

Finally, Disabling Cookies

Unlike Google Analytics, deleting or clearing your cookies does not necessarily mean you will be classed as a new user.  This is because analytics.js does not necessarily rely upon the use of cookies for storage.  Instead it is possible to disable analytics.js from setting cookies and instead using your own storage mechanism which then sends information to Analytics.  To do this you can use the tracker with the following configuration as the last parameter:

Disabled Cookies

This will require supplying your own clientId parameter.

And that’s the way the cookie crumbles.. (Excuse the pun!)

So, hopefully now you understand how Universal Analytics uses cookies and the ways these can be customised to help you extract the data you require.  Let me know in the comments if there is anything interesting in particular that you have noticed about the _ga cookie or perhaps even Universal Analytics tracking in general.

Image Source

Universal Analytics image by Google

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!


  • Yehoshua Coren 25th July 2013

    Hi Gemma,

    I enjoy reading your posts. A few comments (seeing as it the comments sections and all…). :)

    1). GA.js actually uses 5 cookies, not 4. When users are running a content experiment, GA relies on the utmx cookie for variations.

    2). It it worth noting that Universal Analytics is able to minimize 1st party cookie storage because all of this information is stored on the server. This is pretty cool because it means we can change the “names” associated with persistent values if we choose, whereas with persistent cookies the name : value combinations shouldn’t be altered to maintain data integrity.

    3). You said that “to implement cross domain tracking within Google Analytics it was necessary to customise your cookies to treat all subdomains as one.” This is not the case. Cross domain tracking is not related to cookie scope. Cookie values simply need to pass from one site to the other, the scope at which they are written to the browser is irrelevant.

    4). Something that I noticed is that if Universal Analytics detects ga.js cookies on a site, it will set the “identifier” portion of the _ga cookie to match the unique identifier portion of the _utma ID. It appears to me that this is being done so that users will be able to migrate at some point during the future.

    Thanks again for the enjoyable read!


    Reply to this comment

    • Gemma Holloway

      Gemma Holloway 25th July 2013

      Hi Yehoshua,

      Thanks for covering the above points. Number 4 is particularly interesting – Nice spot! I must admit, I was aware this is how cross domain tracking works; however, you’re right it’s not explained correctly – I’ve updated it to make it clearer.

      I’m glad you enjoyed the read :)


      Reply to this comment

  • Ulrik 25th July 2013

    Good article Gemma :-) thanks for the Insights. Now if only GA would allow for a 3rd party cookie to be set to tie together true cross domain tracking, it would be immense.

    Reply to this comment

  • Bhagawat Jadhav 30th July 2013

    Hi Gemma,

    I become a fan of you. I have read previous blog posts also.

    Thanks for noting it down for us.

    -Bhagawat J.

    Reply to this comment

  • Ketan Vakil 1st October 2013

    Thanks for the article, and good to know about the subdomain improvement. But what if there are multiple top level domains (think, gap.com and bananarepublic.com) — GAP owns both of them and might want to see a single view of the customer no matter how they get to each site over time (direct visit, cross-link, etc). What do you do then? Thanks!

    Reply to this comment

  • Sai Stone 20th October 2013

    Thank you for the article Gemma, it really helped a beginner like myself. I am trying to modify my tracking code so that I can track demographic data, however the instructions only seem to apply to “Google Analytics” as opposed to “Universal Analytics” which I use. Please instruct me on how to modify the Universal Analytics code for display advertising, demographics etc. Thanks in advance!

    Reply to this comment

    • Gemma Holloway

      Gemma Holloway 22nd October 2013

      Hi Sai,

      Unfortunately Universal Analytics doesn’t currently support Display Advertising Integration. We do expect this to be a capability in the future.

      Can you please confirm what you mean with regards to demographics? Demographic information is available by default under the Audience menu. Your tracking code will collect basic information by default. If you wish to collect more in depth data, this can be done via Custom dimensions and metrics.

      Reply to this comment

  • Gavin 24th October 2013

    Hi Gemma

    Thanks for the article, very informative!
    One thing I noticed with Google Analytics tracking was that it captured keywords used to navigate to a website.

    Is this something that can still be viewed?


    Reply to this comment

    • Gemma Holloway

      Gemma Holloway 25th October 2013

      Hi Gavin,

      At present this data can still be viewed but Google are increasingly switching searches over to encrypted search using HTTPS, meaning this data will not be available much longer and will instead show in your account as (not provided). Eventually all keyword data will be shown as (not provided).

      Reply to this comment

  • Federico 6th November 2013

    Hi Gemma! Great post! I am trying to understand differences between GA and UA and you helped me a lot.

    Let me ask you. Is there any problem if I keep the previously tracking code and add the new one with a different UA? As the used cookies are different I hope not, however your opinion would be important.

    I look forward your answer

    Reply to this comment

    • Gemma Holloway

      Gemma Holloway 7th November 2013

      Hi Frederico,

      I’m glad the post helped offer some clarity.

      Using the GA and UA tracking codes side by side is perfectly fine – And to be honest is what I would recommend. There is the option to migrate your existing GA account to UA now, but UA still lacks some of the GA functionality, such as remarketing and content experiments. Therefore to ensure you still have access to this functionality, I would recommend running both technologies side by side.

      Hope this answers your questions, feel free to let me know if there is anything else you are unsure of.

      Reply to this comment

  • Martin 7th November 2013

    Nice post emma!

    Reply to this comment

  • Phil 2nd April 2014

    Thanks for the good read Gemma,

    I really like the power of Universal Analytics, but I’m starting to see some limitations when it comes to adding tracking data (UTMZ) to a contact or signup form which is then stored in a 3rd party CRM. This data is needed to attribute a sale from campaign during a longer sales cycle. As Universal Analytics no longer has data that can be parsed right from the UTMZ cookie, have you seen a work around for this for Universal Analytics which allows for metrics such as Source, Medium, Campaign data to be pulled?

    Reply to this comment

Subscribe To The Koozai Blog