I often come across requests to prepare data that would include the number of Unique Users visiting a given site. In today's reality, however, this is more difficult than it might seem. In this article, I explain what exactly causes this and share proven ways to get around these difficulties.

Collect data and make the right decisions for your business!

How does Google Analytics recognize users, or what's the problem?

The number of unique users is always an estimate. This is because recognizing them is very difficult. This is influenced by several factors:

  • Using Multiple Devices and Browsers – Today, users use not only multiple devices (work computer, personal computer, and phone), but also multiple browsers. When you open a link while using mobile applications such as Facebook, Gmail, or LinkedIn, you will be registered as a different user in each of them.
  • Using incognito mode – even if a user accepts cookies in incognito mode, they will be recognized as a new user.
  • No consent to tracking – if the user has not consented to tracking (has rejected consent to analytical cookies), we cannot measure their activity.
  • Delete cookies or cookie expiry.
  • Intelligent Tracking Prevention (ITP) in Apple's Safari browser - the function affects, among other things, the lifetime of cookies, which has been shortened to 7 days
  • Blocking Google Analytics with various browser plugins e.g. Adblock Plus .
  • Using privacy-conscious browsers like Brave.

Can anything be done about this?

Yes and no. Unfortunately, we have to accept most of the factors I have listed that negatively affect the completeness and correctness of user data.

When it comes to data loss, server-side tagging can be a partial solution , but it won’t solve all the problems either. Another possible option is to use data loss modeling from users who have declined to be tracked . However, this method will only work on high-traffic sites that have properly implemented Consent Mode .

There is also an easy and inexpensive way to recognize users more effectively. For this purpose, it is worth implementing a user ID on the website .

What is a user ID?

User ID is a unique identifier, usually a string of numbers, that is assigned to a logged-in user. User ID allows you to track user activity without revealing their identity. Their data remains anonymous under the law, because the user ID itself is not considered personal data until it is linked to data that uniquely identifies the user.

What is client ID and how is it different from user ID?

In Google Analytics, both user ID and client ID are used to track users, but they differ in how they work and in their scope of application.

Client ID is something completely different than intuition suggests. It is a unique identifier automatically generated by Google Analytics for each device/browser that visits your website. Client IDs are stored in the browser. One real user can have several Google Analytics cookies, and therefore several client IDs.

What about the app?

Mobile apps use app instance identifiers, not cookies. An app instance identifier is a unique identifier assigned to an installed app. Implementing user IDs in apps is especially important for organizations that want to measure (logged in) user behavior across platforms, such as between an app and a website.

Identity for reporting purposes

When you configure GA, you have the option to choose your reporting identities . They are based on identifiers (known as identity spaces) such as:

  • Device identifier – a browser cookie or application instance identifier.
  • User ID – identifier assigned to the logged in user.
  • Data modeling – a technique for predicting data that has not been collected.

In addition, we have several levels of reporting identity available :

 

  • Device dependent – uses only the device ID.
  • Observed categories – uses device ID and user ID.
  • Mixed – uses all types of identifiers and modeling.

Do you think the best choice would be to use as many available identifiers as possible? Not necessarily.

In some cases, data modeling in Google Analytics can be flawed, so if you care more about precision than identifying broad trends, you may want to choose a lower reporting identity level. It's worth comparing data across identity levels to make sure the modeling isn't introducing significant distortions into your reports.

How do I check if Google Analytics collects user ID data?

You can use the dimension named "Logged in with user ID" and check if it accepts the values "yes". You can use this dimension in both standard reports (as a dimension, filter and comparison) and in Explore reports.

Having trouble with analytics?

How to implement user ID?

The most popular method of implementing a user ID is to use Google Tag Manager (GTM) . If Google Analytics is implemented in a different way, e.g. directly in the page code, it is best to ask your developer to add the user ID according to Google's instructions.

The most secure and optimal option is to use a user identifier that is placed in the data layer .

How to add user ID to data layer?

If you are not sure if there is a user ID in the data layer, you can look for it in GTM using the preview mode. Make sure you are logged in, because only then will the user ID have a value. In the data layer, the user ID can have different names, but they are most often similar to "user_id" or "userId".

The most secure and optimal option is to use a user identifier that is placed in the data layer .

Data Layer where UserId is visible

If there is no user ID in your data layer, ask your developer to implement it.

The code could look something like this. It should be sent on every pageview to make the data even more accurate on login events.

 window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'userId' : '123456789' // tu przekazywany jest identyfikator użytkownika }) <code readonly="true">window.dataLayer = window.dataLayer || []; window.dataLayer.push({ &#39;userId&#39; : &#39;123456789&#39; // tu przekazywany jest identyfikator użytkownika })</code> window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'userId' : '123456789' // tu przekazywany jest identyfikator użytkownika })
			

In addition, the code should be called on every pageview BEFORE the Google Tag Manager code. This is important because it will give us access to the user_id variable value during the container loaded event, which is the most popular rule for tags called "All pages".

If you want to add user_id also in login event, then event should look like this and be called when user logs in:

 window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event' : 'login', 'userId' : '123456789' // tu przekazywany jest identyfikator użytkownika }) <code readonly="true">window.dataLayer = window.dataLayer || []; window.dataLayer.push({ &#39;event&#39; : &#39;login&#39;, &#39;userId&#39; : &#39;123456789&#39; // tu przekazywany jest identyfikator użytkownika })</code> window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event' : 'login', 'userId' : '123456789' // tu przekazywany jest identyfikator użytkownika })
			

If you use any of the popular e-commerce platforms, the user ID may be part of the data layer generated by GTM plugins.

User ID implementation in GTM

If you have identified the identifier in the data layer, the first step is to create a data layer variable . In our case, the variable should be constructed like this:

The most secure and optimal option is to use a user identifier that is placed in the data layer .

Variable configuration in GTM

In the last step, go to edit the Google tag . Add a configuration parameter called “user_id” and the value of the variable you created a moment ago.

Tag configuration in GTM

Implementation of user ID in the mobile application

Tracking user IDs in a mobile app requires setup in Firebase using the SDK (Software Development Kit) available for Android and iOS. Click here for instructions.

The most secure and optimal option is to use a user identifier that is placed in the data layer .

Finally, make sure everything is working properly

The best way to test the new solution is to use DebugView, which is located in the Administration tab in GA4. Here's how:

  1. To see your traffic in DebugView, it is best to use the GTM preview.
  2. In the preview, go to your site without logging in and log in during your visit.
  3. Check in DebugView if information about logging in with user id appears in the event list.

If you prefer to have your company's data analyzed by professionals, contact us. We perform analytical activities for online stores, service companies, publishing houses, NGOs and many other businesses. We provide all our clients with comprehensive reports in a clear visual form. Here you will find more information about the scope of our services.

Need a free marketing consultation?