Stape
Search
Try for free

Cookieless tracking GA4: explained and set up guide for 2025

Ira Holubovska

Ira Holubovska

Author
Updated
May 12, 2025
Published
Nov 6, 2023
Also available in

With stricter privacy regulations and the phase-out of third-party cookies, traditional tracking in Google Analytics is becoming ineffective. GA4 still relies on cookies by default, despite its privacy-first design. To collect accurate data in GA4 without cookies, it should be implemented using server-side tracking. 

What is cookieless tracking?

Websites traditionally use cookies to track user actions, like saving cart items or recording ad clicks. But with growing privacy concerns, many are shifting to cookieless tracking.

Cookieless tracking relies on first-party data instead of browser-stored cookies. The most reliable way to implement this is through server-side tracking. This not only helps to get rid of cookies and make tracking more accurate but also makes it more compliant and has greater control over the user data.

Cookieless tracking in Google Analytics 4

Google Analytics 4 uses machine learning to model the behavior of users who did not consent to analytics cookies. They use the behavior of similar users who allowed consent to analytics cookies to model the behavior of those who did not agree to analytics cookies. 

To be eligible for machine learning, GA4 property should meet specific:

  • Consent mode is enabled across all pages
  • Tags should trigger before the consent dialog appears 
  • Google tags load in all cases, not only if the user consents
  • 1,000 events per day with analytics_storage='denied' for at least 7 days.
  • 1,000 daily users sending events with analytics_storage='granted' for at least 7 of the previous 28 days

If your GA4 property doesn't qualify for machine learning or if you discover that machine learning isn't providing accurate results, you have the option to rely on first-party data when a user opts out of analytics cookies and implement cookieless GA4 tracking. 

To make GA4 work correctly and recognize users who come back, you have to provide GA4 with the following information:

  • Client ID (cid)
  • Session ID (sid)
  • Session Count (sct)
  • First Visit (_fv)
  • User Engagement (seg)

To set up cookieless GA4 tracking when a user hasn't given consent, we'll use these tools:

How to set up cookieless tracking in Google Analytics 4

To determine if consent was granted or not, we use the gcs parameter. The default GA4 consent configuration sends requests to sGTM, but the request lacks some information. All GA4 requests are written to the Firestore. 

To determine if a user without consent has an active session in GA4, we will use the difference in the timestamp of the previous visit vs the current visit. If the difference is more than 30 minutes, we will update the session parameters in Firestore. 

Firestore will use the UserID as the document name and save details about the user session within these documents. While this is a straightforward way to organize Firestore, there are numerous other approaches to maintain data about the complete user experience in Firebase.

1.2 If needed, write data to Firestore. For this purpose, we use the Firestore Writer tag. Please check this detailed guide on how to use the Firestore Writer tag. We use the collection UserID. For each user ID, we create a new document that uses cid as a document name. 

Firestore Writer tag
Firestore Writer tag
Firestore Writer tag
Firestore Writer tag

1.3 The GA4 server-side tag has a standard configuration and triggers every time the GA4 client is claimed, and the user consents to analytics cookies. 

Google Analytics 4 tag 
Google Analytics 4 tag 
Google Analytics 4 tag
Google Analytics 4 tag

2.1 Existing users with active session

2.1.1 If consent to analytics cookies was not granted, we used Stape User ID power-up to add user ID in sGTM request headers. 

2.1.2 With the help of the Firestore Writer tag, we write data to Firestore and use Stape User ID as a document name.  

Google Analytics 4 tag
Google Analytics 4 tag

2.1.3 To check that the session is active, we use the Firestore Reader variable to extract the timestamp that is associated with the last visit of this user in the Firebase. Then, check the difference between the user's previous session timestamp and the current timestamp. If the timestamp is less than 30 minutes, the user has an existing session. 

Firestore Reader variable
Firestore Reader variable

2.1.4 Parameters are updated like below: 

  • cid and client_id is the value of Stape UserID
  • ga_session_number - a value of the ga_session_number in the Firestore
  • ga_session_id - a value of the ga_session_id in the Firestore
  • x-ga-mp2-seg (engaged session) is set to 1
  • x-ga-system_properties.fv (first visit), x-ga-system_properties.ss (session start), x-ga-system_properties.nsi (new session ID) are removed.

2.1.5 Send modified data to GA4. To update data before sending it to GA4, we use transformation. 

Send modified data to GA
Send modified data to GA
Send modified data to GA
Send modified data to GA
Send modified data to GA
Send modified data to GA

2.2 Existing user with no active sessions

2.2.1 If consent to analytics cookies was not granted, we used Stape User ID power-up to add user ID in sGTM request headers. 

2.2.2 Write user data based on Stape User ID in Firestore again with the help of the Firestore Writer tag.  

Write user data based on Stape User ID in Firestore
Write user data based on Stape User ID in Firestore

2.2.3 To check that the session is active, we use the Firestore Reader variable to extract the timestamp associated with this user in the Firebase. Then, check the difference between the user’s last session timestamp and the current timestamp. If the timestamp is more than 30 minutes, a new session has started. 

2.2.4 Parameters are updated like below: 

  • cid and client_id is the value of Stape UserID.
  • ga_session_id is a ga_session_id value from Firestore, previously set to timestamp in seconds.
  • ga_session_number is the ga_session_number number you have in Firestore plus 1.
  • x-ga-system_properties.ss (session start) is set to 1.
  • X-ga-mp2-seg (Engaged Session) is set to 1.
  • x-ga-system_properties.fv is removed.

2.2.5 Send modified data to GA4. To update data before sending it to GA4, we use transformation. Tag triggers when a GA4 client is claimed, consent is not granted, and the time difference between sessions is more than 30 minutes. 

Send modified data to GA4
Send modified data to GA4

2.3 New user

2.3.1. When analytics cookies are not allowed, use Stape’s User ID power-up to generate a user ID.

2.3.2. Check if a user with the same UserID already exists in Firestore. If no user with the same user ID is found, use a Firestore Writer tag to create a user with session details in the database. 

Firestore Writer tag<br>
Firestore Writer tag<br>
Firestore Writer tag
Firestore Writer tag

2.3.3 Parameters are updated like below: 

  • cid and client_id is the value of Stape UserID.
  • ga_session_id is ga_session_id from Firebase.
  • ga_session_number is the ga_session_number number you have in Firestore.
  • x-ga-system_properties.ss (session start) is set to 1.
  • x-ga-mp2-seg (engaged session) is set to 1.
  • x-ga-system_properties.fv (first visit) is set to 1.

2.3.4 Send modified data to GA4. 

Send data to GA4
Send data to GA4
Send data to GA4
Send data to GA4
Send data to GA4
Send data to GA4

Conclusion

Implementing cookieless Google Analytics 4 tracking through server Google Tag Manager represents a significant step forward in adapting to the changing landscape of online data privacy and user preferences. As the digital world evolves, gathering valuable insights without relying on cookies becomes essential. 

By using the power of server-side tracking and Google Tag Manager, businesses can maintain their commitment to data privacy while still harnessing the crucial data-driven insights provided by GA4. This approach not only ensures compliance with emerging regulations but also fosters trust with users concerned about their online privacy. As we navigate the cookieless future, embracing innovative solutions like server-side tracking and GA4 can help businesses stay competitive and relevant digitally.

Subscribe for updates:

we don’t spam!
author

Ira Holubovska

Author

Ira has 10+ years of digital marketing experience, with the last 5 focused on server-side tracking. She understands how and when it works across various digital marketing scenarios.

author

Comments

Try Stape for all things server-sideright now!