If you use or have implemented Google Analytics 4, you've likely come across the terms Client ID and User ID. We're going to be exploring what these are and how you can find the values being sent for each one when using our Google Analytics 4 extension for the Magento 2 platform.
What are the Client ID and User ID values?
What is the Client ID?
The Client ID is a unique identifier that Google Analytics uses to differentiate between your website visitors. The Client ID is session/device-based and is initialised and stored in a cookie generated when a visitor accesses your store.
Google Analytics then uses this generated identifier to track users across multiple pages of your website. The process looks a bit like this:
- A visitor accesses your website.
- Google Analytics assigns the visitor a cookie with a generated Client ID.
- When the user navigates to a different page on the store, Google verifies the current cookies and looks for one with a Client ID. If it's successful in finding one, it determines that the page view is attributed to the same visitor.
This is all great, however, a problem arises if the same visitor accesses your website using a different device or browser, or clears their browser cookies. In these scenarios, Google Analytics will have to assign a different Client ID, and there'll be no way to assign any subsequent actions to the initial visitor. The solution to this is to send a User ID as well.
How to find the Client ID via the browser?
You can view the current Client ID very easily using your browser. The guide below applies to Google Chrome, but the process should be similar on other modern browsers as well. Follow these steps to find the Client ID:
- Access your website's frontend and open up the console by right clicking the page and clicking on Inspect.
- Access the Application tab and expand the Cookies section in the menu on the left-hand side of the console window.
- Apply a filter for "_ga " to find the cookie responsible for storing the Client ID. The value is composed of GA1.1 + Client ID + TimeStamp. The string in the middle represents the actual Client ID. In the example below, our Client ID is 1744161673.
How to find the Client ID via the Measurement Protocol Log
If you're using the PRO version of our Google Analytics 4 extension, there's a good chance you're using the Measurement Protocol functionality to send event data to Google Analytics server-side, which improves tracking accuracy for the event in question.
If that's the case, you have the option to enable the generation of a log file which includes data about every event enabled for Measurement Protocol. The setting is found in Admin -> WeltPixel -> Google Analytics 4 eCommerce PRO -> Measurement Protocol Tracking Configuration -> Enable File Log.
To find the log file, access your Magento 2 instance via your FTP/SFTP software and navigate into var/log. Trigger an event on the front end of your store and refresh the server files. If you didn't already have a ga4.log file, you should be able to see one now. Open the file and search for client_id. You should now be able to cross-reference this ID to make sure it matches the one generated by Google Analytics in the browser cookie:
What is the User ID?
The User ID can be seen as an extension to the Client ID, which serves to provide more granularity when attributing a specific session to a specific visitor. The value of the User ID is not random, but rather a value that's sent by your website or application which corresponds and identifies a specific user entity. Magento 2 provides a specific User ID for every customer account created on the store, which means our extension can find it, store it and send it to Google Analytics.
Once a User ID is provided, Google Analytics can track a visitor across multiple devices and sessions, regardless of whether their Client ID changes or not!
Note: The User ID is only made available after the visitor logs in, so if your website doesn't include an account creation system, you won't be able to send a User ID.
Note: The User ID value you send should not include personally identifiable information such as email addresses or names because that would go against Google policies. Magento 2 uses a number/string of numbers for this purpose.
How to find the User ID?
The process of finding and confirming User ID depends on how it's being sent. If you're using our Google Analytics 4 extension, it's very simple to find the User ID. There are two ways to do so, depending on whether you're using client-side tracking or server-side tracking (Measurement Protocol, available in the PRO version).
Finding the User ID via Client-Side Tracking
You can use Google Tag Manager's Preview Mode or Google Analytics 4's DebugView for this purpose. To find out more details about how to use DebugView, check out this article: How to preview and monitor Google Analytics 4 events using Debug View. In this example, we'll be using DebugView.
- After setting up DebugView and confirming your events are being recorded, open up your website's frontend and log in to your user account. This is very important as the User ID will not otherwise be sent.
- Trigger an event and wait for it to show up in DebugView.
- Click on the event and open the User Properties tab.
- Open the user_id property and you should see the User ID which corresponds to the Magento Customer ID:
Finding the User ID via the Measurement Protocol Log
If you have your event tracking implemented via our extension's Measurement Protocol functionality (available in the PRO version), there's another way you can find and confirm that the User ID is being sent. The extension has a setting which enables you to choose whether or not to send the User ID, and you'll first need to make sure this setting is set to Yes. You can find it in Admin -> WeltPixel -> Google Analytics 4 eCommerce PRO -> Measurement Protocol Tracking Configuration -> Send User-ID.
Once this setting is enabled, access your Magento 2 instance via your FTP/SFTP software and navigate into var/log. Trigger an event on the front end of your store and refresh the server files. If you didn't already have a ga4.log file, you should be able to see one now. Open the file and search for user_id:
Congrats! You now know the difference between the Google Analytics 4 Client ID and User ID, as well as why they're both useful and how to find and confirm your store is sending them to Google Analytics!