How google analytics use cookies on websites

Google analytics is the first choice for any online business to track its visitors behaviors on websites. Many professional’s use Google analytics to plan their marketing strategy to drive more traffic into their websites/blogs. As resulted this tracking feature from Google getting popular among many organizations. So keeping this in mind i would like to explain the usage of cookies by Google analytics to track visitors behavior on websites.

Google analytics is a simple tool to track visitors behaviors while surfing web pages. It provides JavaScript libraries to website owners to record page information. Google analytics supports two JavaScript libraries for tracking website usage such as analytics.js and ga.js. These JavaScript libraries uses HTTP Cookies to record user behaviors on website pages.

Note: Google analytics does not collect personal information about your website users.

google analytics cookies

How both JavaScript libraries use cookies ?

Analytics.js:

Analytics.js is the new way to track visitors behaviors on the web. Google has recently introduced this JavaScript library to record user interaction with websites. This JavaScript library is similar to the previous(ga.js) library and perform same functionality with flexible approach. However new users can create new Google analytics account with this property and it is purely safe to include both JavaScript libraries into the same website.

Cookie Usage:

By default, this library sets cookies on the top level domain, excluding the leading dot, and sets the cookie path to the root level (/). The analytics.js library is a part of Universal Analytics and uses first party cookies containing an anonymous identifier used to distinguish users. First party cookies belongs to user website. This JavaScript library does not require setting cookies to transmit data to Google Analytics.

Name of Cookie Expiration time Description
_ga 2 Years Used to distinguish users

Note: Analytics.js library is in public beta by the writing of this article. Readers are advised to stay updated with latest updates at: https://developers.google.com/analytics/.

ga.js:

This JavaScript library is traditionally used by Google analytics to track visitors interactions with websites. It uses first party cookie to know few things such as:

  1. to determine particular domain to record
  2. to distinguish unique users.
  3. to record traffic sources
  4. to determine the start and end of a session
  5. to record number and time of previous visits

By default, this library sets cookies on the domain specified in the document.host browser property and sets the cookie path to the root level (/).

Note:  We can track visitor actions or click by adding ” _trackPageview() “ function to html and non-html files.

Cookie Usage:

Google Analytics uses up to five first-party cookies to track and store information about
a visitor. All these cookies are set by the _trackPageview() method which further tracks visitor location,visitor visits and many more attributes.  As i mentioned before that these cookies do not store any personal information about the visitor, so don’t worry about any other personal tracking. The five first party cookies of this JavaScript library are:

Name of Cookie Expiration time Description
_utma 2 Years from set/update Used to distinguish users and sessions. The cookie is created when the javascript library executes and no existing __utma cookies exists. The cookie is updated every time data is sent to Google Analytics.
_utmb 30 mins from set/update Used to determine new sessions/visits. The cookie is created when the javascript library executes and no existing __utmb cookies exists. The cookie is updated every time data is sent to Google Analytics.
_utmc End of browser session Not used in ga.js. Set for interoperability with urchin.js. Historically, this cookie operated in conjunction with the __utmb cookie to determine whether the user was in a new session/visit.
_utmz 6 months from set/update Stores the traffic source or campaign that explains how the user reached your site. The cookie is created when the javascript library executes and is updated every time data is sent to Google Analytics.
_utmv 2 years from set/update Used to store visitor-level custom variable data. This cookie is created when a developer uses the _setCustomVar method with a visitor level custom variable. This cookie was also used for the deprecated _setVar method. The cookie is updated every time data is sent to Google Analytics.

We can also use below mentioned methods to customize how cookies are set:

  1. _setDomainName – Sets the domain to which all cookies will be set.
  2. _setCookiePath – Sets the path to which all cookies will be set.
  3. _setVisitorCookieTimeout – Sets the Google Analytics visitor cookie expiration in milliseconds.
  4. _setSessionCookieTimeout – Sets the new session cookie timeout in milliseconds.
  5. _setCampaignCookieTimeout – Sets the campaign tracking cookie expiration time in milliseconds.

urchin.js:

Historically, Google Analytics provided a JavaScript measurement library named urchin.js. When the newer ga.js library launched, developers were encouraged to migrate to the new library. For sites that haven not completed the migration, urchin.js sets cookies identically to what is set in ga.js.

Note:  Google changes the number and format of the cookies time to time. So before using any of above information, readers are advised to check the format of the cookies to ensure they have not changed.

Knowledge Source:  Google Analytics

Uploaded by:  Author