Knowledge base article

User-IDs: Track logged-in users with GA4

3 minutes reading time

Do you have a login on your site? Would you like to analyze individual users in-depth in GA4? Well, you can. You can pass your own User IDs to Google Analytics. This way you can form a complete picture of your users. You can track them over different sessions, devices, and platforms. In this article, I will guide you through the process of setting up user IDs for tracking in GA4. Let’s go!

What can you do with unique User-IDs in GA4?

Once you register user-IDs in GA4 you have many more capabilities to analyse your users granularly. It gives you the opportunity to link all sessions and events to one user and understand them better. In GA4 it specifically allows you to:

  • Build a comparison of signed-in vs. non-signed-in users
  • Drill-down in Explorations to analyze individual users
  • Create remarketing audiences based on User-ID
  • De-duplicate reporting based on User-ID
  • Export to BigQuery to see user-level data

You can get very creative with the Explorations you can create with this data. Especially, when you export your data to BigQuery. To understand how it works, we need to have a look at how events get attributed to user-IDs.

What happens with the measured events before a login?

Imagine a users visits the page before creating an account or login in. They navigate on your website creating many different events. At that time they will not be linked to any user-ID, because you have none. This will be the bulk of your events.

Luckily for us, once the user does create an account or logs in, all the events that they created prior to that are linked to the User-ID at moment of log in. This gives you the opportunity to analyse what users do before creating an account for example.

What happens with the measured events after being logged in?

Once a user logs out you will lose the opportunity to link the events to their ID. Problably this will not happen that much anyway.

How to implement tracking of User-IDs in GA4?

So how do you send user-IDs to GA4? It is not that hard but you will need some help. Let’s have a look.

  1. Make User-ID available in the datalayer
    • a. Via developer:

      With the help of your developer you can push the user-ID to the dataLayer of your website. This way you can always grab it and pass it along with your events to GA4. The code below should be added where the user-ID value should be updated dynamically.

    • (datalayer.push({ 'event' : 'userData' , 'user_id' : 'abc123' })
    • b. Via a plugin:

      Many plugins for GA4 already populate the users ID to the dataLayer automatically. Take the GTM4WP for WordPress plugin. This makes it very easy for you to track your logged in users.

  2. Add a datalayer variable in GTM which grabs the User-ID
  3. GA4 User-ID GTM variable
  4. Modify your GA4 config tag
    • a. Add field to set with the key: “user_id”
    • b. Insert your variable as the value
    GA4 User-ID
  5. Test your setup and you are good to go!

Data privacy note: make sure you have the proper consent from your users and treat their PII with care. Also, GA4 does not allow you to send PII. So, the User-IDs cannot be PII like an e-mail. Because of this you should always add your own random ID.

The takeaway

Hopefully you know see the potential benefits of sending user-IDs to GA4. Implementing it should be that hard. But, if you have any issues, feel free to contact us.

Profielfoto Freek Kampen

By Freek Kampen

Data & Analytics specialist and co-owner of New North Digital. With a background in online advertising, I solve tracking and data issues for entrepreneurs and agencies.

Related

Continue learning

Looking for more answers?

Check out our knowledge base for more articles and glossary terms. Level up your knowledge with our articles on core concepts in web analytics.

Continue learning
Compare list
Close
Get help

Send us a message