How to track registered users with Google Analytics and Google Tag Manager V2

tracking registered users activity on different mobile devices

Wondering if Samsung Galaxy is more popular than iPhone when engaging with your content? Then set up the User-ID view to see your logged in users’ activity and evaluate behaviour by the device.

With the activity data you collect in the registered users view, you can improve the analysis of your customers’ behaviour by seeing which devices are used to sign up and access your website.

track registered users in google analytics

To summarise the benefits:

  • You get access to the Cross-Device reports, which allow you to analyse which devices your users use to engage with your content. See what the Cross-Device reports look like.
  • You improve your understanding of logged in users who often engage with the site’s content differently than those who aren’t registered.
  • You get a more accurate user count. In your standard analytics view, a new user is counted every time your site visitor switches to a new device or starts a new session. With the registered user view, you give each user a unique ID, which helps to stitch together various activities carried out by the user.
  • You can find out which devices users prefer for different engagement activities across multiple sessions. This helps with tailoring your campaign and content to different devices and activities.

To set this up, you need to have the user ID stored in the data layer. If you don’t have it set up, scroll to the bottom for an advanced hack.

Now let’s look at how to set up the tracking by using Google Analytics and Google Tag Manager V2.

Looking to implement the User-ID in your tracking code?

Check Google’s guidance.

Enable the feature in Google Analytics

Firstly, enable the User-ID feature by going to  Admin > Property > Tracking info > User-ID.

create registered users view in google analytics

Read through the short policy on what you’re allowed to track and not.

Google is very strict about tracking personally identifiable information so you are not allowed to send any personally identifiable information, such as names and email addresses. But numbered IDs or hashed emails are fine to use.

user id policy in google analytics

To agree to the terms, follow the steps and click ‘create.’

Create the variable in Google Tag Manager

Now go to GTM variables and click ‘new’.

Select Data Layer Variable type and use the name stored in your data layer, e.g. uid or user ID

create user id variable in data layer gtm v2

Add the variable to your pageview tag

Go to edit your pageview tag and click on More settings > Fields to set.

Click Add field, enter the field name as &uid and select the variable you’ve just created – eg {{uid}} or {{userID}}.

add user id variable to pageview tag

Test you’re seeing activity in the newly created registered users view with your login, or a test one if you have it.

Don’t forget to publish your GTM container for tracking to work.

Advanced hack

If for some reason you can’t get your developer to store a user ID in the data layer, there is a way around it.

We’ve created a javascript variable to get a username off the page and hash it prior to sending it to GA.

hashed username

For this, you need to pick a custom Javascript type variable and enter the script below into the custom javascript field.

This javascript requires either your developer or you to customise it to work on your page (see the notes in the second and third lines).

function() {
//dependent on using Jquery selectors
//replace ‘.menuTitle small a’ with the selector for your username
var name = $(‘.menuTitle small a’).text();
var hash = 0, i, chr, len;
if (name.length == 0) return hash;
for (i = 0, len = name.length; i < len; i++) {
chr = name.charCodeAt(i);
hash = ((hash << 5) – hash) + chr;
hash |= 0; // Convert to 32bit integer
return hash;

If you need help with any of the above, don’t hesitate to comment below or get in touch!

Comments 7
    1. Hi Tatiana. That part is Jquery to select the login element – it will vary for your site. I suggest you find a Javascript developer who can point you in the right direction.

  1. What should be the variable I would put in dataLayer, userId or uid? I got a bit confused with this.

    1. Hi Rafael, if you store the user ID in the dataLayer, which is required for this setup, you need to use whatever naming it has in the dataLayer for the Data Layer Variable Name when setting up your variable. So if it’s userID in the dataLayer, then you use userID; if it’s uid, then use that; if something else then use that something else. For the actual variable name use whatever is easily understandable for other uses.

Comments are closed.

How to remove referral spam from historical data in Google Analytics

How to remove referral spam from historical data in Google Analytics

This is a quick follow-up to my guide on how to exclude referral spam from your

7 quick wins to speed up your site analysis techniques in Google Analytics

7 quick wins to speed up your site analysis techniques in Google Analytics

Analysis and reporting are the most time-consuming aspects of site or app

You May Also Like