How does Google Analytics work?

16 January 2020
Why you should know how Google Analytics works
Google Analytics, as any analytics system, can provide a lack of, extra, or even incorrect data. That is why it is essential for all users to understand how it works. Once you know it, you will be able to easily spot any discrepancies GA may display and quickly adjust its settings in order to get the data you can truly rely on.

So, let's see what is required for Google Analytics to start operating on your site:

Remember to insert the GA code on every page of your website where you want to track your visitor's online activity.
So, once the code is correctly placed on your site, the data collection process will start.
An example of a Global Site Tag (gtag.js)

_ga cookie by Google Analytics

Every time a new person visits your web resource, Google Analytics tag will put several HTTP cookies into a visitor's browser and will keep them until they expire, or the visitor gets rid of them (don't worry, I will explain this part a bit later in the article).

The default GA cookie is called _ga and its main task is to store a randomly-generated Client ID associated with a visitor's browser.

What is the Client ID in Google Analytics?

So, Client ID is a unique ID that Google Analytics assigns to a website visitor through injection of the _ga cookie into his/her browser.

A Client ID looks like this 2145569444.1676281372 and in future articles I will be showing it to you in the GA interface and explaining what you can do with it.

Below is an example of a cookie with the Client ID:
GA1.2.2145569444.1676281372, where
  • GA1 - is a default part for all cookies of this type.
  • 2 - depends on the domain where the cookie is configured.
  • 2145569444 - is a randomly-generated ID.
  • 1676281372 - the timestamp when the cookie was first created.
By default, this cookie expires in 2 years, meaning that if a visitor does nothing to manually clear it from the browser, Google Analytics of this particular site will be tracking their activities during this period. And, every time a user arrives at your website using the same browser, the life of the cookie will be automatically extended by 2 years.

One should also remember that GA uses the Client ID to detect a unique visitor. In the future, the system will "see" these users as returning across different browsing sessions. However, if a user changes the browser or enters the website from another device - GA will not be able to link these activities. Instead, it will record all these visitors as new.
FYI: If visitors may sign up on your web resource and you can authenticate them - then you will be able to track unique users across different browsers and devices using GA's User ID feature.

Other Google Analytics' cookies

Other cookies which I spotted on various sites with the help of EditThisCookie Chrome plugin include:

  • _gid
  • _gat_<your_GA_property_ID> - when you don't have Tag Manager on your site
  • _gat - when you have Tag Manager on your site
  • _dc_gtm_<your_GA_property_ID> - when you have Tag Manager on your site
Examples of Google Analytics' cookies
EditThisCookie Chrome plugin results on Airbnb.com
Additional Google Analytics cookies will also collect and "remember" the following information:

  • the browser type and the language it is set to,
  • the geo-location,
  • the device (desktop, mobile or tablet),
  • the operating system (OS),
  • the source where the person came from,
  • the total time spent on the website and on each page separately,
  • the sequence in which the user traveled across your site, and other information.
However, let's not forget that the key job of the GA tracking code is to trace user interactions that happen on your web resource. These interactions are the different kinds of activities a user may perform while browsing your site such as: loading a page, clicking a button or a link, scrolling a page, etc.
When a user performs an action on your resource, the GA tracking code accumulates and forwards the updated user behavior data to Google Analytics.

What kind of hits does Google Analytics track?

Every time an interaction occurs, the GA tracking code sends a so-called "hit" to the Google Analytics system.

The most common types of hits are:
The "page view" hit is being sent to Google Analytics every time a visitor opens a new website page which contains the GA tracking code.
The "event" hit contains an interaction a user performs with a component of your site. This hit type allows us to track button and URL clicks, form submissions, page scrolls, downloads and other actions a user may take online. These hits also include four parameters they send to GA: category, event action, label (optional) and value (optional).
The "transaction" hit passes information about transactions, the product items bought, as well as the SKUs (stock keeping units). The Enhanced Ecommerce allows to record user behavior while interacting with the product on your ecommerce site. These interactions include: the number of product views, the number of clicks on a product item, the number of product description views, adding items to a cart, starting a checkout, payments, etc.
The "social" hits refer to social media interactions performed on your website, such as tweets, likes, shares, etc.
Hit, as a message to GA, includes some valuable information in the form of a __utm.gif request, which is a very long URL and may contain the following:

  • An automatically-generated user identifier (Client ID)
  • The language of the browser
  • The title of the viewed page
  • The visitor's screen dimensions
  • The geo-location
  • The browser type
  • The user's operating system
  • The GA ID which relates to a specific Google Analytics account

Every hit sent to GA contains a unique set of parameters. However, it will always include the Client ID for Google Analytics to determine whether the activities mentioned in the hit are coming from an existing user. Thus, this information will let GA understand if this particular visitor is a returning or a new one.

Note that every time a new interaction occurs, a hit with updated information will be forwarded to Google Analytics. The system, in turn, will record it as a single session - a summary of user actions on a given web resource grouped within a specific timeframe.

How Google Analytics works

So, having already learned about cookies and hits, you can easily understand a simplified explanation of Google Analytics works.
1
An undefined user, Peter, opens your website in a Chrome browser.
2
The Google Analytics' JavaScript code loads and asks whether Peter's browser already has your website's _ga cookie.
3
The code doesn't find the _ga cookie, so it cannot identify this user.
4
That is why, it adds the _ga cookie to his browser, generates a Client ID and starts tracking his actions, passing them and other useful information via hits to GA.
5
Peter leaves your site as a defined user.
6
The next time he arrives at your site using the same browser, the code will be able to identify him and continue tracking his usage history.
Simple scheme "How Google Analytics works"

Removing or opting out from cookies

As a site owner, you have to know that your visitors may opt-out or minimize Google Analytics tracking since they can:

  1. Adjust their browser setting which relate to cookies (Chrome, Firefox, Safari, etc.)
  2. Use plugins or other tools to block cookies
  3. Do not give consent to cookie collection when visiting the site
  4. Clear cookies after every visit to a website (Chrome)

Wrapping up

Let's summarize this blog post and see what actionable advice you can get from here:
1
Google Analytics may display incorrect data due to a large number of stages involved in data processing and its default settings. Understanding how it works will help you minimize data loss by customizing its configurations, as well as help you spot and fix any discrepancies arising during the data collection process.
2
Google Analytics uses HTTP cookies to differentiate visitors and collect additional information about them, and hits - to accompany the above mentioned data with user interactions, sending them over to GA.
3
The number of Users that you may see in the default Audience Overview GA report does not equal real visitors, but shows the number of unique browsers where a visitor opened your website. If a previously defined by GA user enters your website from a new device or a new browser, these visits will be counted as new Users in your GA reports.
The Google Analytics Audience Overview Report
comments powered by HyperComments
Made on
Tilda