How Google Analytics 4 Uses Cookies to Track Visitors

Katie Rigby
25th June 2024

Cookies have been the main way marketers have tracked users visiting their websites. But how does Google Analytics use cookies, and how will this change? 

Every time you visit a website, you’re adding a cookie to your browser. That’s huge amounts of tracking information on you and the content you engage with. 

These cookies are an essential tool for marketers to better understand how people engage with their website. 

Google Analytics uses cookies to show more detail on who website visitors are and how they behave. 

Pretty useful. 

But as privacy laws change and tools move to better protect their users’ data, businesses like Google are left looking at the prospect of a cookieless future. 

So, let’s dive in. This blog will run you through: 

💡 Pro Tip

Ruler uses first-party cookies and unique user identifiers to monitor individual user journeys and connect them directly to revenue. When cookies and unique identifiers are unavailable, Ruler employs statistical models and machine learning to estimate the impact of each touchpoint on conversions and revenue, giving you visibility over campaign effectiveness.

Book a demo to see how Ruler works


Does GA4 use cookies? 

Yes, Google Analytics 4 utilises first-party cookies stored on your users’ browsers to track and distinguish between individual users and their browsing sessions. 

Related: How to collect first-party data

These cookies allow GA4 to create a detailed picture of your visitors’ journeys, including how they arrived at your site, their on-site behaviour, and their eventual departure.

It’s important to remember that because these cookies are used for website analytics, rather than essential functionalities, they don’t fall under the “necessary cookies” category. 

This means that if you’re using GA4 on your website, you’ll need to acquire explicit user consent before activating these cookies to comply with regulations like the GDPR (General Data Protection Regulation).

 GA4 primarily relies on two main cookies set by the analytics.js library:

1. _ga cookie: This cookie acts as the workhorse for distinguishing individual users. It assigns a unique identifier to each visitor, allowing GA4 to track their movements across your website and build user profiles.

2. ga<container-id> cookie: This cookie focuses on session state data. It tracks a user’s activity during a specific visit, helping GA4 understand things like session duration and page flow.

Both these cookies boast a default expiration time of two years, allowing GA4 to recognise returning visitors for an extended period.

In essence, when a user visits your site, the analytics.js library creates this first-party cookie duo. 

These cookies store information like unique user IDs, session details, and website interactions. This data is then securely transmitted to Google’s Analytics servers, where it’s processed and transformed into the reports and Explorations you see within your GA4 dashboard.

As mentioned earlier, before activating GA4 cookies, you’ll require user consent for GDPR compliance. 

To obtain this consent in a GDPR-approved manner, you’ll need a compliant cookie banner solution like the one offered by the Cookiebot consent management platform (CMP).

Google Consent Mode simplifies managing your GA data, cookies, and GDPR user consent all at once. 

Launched in September 2020 and updated in November 2023, Consent Mode is a game-changer for achieving a balance between data privacy and website analytics.

Here’s how it works:

Consent Mode acts as a bridge, communicating your users’ consent choices directly to Google tags and other services. 

Specifically, the “analytics_tag” setting within Consent Mode allows you to control the behaviour of analytics cookies. 

When a user withholds consent for these cookies, Consent Mode ensures they don’t fire at all.

But that doesn’t mean you’re left completely in the dark. 

Even without explicit consent, Consent Mode still provides you with valuable, aggregate, and non-identifying insights into your website’s performance. This includes metrics like overall traffic and user behaviour trends.


What is user ID in Google Analytics 4? 

In Google Analytics 4, you can access the user ID feature. 

Related: How to track individual users in Google Analytics

This allows you to associate identifiers with individual users so that you can connect their behaviour across different sessions and devices. 

As opposed to Google Analytics counting new users via cookies, it would instead use the user ID leading to more accurate user counts and more data on how users engage with your content.

How to get started 

First things first, you need to create a unique ID for each user and assign them to your users. This can be during login.

So when a user logins in via inserting an email address, that will create a unique ID that you can then use to track them onsite. 

Note It’s up to you to ensure that your use of user ID falls in line with the Google Analytics Terms of Service

Next, you need to ensure your property uses a reporting identity that includes the user ID option. 

First, head to Admin and make sure you select your desired property. 

In the Property column, click Reporting Identity

Select either By User-ID, Google signals, then device or By User-ID and device. 

To send your user IDs, read the full guide from Google


What you can do with user ID in GA4

There are many things you can do using your user ID in Google Analytics. 

They are: 

Compare signed-in with non-signed-in users

You can easily compare users who are signed in to those not by building a comparison that uses the Signed in with user ID dimension which should be set to ‘yes’. 

A comparison including the "Signed in with user ID" dimension and dimension value = yes

Look at user exploration

User exploration is a report that’s available within the Explore tab in GA4. 

You can configure a new exploration (or report) and drill down into the list to see detailed information about individual users, including: 

Create remarketing audiences 

Everyone is looking to create remarketing audiences following the iOS 14.5 update. And the user ID in GA4 can help as you can create audiences based on this field. 

If you’ve already linked your GA account to your Ads account, then these audiences will be available to add to campaigns in your shared library. 

The reality is, a significant portion of users (our data shows an average of 69%) reject cookie consent, limiting GA4’s ability to gather comprehensive user behaviour data.

As you know, when a user rejects Cookie Consent, GA4 employs modelling techniques to fill the gaps.

However, the lack of transparency in these models raises concerns about accuracy and trustworthiness. 

This, coupled with limitations in multi-touch attribution and post-conversion metrics like lead progression and revenue, leaves marketers struggling to understand the true impact of campaigns.

These challenges are why we’ve introduced probabilistic modelling into Ruler. 

Related: What is probabilistic attribution modelling?

Unlike GA4’s limited event tracking, Ruler leverages first-party cookies and user identifiers to track individual user journeys and link them directly to revenue. 

Additionally, Ruler utilises statistical models and machine learning to estimate the influence of each touchpoint on conversions in the absence of cookies and unique identifiers, providing marketers with a clearer picture of campaign effectiveness.

It uses advanced techniques like marketing mix modelling (MMM) to estimate channel contributions.

In the absence of MMM data, Ruler’s probabilistic attribution model turns to key indicators such as click-through rates, impressions and other user-level signals to generate impartial and data-driven reports. 

This allows us to: 


Getting comfortable with Google Analytics cookies? 

Keep in mind, cookies won’t last forever.

As Google transitions to a cookieless future, questions arise about the capabilities of machine learning in this new landscape.

Additionally, there are limitations to consider, such as the absence of certain multi-touch attribution models, lack of conversion metrics, and a short lookback window.

Thankfully, tools like Ruler can track each touchpoint of an individual user to revenue, and also use advanced machine learning to accurately attribute credit where it’s due.

Interested? Book a demo to see it in action, or sign up for our newsletter to stay informed.

analytics-banner-ruler-analytics