• Courses
    • Courses
    • Course bundles
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login
  • Courses
    • Courses
    • Course bundles
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login

March 28, 2025

How to Get Google Analytics Client ID? (5 Options)

Updated: March 28th, 2025

Let’s say that you are running Google Analytics on your website, and you (or your developers) need to fetch the GA Client ID. For example, maybe there is a need to send a request to the Measurement Protocol (which requires a client_id parameter).

Or do you just want to check your own client ID?

In this blog post, I will explain several methods to get a Google Analytics Client ID. First, I’ll start with technical (programmatic) options and end with the more basic ones.

 

Table of Contents

Here’s what you will learn in this article

  • #1. Using the “get” command in gtag()
  • #2. Fetching the value of a _ga cookie with pure JavaScript
  • #3. Fetching the value of a _ga cookie with Google Tag Manager
  • #4. Checking in the Google Analytics 4 interface
  • #5.Bigquery
  • Final Words
Subscribe and Get the Ebook - JavaScript for Google Tag Manager

 

Video tutorial

If you prefer video content, here’s a tutorial from my Youtube channel.

 

#1. Using the “get” command in gtag()

Google Analytics 4 tracking code (a.k.a. GTAG) offers a set of commands you can use for your convenience. One is get that can return values of certain fields/parameters in GA4.

Here’s an example of a command that you can execute right in your Google Chrome console:

gtag('get', 'G-XXXXXX', 'client_id', function(clientId) {console.log(clientId)})

Replace G-XXXXXX with your GA4 property’s measurement ID. Of course, if your developers want to use it, they will need to modify the code (the console.log part) in order to pass the client_id’s value to other parts of your website’s code.

However, remember that this method will work only if the GTAG tracking code is already loaded on a site.

 

#2. Fetching the value of a _ga cookie with pure JavaScript

When a visitor comes to your site for the first time and Google Analytics loads, it creates a _ga cookie that contains the GA client ID. If a visitor returns to your site and the cookie already exists, you can get its value. as soon as the page starts loading.

To do that, you (or your developers) can define a get_ga_clientid function. Once it is called, it will return a client ID from the _ga cookie. Here’s the code that could be used:

function get_ga_clientid() {
  var cookie = {};
  document.cookie.split(';').forEach(function(el) {
    var splitCookie = el.split('=');
    var key = splitCookie[0].trim();
    var value = splitCookie[1];
    cookie[key] = value;
  });
return cookie["_ga"].substring(6);
}

You can test this code directly in your browser’s console. First, make sure that _ga cookie is present in your browser. Then open the JavaScript console (on Windows, that’s F12 > Console), and paste the code I shared above. Hit enter.

Then call the function by entering the following command in the console (and then hit enter):

get_ga_clientid()

It will return your client_id.

 

#3. Fetching the value of a _ga cookie with Google Tag Manager

If you are using Google Tag Manager and you want to have the client ID as a variable, here’s an option.

Open the developer tools in your browser (usually accessible via F12 (on Windows) or right-click the page and select “Inspect”). Navigate to the Application tab (I am using Google Chrome in this example).

Go to Cookies and select your domain. Then locate the _ga cookie. Its value might look something like this (of course, in your case, the value will be different):

The last two numbers (with a dot between them) are the client id. So if you look at the screenshot above, the client ID value is 40030803.167153367.

If you want/need it, you can access that cookie with Google Tag Manager. In GTM, go to Variables > New > 1st party cookie and enter the following settings (name it exactly as I show in the screenshot below):

This variable will return the full value of the cookie, e.g., GA1.1.40032303.1671533621. If you want to parse just the last two numbers, go to Variables > New > Custom JavaScript and paste the following code (it will work only if you have named the 1st party cookie variable exactly as I did in the screenshot above).

function() {
  return {{ga cookie}}.substring(6)
}

This code will remove the first six characters of the _ga cookie, and the result will be 40032303.1671533621 (or any other numbers that were stored).

Subscribe and Get the Ebook - working with reports in ga4

#4. Checking in the Google Analytics 4 interface

To locate the client ID in Google Analytics 4, follow these steps:

Log in to your Google Analytics 4 account. Navigate to the Explore section. Click on User Explorer.

Within the User Explorer, you will see the client ID listed for each individual user.

There isn’t much you can do with these IDs here. However, if you want to check the client ids you have tracked quickly, well, this is the list.

 

#5.Bigquery

And last but not least. If you have already connected Google BigQuery with Google Analytics, the data will be streamed to BQ. So there, many events will contain a field called user_pseudo_id. This is just a fancy name for the client ID.

 

Get Google Analytics Client ID: Final Words

In this blog post, I wasn’t planning to talk about why the GA client ID is essential (there is another article for that). This time, we focused on a bunch of methods to find/get it. Some options were more technical (but they allow you to get Google Analytics client ID programmatically). Others were simpler (if you want to check a particular client ID manually).

I hope you gained a well-rounded understanding of various techniques here, allowing you to select the most suitable method based on your situation.

Julius Fedorovicius
In Google Analytics Tips
7 COMMENTS
Nick
  • Apr 1 2023
  • Reply

Julius, thank you for this post. Could you possibly answer 2 questions?
1. Is it possible to push this client id to GA4 with GA4 Event tag (like we did in UA with customTask) in order to have it as a secondary dimension?
2. Is it legal? :)
thank you!

    Julius Fedorovicius
    • Apr 2 2023
    • Reply

    Never send client id as as custom dimension to GA4. Otherwise, you will face high-cardinality issues.

      Nick
      • Apr 2 2023
      • Reply

      Got, it has something wrong with going over 500 unique values per day.. if I'm not mistaken. Thank you!

      Nick
      • Jun 17 2023
      • Reply

      Still, may I ask more specific question. We can pass Client ID only with transactions GA4 Event Tag (we have them far less than 500 a day). Is that a good solution? 😁

        Julius Fedorovicius
        • Jun 19 2023
        • Reply

        Should be ok

Piotrek
  • Apr 5 2023
  • Reply

Hi Julius,

I use gtag() to manage events and for initial setup.I faced some problem with client_id on debug mode. The representation of client_id looks like: "5.7978e+08" :/
In user explorer under App-instance ID looks ok so I am wondering if this have some negative impact of our data?

Best regards
Piotrek

Esther
  • Nov 28 2023
  • Reply

Is it possible to use the client_id as a Value Track parameter in Google Ads?

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *


 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey. Read more
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
Recent Posts
  • Setting up cookie consent for Microsoft Clarity (V2)
  • Conversion rate in Google Analytics 4
  • Google Tag Manager Data Layer Explained
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings