hello@newnorth.nl+31 (0) 85 401 31 62
/Journal

User-IDs in GA4: tracking logged-in users across sessions and devices

GuideAnalytics2023.03.28
Freek Kampen
Freek KampenCo-founder, New North Digital

If your site has a login, you can send your own user IDs to GA4. What that gives you, and how to set it up.

What a User-ID gives you

Once GA4 knows a user ID, you can tie together every session and event from the same person. Across sessions, devices and platforms.

That unlocks a handful of things you can't do without one:

Specifically, you can

  • compare logged-in against logged-out users
  • zoom in on a single individual in Explorations
  • build remarketing audiences based on User-ID
  • deduplicate your reporting on User-ID
  • export to BigQuery and analyse at user level

What happens to events from before the login

Someone visits your site, clicks around and triggers events, all before there's an account or anyone logs in. At that point there's no ID yet. This is usually the bulk of your events.

When they do log in or create an account, GA4 attaches those earlier events to the User-ID after the fact. That lets you analyse what people do before they sign up.

Once someone logs out the link stops. In practice that happens rarely enough not to worry about.

How to set it up

  • Put the User-ID in the dataLayer. Your developer can push it, for example dataLayer.push({event: 'userData', user_id: 'abc123'}). Make sure that value updates dynamically.
  • On WordPress, plug-ins like GTM4WP often already handle this for you.
  • Create a dataLayer variable in GTM that reads the User-ID.
  • In your GA4 configuration tag, add a field with the key user_id and your variable as the value.
  • Test the setup, and you're done.

Mind your privacy obligations

Make sure you have consent and handle personal data carefully. GA4 doesn't allow personally identifiable information, so your User-ID can't be an email address or anything comparable.

Always use your own randomly generated IDs.

Want to talk about this?

Let's talk data.

Tell us about your stack, your goals, the data you wish you had.

Takes 1 minute