- Updated:
- April 6, 2018
- Published:
- April 18, 2016
Every day, we rely on Google Analytics (GA) to make data-driven decisions, the results of which depend heavily on data accuracy. Although GA provides many valuable insights, there are many caveats to keep in mind when analyzing GA data, especially for larger sites. For example, sampled data in GA reports provide results based on a representative sample of traffic for the date range selected. When you analyze data more granularly with a secondary dimension in an already segmented report, data is limited further to results for a percentage of that percentage.
In other words, the closer you get to individual user data, the more inaccurate your data may become.
GA is a great tool to provide a useful picture of your audience as a whole, but it does not provide as much detail on individual user interactions on your site. For example, the combination of devices used before a conversion, the lifetime value of different user types, and differences between members and non-members are not available in any basic GA reports. Even the number of users and sessions may be reported inaccurately in your current GA view.
We’ll explain why the user count is inaccurate in GA, the benefits of tracking user engagement, and how you can track individual users to gain new insights.
Why use User ID tracking?
GA already captures an ID for every user that visits your site, which is called a Client ID. However, a Client ID is not specific to browser and device types; a User ID is. In the regular GA view, the same user can enter your site simultaneously through Safari on an iPad, Chrome on a desktop, and via their phone, and it counts as three separate users and sessions.
User ID tracking is set up by creating a new view within GA that collects data through a custom data layer. This data layer is a one-line script that directs GA to stitch together all sessions that occur among different browsers and devices for the same user under the same ID.


Benefits of User ID Tracking
There are four main benefits to User ID tracking:
- More accurate user count. The new view allows GA to stitch together sessions previously separated by multiple entry points.
- Data segmented by logins. Typically, registered users behave differently than those who do not sign up (or sign in). User ID tracking allows you to compare the behavior of logged-in users to “guests.”
- More reports in GA. User ID tracking creates an entirely new view that collects only unique user data. The more granular reports in this view aren’t available in regular GA views.
- Relationships between devices and engagement. New views include Device Overlap, Device Paths, and Acquisition Device.
Think these new reporting capabilities could improve performance on your site or better allocate outside marketing efforts? Read on to learn how to set up User ID tracking easily in Google Tag Manager (GTM).
User ID Tracking Elements
To set up User ID tracking, a site must have Universal Analytics and Google Tag Manager installed, and an authentication system. In most cases, the authentication system is a login for returning customers.
Every page should contain (at least) two of the following codes in this order:
1. Universal Analytics code. Classic Analytics does not support the User ID feature, so migrate your site to Universal Analytics before setting up User ID tracking. (Ignore this step if implementing GA tracking through GTM.)
2. dataLayer script. This will push user ID data to your GTM container, which will look like this:
<script>dataLayer = [{'userID': '12483'}];</script>
Work with a developer to have the number in the script above populate with a unique User ID whenever a user logs in to the site. Usually, a unique number can be pulled from the login.
3. GTM container. Placed after the dataLayer script.
How to Set up User ID Tracking with Google Tag Manager
GTM is the easiest and most popular method to set up User ID tracking. Set up the GTM container to capture the unique User ID through a cookie or data layer variable. This tutorial focuses solely on the data layer method because it doesn’t require pre-established cookies.
After the above three codes have been placed on every page of the site, set up the GTM data layer variable and tag.
First, create a new data layer variable and configure it to collect data from the dataLayer script by assigning the name “userID”.
Once you have created a data layer variable, set up the tag. Set your tag’s product as “Google Analytics,” tag type as “Universal Analytics,” and attach the Tracking ID of the property you wish to track. The track type will be set as a pageview that fires on all pages because it acts as a “general data collecting” tag that will associate any and all hits with an assigned User ID.
Set custom fields to avoid double counting all hits that aren’t associated with a logged-in user. Open up the “More Settings” drop-down menu to set the custom field as “userid” with the data layer variable just created as the value.
This next step is optional but will enable you to compare datasets between logged-in users and guest users in the same reporting view. Set a custom secondary dimension, which will show up in regular reporting views, as seen below:
Once you’ve finished the tag, it should look like this:
Ta-da! The “hard” part is over. Just enable User ID tracking in your GA property and define the custom dimension to sort your data by User IDs.
In the Google Analytics Admin section under Property Settings, find “User-ID”. Agree to the User ID policy that states that you won’t upload any personal information along with the data you collect. Also, remember that you must let users know you are tracking them at an individual engagement level. Add a line or two in your privacy policy, and you should be set.
You also have the option to turn on Session Unification. Although not mandatory, Session Unification allows you to collect as much data as possible. Hits collected in a session before a user logs in are assigned to that user’s Unique ID after the subsequent login. The new User ID view will display data only from users assigned User IDs.
If you added in a custom dimension to your GTM tag in the previous step, identify the custom dimension in GA as well. Under “Custom Dimensions” in Admin, set the dimension’s name and scope. Use the exact name specified in the GTM tag and the scope “user”, since we are sorting by user-level data.


Curious to discover how tracking individual user data can benefit your site? Contact us today to get a free audit.
Comments
Great guide. I had some initial trouble setting up, but this was most helpful. Thanks Oeuyown!
Thanks for a clear and great guide!
Thank you so much for your tutorial on this, it really is making more sense to me now.
Unfortunately we are getting the “userID” as “Undefined” when following the steps
If you could offer some guidance or Help on what we may be doing wrong we would be very grateful!
Here is a screen shot of the Preview mode in GTM
http://prntscr.com/f6lcl2
Kind Regards
Hi Cathal,
I’m glad my post was helpful! I looked into the domains listed in the screenshot you provided and did not find a dataLayer set up for “userId”. However, it may be due to the limited information I have publicly.
I would check for the following:
– There is a dataLayer set up to populate the correct information for “userId”
– This dataLayer is placed above your GTM container in the source
– This dataLayer is spelled exactly the same with the same capitalization, “userId”, as specified in the GTM dataLayer variable
If you’ve checked for all of these and your field is still coming up as “undefined”, please feel free to contact me directly at oeuyown@workshopdigital.com! I will need more information than I’m able to gather publicly to debug this issue.
Thanks!
Thanks so much for the steps. I have a quick question. The variable name should be the same throughout, is that correct?
In the instructions to create the dataLayer you are using userID. When defining the variable, you are using userID also.
However, in the tag, you are naming it userId and doing the same in the custom dimension in Google Analytics. Is this on purpose.
I ask because i have made my variable as userID all over the place and the view is not populating at all.
Hi Ateeq,
Thanks for your comment! The GTM variable name must match the dataLayer name exactly, which is “userID.” Where you see me use “userId” is simply to name the custom dimension field that appears in Google Analytics. It’s okay to set the field NAME as something different as long as the VALUES are the exact userID dataLayer variable you created.
In the custom dimension settings in your UA tag, did you pull in the userID variable or just define the value yourself? {{userID}} is the correct value whereas “userID” would not pull in anything. I hope this helps!
Thanks!
Thanks so much for the response. I got it working using some of your explanation and some hit and trial. There is a problem with the userid case. I am afraid, there is some hard coding needed on my end. I don’t know if that is universal. Please see my steps here. http://ateeqahmad.com/wordpress/2017/07/13/track-userid-google-analytics/
Thank You! That is what I just was looking for!
With the update to GTM and its interface, I am having difficulty following these steps. It’s now a different setup for tags and I do not see the option to set fields as an advanced option. Please help! Thank you 🙂
Gina