Cross device tracking with User ID in Google Tag Manager

This article is in conjunction with the article: Guide to Cross device tracking with User Id in Google Analytics, where I introduced the concept of User ID and explained in great detail about:

#1 What is User ID

#2 Difference between User ID and Client ID

#3 Benefits and limitations of User ID

#4 Session Stitching

#5 Various User ID terminologies (User ID views, User ID hits, User ID sessions)

#6 Various cross device reports

So I won’t be explaining the very basics of User ID in the present article.

I have written this article under the assumption that you are already familiar with the concept of User ID in Google Analytics and the user authentication system that you use is ‘website login’.

If you are using a user authentication system other than ‘website login’ like: biometric identification, loyalty cards, wrist bands etc then you also need to use measurement protocol and my article does not cover that.

I selected ‘website login’ as authentication system because it is most widely used. Needless to say, if you don’t authenticate users on your website then User ID is not useful for you.

Today, I will show you how to implement cross device tracking with User ID in Google Tag Manager when your authentication system is a ‘website login’.

Here is what I am going to do in a nutshell:

#1 Enable user id feature and create a User ID View

#2 Define a new custom dimension for User Id

#3 Generate User ID and push it into data layer

#4 Pull User ID from data layer into Google Tag Manager

#5 Send User ID from Google Tag Manager to Google Analytics

Get the E-book (72 Pages)

Get the E-Book (62 Pages)

#1 Enable user id feature & create a new User Id view

Step-1: Login to your Google Analytics account and then go to the Admin section.

Step-2: Click on the ‘User ID’ link under ‘Property’ > ‘Tracking Info’ as shown below:

tracking info

Step-3: Read the user id usage policy and set the toggle button to ON:

review the user id policy

According to user id usage policy, your user ids can not contain any personally identifiable data (like email address, names etc).

Step-4: Click on the ‘next step’ button twice (keeping the ‘session unification’ settings intact i.e. ON).

Step-5: Click on the ‘create’ button to create a new user id view:

create user id reporting viewYou need to create this view, as user id data can appear only in the user id view.

#2 Define a new custom dimension for User Id

This step is optional. But if you want to see user id data in your GA reports then you need to define a new custom dimension with user level scope in your GA property:

user id custom dimension

You can learn more about creating custom dimensions from this article: Google Analytics Dimensions and Metrics explained in great detail

#3 Generate User ID and push it into data layer

To generate user ids you will need to take the help of your web developer.

Ask him to write a script which generates unique IDs (any unique alphanumeric character set), assign them to each user as soon as they login, on your website and at the same time push user id into a data layer.

You can also use login ids as user ids, as long as they don’t contain personally identifiable information.

When a user login, push the user id into a data layer:

‘userID’ : [userid],

Note: here [userid] is a server variable and not the variable value.

If you are brand new to data layer, then read this article: Google Tag Manager Data Layer explained like never before

#4 Pull User ID from data layer into Google Tag Manager

In order to pull user id from the data layer into GTM, you need to create a data layer variable.

Follow the steps below:

Step-1: Login to your GTM account.

Step-2: Create a new data layer variable with following specifications:

user id data layer variable

If you are not sure how to create variables in Google Tag Manager, then read this article: Understanding Triggers and Variables in Google Tag Manager V2

#5 Send User ID from Google Tag Manager to Google Analytics

In order to send user id data to Google Analytics, you need to set the user id field by editing the tag you use to deploy Google Analytics on your website.

Follow the steps below:

Step-1: Login to your GTM account and edit the tag you use to deploy Google Analytics on your website.

Step-2: Click on ‘Fields to Set’ link under ‘More Settings’ as shown below:

fields to set

: Click on the ‘+Add Field’ button and then select ‘user id’ from the ‘Field Name’ drop down menu as shown below:

user id

Step-4: Select the data layer variable we just created (i.e. ‘pull user id from data layer’) by clicking on the ‘+’ button next to the ‘Value’ text field:

pull user id data layer variable

pull user id data layer variable2

Step-5: Click on the ‘Custom Dimensions’ link and then configure it as shown below:custom dimension google tag manager

Note: The index value of your custom dimension may not be 1. So use the one which is relevant in your situation.

Step-6: Save your Google Analytics tag, preview the container and then publish it.

Step-7: Go to your user id view and check for any new data in your ‘Cross Device reports’:

cross device reports

Step-8: Create a new custom report and use the ‘user id’ custom dimension.

That’s how you can implement Cross device tracking with user id in Google Tag Manager.

Other article you will find useful: How to identify web pages with zero traffic in Google Analytics

Most Popular E-Books from OptimizeSmart

Learn to read e-commerce reports book banner

How to learn and master Web Analytics and Google Analytics?

Take the Course

Check out my best selling books on Web Analytics and Conversion Optimization on Amazon

How to get lot more useful information?

I share lot more useful information on Web Analytics and Google Analytics on LinkedIn then I can via any other medium. So there is really an incentive for you, to follow me there.

Himanshu Sharma

Certified web analyst and founder of

My name is Himanshu Sharma and I help businesses find and fix their Google Analytics and conversion issues. If you have any questions or comments please contact me.

  • Over twelve years' experience in SEO, PPC and web analytics
  • Google Analytics certified
  • Google AdWords certified
  • Nominated for Digital Analytics Association Award for Excellence
  • Bachelors degree in Internet Science
  • Founder of and

I am also the author of four books:

error: Alert: Content is protected !!