As a website owner, you certainly use Google Analytics to learn more about the user’s behavior on your website. Probably you are familiar with the different Google Analytics reports and you consult them on a daily basis. But do you know how exactly Google Analytics collects data?
You have probably heard that Google Analytics relies on cookies to remember and to record a users’ behavior on a website. But what are cookies?
Continue reading this article to learn how exactly Google Analytics works and collects its data.
What is Google Analytics?
Google Analytics is the world’s most popular web analytics tool. It’s a software that is connected to your website through a snippet of Javascript code. This Javascript code (also called tracking code) is unique for each website and needs to be placed on every page of your website that you want to track.
Currently, Google Analytics supports two types of JavaScript libraries (tags): analytics.js and ga.js. You can think of them as two versions of the Google Analytics tracking code. The tracking code you place on your website is either analytics.js code or ga.js.
The Google Analytics JavaScript libraries use HTTP Cookies (commonly referred to as just “cookies”) to “remember” what a user has done and how he interacts with the website.
In other words, almost all the data you see in your GA account comes from the cookies.
What is a cookie?
A cookie is a small text file that a website places on a visitor’s browser. It’s a string of text characters (not bigger than 4 KB) that might look like the following:
“max-age=60; path=/; domain=velizaratellalyan.com”
Cookies are used by websites to remember and store the information about your visit. Each cookie contains the following data:
- A name-value pairs containing the actual data
- An expiry date after which the cookies will no longer be valid
- The domain and path of the server it should be sent to
For example, the below-mentioned cookie has 3 variables and one value for each variable:
- max-age, which is set to 60 – that’s the time in seconds the cookie will last;
- path, which is set to the “/”, – that’s the web page directory for which the cookie is valid. In this example, the cookie is set to the root of the web directory (“/”), which means that it is valid for the entire website.
- domain, which is set to “velizaratellalyan.com”, – this is the sub-domain for which the cookie is valid.
But a cookie can have many more variables (including user name, password,
language) which store different user preferences.
And every cookie has its own ID (a combination of letters and numbers) that
allows its identification.
As soon as you request a page from a server to which a cookie should be sent, the cookie is added to the HTTP header.
Server-side programs can then read out the information and apply the setting from the cookie to the page you’ve requested.
So every time you visit the website the cookie comes from, information about you is already available: you won’t have to re-type your password or to set up your preferred language again. Most of the cookies, however, don’t store personal information (name, phone number).
So that’s how cookies are used by websites (and search engines) to improve user’s experience and to simplify your navigation on the Web.
What different types of cookies websites use?
There are two different types of cookies.
- First party cookies are issued by the website being visited and the web browser. They allow the communication between this website and the browser back and forward. Only the website which issued the first party cookie can read it.
- Third-party cookies are sent to your browser by third-party websites (different from the website being visited). These websites are usually ad serving companies that use third-party cookies to remember what ads have already appeared on your browser. The cookies allow the ad serving website to deliver your ads relevant to your interests and to control the number of times you visualized a specific ad on your browser.
Why Google Analytics needs cookies?
Google Analytics also uses a set of cookies to collect information about
website users’ behavior and to report website usage statistics.
That’s possible thanks to the JavaScript tracking code.
JavaScript can create, read, and delete cookies and Google Analytics uses the JavaScript code to collect different information about visitors’ web sessions: to determine new sessions, to detect new visitors, to determine traffic sources or visitor’s segment.
GA’s JavaScript code either creates or updates the cookie on the website’s user’s browsers.
What types of cookies does Google Analytics use?
It’s important to know that Google Analytics mainly sets first-party cookies. The exact cookies that GA will use depend on the JavaScript library (Google Analytics tracking pixel’s version) being used.
The only third-party cookie that it uses is the DoubleClick cookie.
This cookie is set up by modifying the GA’s tracking code and it is used by websites that run re-marketing and display advertising campaigns. Thanks to the DoubleClick cookie the website is able to serve its ads on different Google properties (like Google Search) and across the web.
Throughout this yummy article, you learned what cookies are and how GA uses them to collect information. If you want to learn more about the exact type of cookies that Google Analytics sets, you can read my next entry to learn which first-party cookies are set by Google Analytics.