• GA4 Hub
  • Posts
  • How to Get GA4 Client ID

How to Get GA4 Client ID

GA4 Question That You Might Have Too

“How do I get GA4 Client ID?”

This is a question one of the readers asked.

But before we look at the answers, let’s first understand what GA4 Client ID is.

GA4 Client ID is a unique ID that GA4 generates to track users on your site.  This ID is created on the user's first visit to the site and then stored in the browser cookie for future reference. The name of the GA4 cookie is “_ga”.

Here is an example of a GA4 Cookie value.


The characters after GA1.2. constitute the “Client ID”. In other words, Client ID starts at the 7th Character of the GA cookie.

If you want to store this ID in your backend system or send it to another tool then you will need to extract it from the cookie and pass it to whichever solution you desire.

Below are some ways to extract this ID

In Google Tag Manager

If you are using Google Tag Manager then follow these steps:

  1. Create a variable of type "1st Party Cookie".

  2. Configure it to pull the value of _ga cookie

  3. Create a new variable of type Custom JavaScript

  4. Write the following JavaScript code to pull the Client ID part from the _ga cookie. (See below). I am using substring (6) to extract the value of the “Client ID” from the cookie as the client ID starts at the 7th position in the Cookie and the JavaScript index starts from 0.

  5. This second variable is the one that you can use to send the "Client ID"

Without Google Tag Manager

If you are not using Google Tag Manager then follow these steps

  1. Write JavaScript code to pull to read _ga cookie

  2. In that code write code to extract the "Client ID" part of the cookie

  3. Return the extracted value as "Client ID"

 That’s it.

If you have any GA4 questions that you want me to answer in future posts then email those to me at [email protected]

Google Analytics 4 Help and Support

We are here to help you with all your Google Analytics needs. Our team can get you up and running in no time and also train you and your team to save you a lot of time so that you can focus on driving the business outcomes rather than configuring Google Analytics 4.

Online Course -Master GA4 with my comprehensive GA4 course on Optizent Academy
Workshop - We conduct the onsite customized workshop. Reach out to us for more details
Hire Us - We have helped several businesses implement and fix their GA4 issues. Are we the right agency for you? Contact us for a no-obligation conversation.

Thank you,
Anil Batra. Optizent.com