How Google Analytics Tracks Your Every Move After You Accept Any Cookie

/blog/avatar-andrii-minchekov.png

June 10, 2024, written by

Andrii Minchekov

[object Object]

This article explains how 📊Google Analytics cookies track your every move across websites once you give consent. Discover the intricate client-server interactions, the role of unique Client IDs, and the detailed process of data collection and analysis. Learn what specific data are collected, including page views, document locations, referrers, document titles, and browser/system information, to provide insightful analytics.

Google Analytics data collection scheme Google Analytics client-server interaction scheme

The sequence diagram illustrates the interactions between the user's browser, the website using Google Analytics, the Google Analytics script, and the Google Analytics server. It highlights the key role of the Google Analytics cookie in tracking user behavior across different websites.

Google Analytics data collection scheme explained

  1. User Visits First Website:

    • Action: The user navigates to www.example.com which uses Google Analytics script.
      The Google Analytics script runs and checks if the Google Analytics cookie is present. If not it sets cookie with ClientId and start tracking all user actions.
  2. User Visits Another Website:

    • Action: The user navigates from www.example.com to another site that uses Google Analytics, such as www.anotherexample.com.
  3. Web Page Loading:

    • Action: As the user's browser loads www.anotherexample.com, it executes the Google Analytics script included in the webpage.
  4. Script Execution:

    • Action: The Google Analytics script runs and checks if the Google Analytics cookie is present.
    • Details: This cookie would have been created during the user's previous visits to sites using Google Analytics.
  5. Data Collection Initiation:

    • Action: If the cookie is present, the script identifies the user/browser with the unique Client ID from the cookie.
    • Details: The script begins collecting data about the user's interaction with www.anotherexample.com.
  6. Data Collection and Cookie Access:

    • Action: The Google Analytics script collects user interaction data.
    • Details: The script accesses the Google Analytics cookie to retrieve the existing Client ID, ensuring continuity in tracking.
  7. Sending Data to Google Analytics Server:

    • Action: The collected data, along with the Client ID, is prepared to be sent to Google Analytics servers.
    • Details: This communication typically occurs during or shortly after the webpage loads.
  8. Data Processing by Google Analytics Server:

    • Action: The Google Analytics servers receive and process the data.
    • Details: The data is associated with the user's Client ID, allowing for an aggregated view of the user's behavior across different websites.

What data is sent from your web browser to the Google Analytics server?

When data is sent to Google Analytics servers, it includes information derived from the Google Analytics cookie and additional details collected by the GA script. This data is part of an HTTP request.

Key Data Points:

  1. Client ID (from Cookie):

    • A unique identifier, like: 123456789.987654321
  2. Pageview Hit Type:

    • For instance: pageview
  3. Document Location URL:

    • The current page URL, such as: http://www.example.com/about
  4. Document Referrer:

    • The referral page URL, like: http://www.google.com
  5. Document Title:

    • The title of the current page, e.g., About Us
  6. Browser/System Information:

    • Details like browser type, screen resolution, operating system, etc.

Example of HTTP Request to Google Analytics server

Here's a simplified representation of how this data might be structured in an HTTP GET request to the Google Analytics servers:

GET /collect?v=1&tid=UA-000000-2&cid=123456789.987654321&t=pageview&dl=http%3A%2F%2Fwww.example.com%2Fabout&dr=http%3A%2F%2Fwww.google.com&dt=About%20Us&... HTTP/1.1 Host: www.google-analytics.com

This structured data is sent via a background HTTP request, typically initiated by JavaScript on the webpage, and is processed by Google Analytics to provide insights into user behavior and website traffic.

Google Analytics client-server interaction
Google Analytics client-server communication
Google Analytics Cookie Usage Explained
Google Analytics Communication Architecture