Learn how to set up GA4 cookieless tracking and track user activity without cookies. Follow our easy guide to ensure privacy-friendly analytics in GA4.
What is cookieless tracking?
Cookieless tracking refers to the process of tracking user behaviour and interactions on websites or apps without relying on browser cookies, particularly third-party cookies used for tracking across multiple websites.
What is a cookie?
A cookie is a text file that is used to:
- Store information about user preferences, user location, and other details
- Protect users’ data from unauthorized access
- Maintain certain websites’ functionality
- Serve personalize ads to users and make advertising more effective via re-marketing
- Collect Google Analytics data and other tracking data.
Cookies are stored on a user’s hard disk and can be enabled or disabled via web browser settings.
For more information on cookies: Understanding Google Analytics 4 cookies – _ga cookie.
Classification of cookies.
In terms of privacy compliance, Cookies can be broadly classified into two categories:
#1 Essential cookies—These are the cookies required for maintaining website functionality and security. They can be first-party and/or third-party cookies.
#2 Non-essential cookies – These cookies are not required to maintain website functionality and security. They can be first-party and/or third-party cookies. Non-essential cookies are often used to enhance user experience, gather analytics, or serve personalised ads.
First-party cookies are issued by the website being visited, and only the website that issued them can read them. Whereas, third-party cookies are issued by the website(s) other than the website being visited.
Not all first-party cookies are essential cookies.
It is a common misconception that first-party cookies are inherently essential, but this is not true.
First-party cookies can be either essential or non-essential, depending on their purpose.
For example, a Google Analytics cookie is a first-party cookie but a non-essential cookie since the website can function perfectly well without gathering analytic data.
Not all third-party cookies are non-essential cookies.
Some third-party cookies are crucial for the core functionality and security of websites.
For example, if a website uses a third-party SSO provider (like Google or Facebook login), third-party cookies are essential to authenticate users and manage the login session across different websites.
These cookies enable users to sign in across different services without repeatedly entering credentials.
Cookies from payment processors like Stripe or PayPal can be essential for secure transactions on e-commerce sites.
Services like Cloudflare may use cookies that are essential for load balancing, DDoS protection, and optimising content delivery.
How GA4 provide Cookiless Tracking
GA4 (Google Analytics 4) primarily relies on first-party cookies (like the ‘_ga’ cookie) for tracking users and sessions under normal circumstances.
Still,
GA4 has mechanisms to provide cookieless tracking when cookies are not available or when users do not consent to cookie-based tracking.
GA4 uses the following techniques to track users even when cookies are not available or consent is not granted for cookie-based tracking:
#1 Behavioural modeling – Estimates user behaviour when they don’t consent to cookies.
#2 Conversion modeling – Estimates the impact of marketing when conversions can not be directly attributed to a traffic source.
#3 User-ID tracking – Allows users to be tracked across devices and browsers when they are logged in. If a user is logged in, the User ID can be used as the primary identifier across devices and sessions without needing cookies. In this case, it acts as a cookieless tracking method because the User-ID replaces the Client ID (stored in a cookie) as the key identifier.
#4 First-Party Data Collection – GA4 encourages businesses to use first-party data, such as email addresses or other login information, to identify users. This helps create a more comprehensive understanding of user behaviour across devices and sessions without relying entirely on cookies.
#5 Google Advanced Consent Mode – Allows for cookieless tracking through several mechanisms like Cookieless Pings, Default Consent States, Behavioral and Conversion Modeling, Anonymous Data Collection, etc.
How to set up Cookiless tracking in GA4?
You can set up cookieless tracking in GA4 by using the following storage mechanism (instead of cookies) to achieve as much functionality as possible without compromising user experience, functionality, or data privacy.
- Data Layers.
- Session Storage.
- Local Storage.
- URL Parameters.
- Server-side storage.
- Server-side tracking.
#1 Use a data layer instead of a first-party cookie for storing real-time data.
If you want to temporarily store data (like the data from UTM parameters) before consent is granted, use the data layer instead of the first-party cookie.
That way, you don’t need to place any analytics cookie before the consent is granted.
When a user lands on your page, you can capture the UTM parameters from the URL and temporarily store them in the data layer.
Once the user consents to tracking (through a cookie consent banner), you can then move the data from the data layer to an analytics tool like GA4.
Note: Only pass necessary and lightweight data through the data layer. For larger datasets, rely on server-side storage. Server-side storage replaces cookies for handling large or sensitive datasets that can’t be handled efficiently in the data layer.
#2 Use Session Storage for storing session specific data.
Use ‘Session Storage’ for data that only needs to persist for the duration of a user’s session. The session ends when a browser tab or window is closed by a user.
Session Storage is a part of web storage API that provides a programmatic interface for developers to interact with the browser’s session storage mechanism.
SessionStorage can replace analytics cookies for session-specific analytics, tracking user behaviour, page views, and interactions during a single session.
This approach is privacy-friendly because data is automatically cleared once the session ends (i.e. when the user closes the browser tab or window).
For example,
You can track how many pages a user views during a session by using session storage:
You can track how many times a user clicks a specific button during the session.
Tracking items added to a cart using SessionStorage
You can track items added to a shopping cart using SessionStorage by storing the cart data in an array or object, updating it as the user adds items, and retrieving it when needed during the session.
For example, each time a user adds an item to the cart, you update the cart stored in SessionStorage.
You can retrieve the cart from SessionStorage and display the items on the cart page.
You can also remove an item from the cart and update SessionStorage.
Note: Session Storage is not designed for long-term tracking. If you need to achieve long-term tracking without relying on cookies, consider alternative approaches, such as LocalStorage, server-side storage, or user authentication.
#3 Use Local Storage for storing persistent, non-sensitive data across sessions.
Use ‘Local Storage’ for storing persistent, non-sensitive data across multiple sessions.
Local Storage is a part of web storage API that provides a programmatic interface for developers to interact with the browser’s session storage mechanism.
LocalStorage can replace analytics persistent cookies for storing non-sensitive, persistent data that needs to remain across sessions and page reloads.
This approach is privacy-friendly because, unlike cookies, LocalStorage does not automatically transmit data to the server with each HTTP request, reducing the risk of unwanted data sharing or tracking across different websites.
For example,
You can use LocalStorage to store a unique identifier for each user.
This identifier helps in recognising returning users across multiple sessions:
You can store user preferences (such as theme, language, or layout settings) in LocalStorage so that they persist across sessions.
You can track the number of sessions a user has completed by incrementing a session counter in LocalStorage.
You can store and update the total number of purchases made by a user in LocalStorage.
#4 Use URL Parameters for cross-page tracking.
You can use URL parameters to pass tracking data from one page to another without relying on cookies or local storage.
This method is particularly useful when tracking data needs to be persisted across multiple pages but in a privacy-friendly way.
URL parameters are visible in the browser’s address bar and can be easily shared, logged, or cached.
If sensitive information (like personally identifiable information) is included in URL parameters, it may be exposed to third parties or leaked unintentionally.
Avoid storing sensitive data in URL parameters. If you have to store sensitive data, use anonymised or hashed values.
Use URL parameters in combination with sessionStorage or localStorage to avoid having to pass the data across every page via URLs.
For example, if you capture the UTM parameters on the landing page, store them in sessionStorage, and use them throughout the session without exposing them in subsequent URLs.
URL parameters offer a privacy-friendly alternative to cookies for passing session data between pages.
Unlike cookies, which are stored on the user’s device, URL parameters are transmitted with each page request. This means that sensitive data is not stored locally.
#5 Use server-side storage for sensitive or long-term tracking.
Server-side storage is a more secure and privacy-friendly approach for handling sensitive or long-term tracking compared to client-side mechanisms like cookies, LocalStorage, or SessionStorage.
Server-side storage refers to data stored on a web server or in a database that the server manages.
This data typically relates to user sessions, application state, or preferences.
Server-side storage data is more secure and reliable because it’s not affected by browser settings or user actions (like clearing cookies or switching devices).
Note: Cookies and server storage often work together. But server-side storage can function without cookies.
Key differences between DataLayers, SessionStorage, LocalStorage and ServerStorage
Following are the key differences between DataLayers, SessionStorage, LocalStorage, and ServerStorage in terms of their scope, persistence, and functionality:
For best results, use server-side storage along with data layers, sessionStorage, localStorage and URL parameters.
Each method complements the others by handling different types of data with various levels of security and persistence, ensuring both user privacy and website functionality.
Scenario: A user visits an e-commerce website, adds a product to their cart, and proceeds to checkout.
Landing Page:
- The user lands on the website with UTM parameters in the URL.
- The UTM parameters are captured and added to the data layer.
- The UTM parameters are stored in local storage for future reference.
Product Page:
- When a user views a product, the product information (e.g., productId, productName, productPrice) is added to the data layer.
- The viewed product is added to a session-based “recently viewed” list in session storage.
Cart Page:
- When a user adds a product to their cart, an ‘addToCart’ event is triggered, and the product information is added to the data layer.
- The user’s cart items are stored in local storage to persist across sessions.
- The cart data is sent to the server and stored in a database.
Checkout Page:
- Checkout events (e.g., ‘checkoutStarted’, ‘checkoutCompleted’) are triggered with relevant data.
- The checkout data is stored on the server, including customer information, shipping address, and payment details.
- Any temporary session data, such as shipping methods or coupon codes, is cleared.
By relying on data layers, SessionStorage, LocalStorage, URL parameters, and server-side storage, you can achieve the same functionality traditionally handled by first-party analytics cookies without compromising user experience, functionality, or data privacy.
#6 Server Side Tracking
GA4 Server Side Tracking is another cookiless tracking method in GA4.
Srver-side tracking allows you to send tracking data directly from your server to GA4, bypassing the need to rely on client-side cookies for user identification and behaviour tracking.
Server-side tracking allows you to overcome ad blockers, cookie consent issues and browser restrictions (such as ITP in Safari or ETP in Firefox), which can block or limit traditional cookie-based tracking.
Since data is processed server-side, you have more control over what data is collected, how it is anonymized, and when it is sent to GA4.
Following is an example of how you might send a page view event from your server to GA4 with the measurement protocol.
How to make GA4 Cookiless tracking Privacy Compliant.
Cookieless tracking often leads businesses to rely more on first-party data collection, but it is crucial to understand that first-party data collection does not automatically make you GDPR compliant.
Moving to first-party data collection (via cookiless tracking) is nonsense in terms of privacy compliance because you are still collecting third-party non-essential data but now in a first-party context.
The nature of the data collection often remains the same, even if it is done in a ‘first-party’ context.
When companies shift from third-party to first-party data collection, the data collected often includes the same type of non-essential, tracking-based information that third-party cookies would have previously collected.
In this context, the main privacy concern is not eliminated; it is simply reframed as ‘first-party data collection.’
Whether the data is collected by a first party or a third party, the real privacy issue lies in how the data is used, how much control users have over it, and whether they are aware of its collection.
Many websites that claim to use “first-party” data are still sharing that data with third-party vendors or services (e.g., Google Analytics, Facebook Pixel), even if the data is collected in a first-party context.
In other words, user data is still being funnelled to third-party service providers, but now it’s happening through the first party as an intermediary.
There are only two categories of data collection in terms of privacy compliance: Essential and Non-essential.
Essential data collection is necessary for a website or service’s basic functionality or security (e.g., session management, fraud prevention).
Non-essential data collection refers to data used for purposes like marketing, analytics, personalisation, and tracking, which aren’t required for the core operation of a website but are often used for business or optimisation purposes.
Which means,
Not all first-party cookies (like Google Analytics cookies) are essential cookies.
Not all third-party cookies are non-essential cookies.
Not all first-party data collection is privacy-compliant.
Not all third-party data collection is bad for privacy.
The data collection method (first-party vs. third-party) is not the most important factor in privacy compliance.
What truly matters is the purpose and necessity of the data being collected.
Instead of moving to first-party data collection, focus on privacy-driven data collection.
It emphasises that privacy is the priority, regardless of whether the data comes from first-party or third-party sources.
Stop being obsessed with first-party and third-party distinctions. Focus on privacy-driven data collection.
Display Consent Banner.
The majority of businesses that use GA4 server-side tagging are not GDPR compliant because they don’t display consent banners.
When did you last see a consent banner on a website using server-side tagging?
I am not referring to the cookie banner here.
Just because you use server-side tagging does not mean you no longer need to ask for consent. The cookie banner is replaced by the consent banner.
Server-side tagging doesn’t eliminate the need for consent under GDPR.Users should be informed about how their data is collected and used, even with server-side implementations.You are not GDPR compliant if you don’t display a consent banner.
Other Articles on GA4.
- Web Analytics Career Path – How to Become a Web Analyst.
- GA4 Form Interactions Tracking – Enhanced measurement.
- How to track form submissions in Google Analytics 4.
- How to send data from Google Search Console to BigQuery.
- How to fix duplicate events in Google Analytics 4 (GA4).
- How to use two Google Analytics codes on one page.
- How to import GA4 Conversions into Google Ads.
- What are predictive metrics in Google Analytics 4 (GA4).
- Google Tag Manager Event Tracking Tutorial.
- How to use Google Analytics 4 with iframe.
- Why GA4 Audiences not showing in Google Ads.
- Google Analytics 4 Scroll Tracking Tutorial.
- Why Google Ads and Google Analytics data don’t match & how to fix it.
- Google Analytics 4 Calculated Metrics with Examples.
- How to view subdomain traffic in Google Analytics 4.
- Google Analytics 4 Cookieless Tracking Setup.
- Using Funnel Exploration Report in Google Analytics 4.
- Google Advanced Consent Mode and GA4 BigQuery Export.
- Which Conversion Window to use in Google Analytics 4.
- Tracking single page apps in Google Analytics 4.