Google Analytics Cookies Explained in Great Detail

 

For the next few posts I will be answering the questions I am frequently asked about various issues in Google Analytics.  Instead of replying to the individual emails I thought of addressing all the issues in one go and at the same time share my understanding of Google analytics with others. This post is the first in the series.  You should have a good knowledge of cookies so that you can understand how Google Analytics collect data, how it define visits, visitors and other metrics.

 

What is a Cookie?

Cookie is a text file which is used to store information about a visitor, his preferences, location and other details.

 

How websites that run Google Analytics are able to track unique Visitors?

They are able to track through first party cookies.  Websites that run Google Analytics (GA) issue first party cookies which are stored on visitor’s hard disk. So when a visitor returns to a website that runs GA, the website is able to remember the visitor through the cookies set up on his hard disk. In this way Google Analytics doesn’t count the returning visitor as a new visitor.

 

What are the different types of cookies?

There are two types of cookies:

  1. First Party Cookies
  2. Third Party Cookies

First party cookies are issued by the website being visited and only the website which issued the first party cookie can read the cookie. Third party cookies are issued by the website(s) other than the website being visited.

 

Which types of cookies are used for Google Analytics tracking?

Google Analytics uses First party cookies.

 

Can a visitor disable some or all types of cookies?

Yes.

 

Can cookies be set with or without expiration date?

Yes.

 

What is the difference between persistent and temporary cookies?

Persistent cookies are the cookies with expiration date. They remain on your computer even when you end the web session or close your browser window. They can be read by the website that created them on return visits. Temporary cookies are cookies without expiration date. They expire as soon as you end the web session or close the browser window.

 

Can we determine exact number of visitors who have cookies enabled or disabled?

No.

 

Which websites can read your Google Analytics Cookies?

Only your website can read the cookies set by it and no other website. This is because Google Analytics cookies are first party cookies.

 

Which first party cookies are set by Google Analytics on my visitor’s hard disk?

Google Analytics can set following five first party cookies:

  1. _utma (unique visitor cookie)
  2. _utmb (session cookie)
  3. _utmz (Campaign cookie)
  4. _utmv (visitor segmentation cookie)
  5. _utmx (Google Website Optimizer cookie)

 

Note: There is one more cookie which Google Analytics set on a visitor’s hard disk. This cookie is known as _utmc cookie. Google Analytics doesn’t use this cookie any more to determine session status (if you are using ga.js tracking code).

 

Which Google Analytics Cookies are persistent and which are temporary?

All of the Google Analytics cookies are persistent except the _utmc cookie which is a temporary cookie.

 

When _utmv cookie is set up by Google Analytics on a visitor’s hard disk?

This cookie is set up only when Google Analytics tracking code call the _setCustomVar() method (in case of ga.js).

 

 

When the Google Analytics cookies expire?

i)  _utma  – this cookie expires after 2 years from the last time your visitor visited the site.

ii)  _utmv – this cookie expires after 2 years from the last time your visitor visited the site.

iii)  _utmx – this cookie expires after 2 years from the last time your visitor visited the site.

iv) _utmb- this cookie expires after 30 minutes from the last time your visitor visited the site or at the end of a day.

v)  _utmc – this cookie expires as soon as you close the browser window

vi) _utmz – this cookie expires after 6 months from the last time your visitor visited the site.

 

How I can view the various cookies set up by Google Analytics when I visit a website?

Step-1: Install web developer toolbar in Firefox or use your favorite tool to view cookie information.

Step-2: Go to the website which has installed Google Analytics Tracking code on its web pages.

Step-3:  Click on the cookies menu from the ‘web developers’ toolbar and then select ‘view cookie information’ as shown in the image below:

 

You can now see the cookies set up by Google Analytics on your hard disk:

Note: You can use the above method to see all the cookies (not just Google Analytics cookies) set up by a website on your hard disk.

 

Does Google Analytics set different set of cookies when I return to a website via another web browser?

Yes. This is because all cookies are browser specific.

 

When cookies are created /set up by Google Analytics?

Cookies are created as soon as you visit a website.

 

Through which cookie Google Analytics is able to indentify unique visitors?

Through _utma cookie.

 

How I can interpret the _utma cookie?

 

Domain Hash => This number represents the domain which set up the cookies.  All Google Analytics cookies set by a particular domain have same domain hash.

 

Random Unique ID => This is the second number which is randomly generated.

The next three numbers are timestamps which represent the time of initial visit, beginning of previous session and beginning of current session. All these three numbers also represent the number of seconds elapsed since Jan 1, 1970.

The last number is the session counter. It is incremented each time a visitor starts a new session.

 

 

How Google Analytics define visitor as unique?

Google analytics assign unique ID to each visitor on your website. This ID is called the visitor ID and it is made up of random unique ID and the first time stamp (also known as the time of initial visit).

 

 Note: If you look at the three timestamps above, you will notice that they all are same.

 

What does all the same timestamps in the _utma cookie tells you?

It tells you that this is your first visit to the website.

 

How I can reset my session counter in _utma cookie to 1?

You can do this by deleting all the Google Analytics cookies or by using a different web browser or computer to return to a website.

 

Can I change the expiration date of _utma cookie?

Yes through _setVisitorCookieTimeout() method. This method is used to change the expiration date of _utma cookie. By default, _utma cookie expires after 2 years. But you can set it to expire after 1 week or any time you want to. For example:

_gaq.push(['_setVisitorCookieTimeout', 604800000]);

Here _setVisitorCookieTimeout() method sets _utma cookie to expire after 1 week.

Note: Use a search query like ‘1 week in milliseconds’ on Google to convert any time into milliseconds.

 

Can I set the _utma cookie to expire as soon as the browser window is closed?

Yes. For this set the expiration timeout of the _setVisitorCookieTimeout() method  to 0. For e.g.

_gaq.push(['_setVisitorCookieTimeout', 0]);

 

 

Through which cookie Google Analytics is able to identify a web session?

Google Analytics uses _utmb cookie to identify a web session.  When your visitor loads a web page, the Google analytics tracking code check for _utmb cookie on the visitor’s hard disk. If this cookie is missing then Google Analytics treats the session as a new session and creates a new _utmb cookie. If the cookie is already present than Google Analytics update the cookie to expire in 30 minutes.

Note: Web session is also known as visit.

 

When Google Analytics end a web session?

A web session ends when _utmb cookie is destroyed. This cookie is automatically destroyed after 30 minutes of its setup.  If a visitor stays on a web page for more than 30 minutes, the _utmb cookie is automatically destroyed and the current web session automatically expires. If later the same visitor reloads the web page or navigates to other page of the website, Google Analytics starts the new session. As long as the visitor’s activity continues on your website within 30 minutes interval, the _utmb cookie will not be destroyed even if the visitor closes the browser window or navigate to web pages of other websites within the 30 minutes time frame.

 

The _utmb cookie is also destroyed at the end of a day or when a visitor returns to the website via a different traffic source value (utm_source, utm_medium, utm_campaign, utm_content, utm_term, utm_id or gclid) even within the 30 minutes time frame. For example if a visitor come to your website via a PPC ad and then later return to the website via organic search listing then his second visit will start a new web session even if 30 minutes have not elapsed between the two page views/visits.

 

How a web session can be longer than 30 minutes when _utmb cookie expires after 30 minutes?

Whenever a visitor navigates to other page of a website, Google Analytics updates the _utmb cookie to expire after 30 minutes. So as long as the visitor doesn’t stay on a web page for more than 30 minutes and continue to navigate other pages of the website, the _utmb cookie will not expire and hence the web session will not terminate.

 

How I can interpret the _utmb cookie?

 

 

Can I change the session time out length (which is usually 30 minutes) to anything I want?

Yes you can. Use the _setSessionCookieTimeout() method in your Google Analytics tracking code. This method is used to specify when the session should time out in milliseconds.

1 millisecond = 0.001 seconds

Syntax:  _gaq.push(['_setSessionCookieTimeout', 100000]);

Here you are telling Google Analytics to end a web session in 100 seconds.

Note:  Avoid using this method as it can considerably increase or decrease the number of visits reported by Google Analytics. It can also skew all those metrics which use visits in its calculations.

 

Can I set the _utmb cookie to expire as soon as the browser window is closed?

Yes. For this set the expiration timeout of the _setSessionCookieTimeout() method to 0. For e.g.

_gaq.push(['_setSessionCookieTimeout', 0]);

 

What is _utmz cookie?

It is a campaign cookie which is used by Google Analytics to store campaign information. The campaign information is stored in campaign variables. Following are the campaign variables supported by Google Analytics:

  1. utm_source
  2. utm_medium
  3. utm_campaign
  4. utm_term
  5. utm_content

 

How I can interpret the _utmz cookie?

 

The first number in the _utmz cookie is the domain hash which represents the website that set up the cookie on visitor’s hard disk. The second number is a timestamp. The third number is the session number which is incremented every time a visitor starts a new session. For example: from the image above we can see that this is the 8th session of the visitor.

Note: For every new session that campaign cookie values gets overwritten with new value.

 

The fourth number in the _utmz cookie is the campaign number. This number is incremented every time a visitor arrives at your website via a different campaign even within the same session. From the image above we can see that the visitors arrived on my website via 6 different campaigns.

 

The last number in the _utmz cookie contains information about the campaign which resulted in the current visit.

utmcsr = >It represents campaign source and stores the value of utm_source variable. For example, from the image above we can see that the campaign source for the current visit is Google.

utmccn = >It represents campaign name and stores the value of utm_campaign variable. For example, from the image above we can see that the campaign name for the current visit is organic.

utmcmd = >It represents campaign medium and stores the value of utm_medium variable. For example, from the image above we can see that the campaign medium for the current visit is organic.

utmctr = >It represents campaign term (keyword) and stores the value of utm_term variable. For example, from the image above we can see that the campaign term for the current visit is seotakeaways.

utmcct = >It represents campaign content and stores the value of utm_content variable.

 

So in short the visitor clicked on my search engine listing for the keyword ‘seotakeaways’ via Google Organic search.  Once Google Analytics read the _utmz cookie it sends the campaign information to the Google Analytics server which then sends the data to analytics reports.

 

 

How the content of the campaign cookie _utmz will look like if I visit the following URL:

http://www.seotakeaways.com/?utm_source=bing&utm_medium=ppc&utm_term=web-analytics&utm_content=st-brand-1&utm_campaign=brand

The campaign cookie will look like this:

 

How I can see the campaign information collected by _utmz cookie in my Google Analytics reports?

Check the ‘All traffic sources’ report or ‘campaigns’ report (not the Google Adwords campaigns report) in your Google Analytics reports.

 

The _utmz cookie has a 6 months time out. What does that means?

It means Google Analytics attribute visit to a campaign for up to 6 months or until the campaign cookie value is overwritten with another value.

 

Can I change the campaign cookie time out length?

Yes you can. Use the _setCampaignCookieTimeout() method in your Google Analytics tracking code. This method is used to specify when campaign cookie expiration should time out in milliseconds.

1 millisecond = 0.001 seconds

Syntax:  _gaq.push(['_setCampaignCookieTimeout', 100000]);

Here you are telling Google Analytics to delete the campaign cookie (_utmz) after 100 seconds.

 

Can I set the _utmz cookie to expire as soon as the browser window is closed?

Yes. For this set the expiration timeout of the _setCampaignCookieTimeout’ () method to 0. For e.g.

_ gaq.push(['_setCampaignCookieTimeout', 0]);

 

 

What is custom/user defined visitors segmentation in Google Analytics?

Visitor segmentation is used to label your visitors as male, female, member, non member, signed in or signed out visitors etc.

 

What is _utmv cookie and how can I set it on a visitor’s hard disk?

This is a visitor segmentation cookie which is used by Google Analytics to identify a visitor as member, non-member, pro-member, pro++ member, male, female, employee, non-employee etc.

To set this cookie you need to use the _setCustomVar() method in your Google Analytics tracking code.

Syntax: _setCustomVar(index, name, value, opt_scope)

Example: _gaq.push(['_setCustomVar', 1, 'visitor-type', 'pro-member', 3]);

 

How I can interpret _utmv cookie?

 

 

From the cookie above we can determine that the visitor is a pro member. 

Other Posts you may find useful:

 

 

Himanshu Sharma About the Author: is the founder of seotakeaways.com which provides SEO Consulting, PPC Management and Analytics Consulting services to medium and large size businesses. He holds a bachelors degree in ‘Internet Science’, is a member of 'Digital Analytics Association', a Google Analytics Certified Individual and a Certified Web Analyst. He is also the founder of EventEducation.com and EventPlanningForum.net.

My business thrives on referrals, so I really appreciate recommendations to people who would benefit from my help. Please feel free to endorse/forward my LinkedIn Profile to your clients, colleagues, friends and others you feel would benefit from SEO, PPC or Web Analytics.

 

 

  • http://www.quickdrycleaning.com Rahul Singh

    one of the excellent blog post in your blog and this blog giving me depth knowledge about Anlaytics Cookies part

    :)

    keep it up

    • Paras

      I want to add GA to my e-commerce site but i worried whether Google Analytics gathers any secure data like CreditCard details.Please confirm is it secure to go with Google Analytics

      • seohimanshu

        Google analytics doesn’t collect any credit card details. It is secure to use it.

  • Terry Lund

    This might be considered a bit of a nit pick comment, but the wording seems to suggest that a web server can read the contents of the cookies on a person’s hard drive. I believe it’s better (more accurate) to indicate that the user’s browser will send each of the cookies to the web server with each request for a page or other object (i.e images etc.).

    • http://www.seotakeaways.com/ Himanshu

      Thanks for pointing out the issue. I will look at the wordings.

  • http://www.seodailyupdates.com Sankar Datti

    Great article boss. Preparing for GA exam, this information helps me a lot. Good Work. Keep it up.

  • http://www.liquid-silver-marketing.co.uk Farky

    Excellent article very helpful at the moment as the eu cookie directive came into force lat week in the UK, 500k fine if we don’t make it clear about what cookies we use and why! Not too much information given my google about how we can be compliant think it also effects retargeting via AdWords

    • http://www.seotakeaways.com/ Himanshu

      Thanks Farky. Fortunately in UK, cookie law is not causing any tracking problem as such because of implied consent.

  • Deepali

    Excellent work Himanshu, Loved the post, however I felt that you must have written few more lines explaining the point as at some places I got bit confused. other than that I felt that this post is an excellent one and I’m going to share with my team as some are planning to take the GAIQ test so this post would be of great help to them.

    • http://www.seotakeaways.com/ Himanshu

      Hi Deepali! Can you please let me know which part you find confusing.

  • http://www.thyngster.com David Vallejo

    Great article but I noticed one error __utmv is only set for visitor scope (1) , visit and page scopes are not going to set a __utmv cookie .

    _setVar() does the same as _setCustomVar but just allow 1 variable, and it’s deprecated even if it’s still working.

    I would like to add that there are at least 2 more cookies on GA that you may want to add to this article:

    __umtx = For Optimizer / Content Experiments
    __utmli = For Enhanced Link Attribution : http://support.google.com/analytics/bin/answer.py?hl=en&answer=2558867

    ;)

  • zubair

    Hey Himanshu ……great work once again……it wud be great if you could write a post on Custom variables in Google analytics…..

    Cheer!!!!

  • zubair

    Hey Himanshu ……great work once again……it wud be great if you could write a post on Custom variables in Google analytics…..

    Cheer!!!!

    • seohimanshu

      Sure. I have been thinking of writing about it for a long time. But there are some issues which i need to sort out first to make the blog post more practical.

  • zubair

    Hey Himanshu ……great work once again……it wud be great if you could write a post on Custom variables in Google analytics…..

    Cheer!!!!

  • Guest

    I’ve been asked to

  • stevoarmstrong

    I’m doing a cookie audit at the moment and have been asked to find out what are the consequences of not accepting these cookies from Google. A one or two liner should suffice.

    • seohimanshu

      If you wont accept cookies then Google Analytics wont be able to track traffic on your website.

      • stevoarmstrong

        simple as, thank you!

  • hail

    why is it that some cookies say they will expire in 2023? thats 10years from now. You have listed that cookies only last up to 2 years.

    • seohimanshu

      where is 2023?

  • http://www.clubnetsem.com/ Dave

    Hey Himanshu. Do you know of a way of modifying the cookies to extend the 30 day view-through conversion? Say someone visits a website but doesn’t come back to actually convert for 4 or 5 months later, is there any way we can track this visitor for this period? Thanks

    • seohimanshu

      No. At present the look back window can be set to maximum 30 days. In the future GA will allow to set the look back window to up to 90 days (3 months). I don’t think look back window will ever be set for 4 to 5 months.

      • http://www.clubnetsem.com/ Dave

        Thanks for your response :) Are you aware of any other 3rd party tools / analytics tracking that may be able to track visitors for as long as this by any chance? Thanks.

        • seohimanshu

          no. please let me know if you find one.

  • Anthony

    29. Which technologies does Google Analytics
    use to track visitors?

    a)
    Java
    and four temporary cookies

    b)
    JavaScript
    and third-party cookies

    c)
    JavaScript
    and first-party cookies

    HTML only

    • seohimanshu

      Javascript and first party cookies.

  • Valentina

    Again, a very good and detailed post on cookies. Thank you for posting this. Can you explain how registration IDs function in relation to Visitor ID? Is it true that if a user is a lurker and comes back as a logged in user has different Visitor IDs?

    • seohimanshu

      The visitor ID is going to remain the same.

  • darf

    Hey there! Very nice article! Congratulations!

    I still have a question… Is it possible to know if the user is accessing a webpage by clicking a “paid” link? I mean, how to make the difference between people who click on the sponsored links and people who don’t do that…

    Thanks in advance!

    • seohimanshu

      You can find that through traffic sources report in Google Analytics.

      • darf

        Thanks for the answer!
        But do you know if there’s any other way to access this data via Java?

  • Ray

    I have GA set up on my website. Is it possible to read the Random Unique ID from the __utma cookie and assign that value as my internal customer ID when they buy something from my site?

    • seohimanshu

      No

  • SzU

    Hi again!
    Have you had the problem of getting a truncated value for the __utmz cookie when you try to access the .getValue() method? I’m experiencing that in my website and don’t know how to fix it.
    I’ve googled it and read that it’s something related to the cookie version (should be 1 instead of 0) but can’t fix it at all, I have no idea about how the cookie is created or managed. Have you experienced that? If so, is there any hint on how to fix that?
    Thanks in advance!

    • seohimanshu

      sorry i have not experienced anything like that.

  • Brooke

    This is fantastic Thanks Himanshu! I have some curious behavior on a website that I am managing – it looks like the Start, Current and Last Session times are all the same and these all refresh when the page is refreshed. Is that possibly connected to a cookie issue?

    Session Time – First : Wed Jan 22 2014 16:35:33 GMT-0500 (Eastern Standard Time)
    Session Time – Last : Wed Jan 22 2014 16:35:33 GMT-0500 (Eastern Standard Time)
    Session Time – Current : Wed Jan 22 2014 16:35:33 GMT-0500 (Eastern Standard Time)
    Campaign Time : Wed Jan 22 2014 16:35:33 GMT-0500 (Eastern Standard Time)

    • seohimanshu

      it could be a cookie problem or browser problem. Is this issue the same for all the websites you visit or is it just your website?

  • http://www.perfectbody.nl/ Eddy

    Hello Himanshu,

    Do you think it is possible to save all the data on the ‘thank you’ page and this information later to Google? I would like to send all conversion data to Google when I approve the order.

    Now I have customers which place 5 orders but only pay one. GA gives me unreal statistics in that matter. Can this be solved?

    • seotakeaways

      Hi Eddy! Sorry for the late reply. Somehow i missed your comment. I am not sure how your ecommerce tracking has been setup. But Ideally the ‘thank you’ page should be displayed only for approved orders. Why do you need to manually approve orders?

      • http://www.perfectbody.nl/ Eddy

        Hi Himanshu! I received many orders with the payment option ‘Wire the money’. Unfortunately, a lot of those orders are not paid. But for Google analytics they are so I get unreal statistics. It would be great if there is a solution for this.

  • Deepak

    Hi Himanshu,

    I have a question regarding the expiry time of _utmz campaign cookie. In your blog you have mentioned it’s 6 months, but i think it is 24 months?
    Please clarify