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

 

#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: https://support.google.com/analytics/answer/2709829?hl=en

 

#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:

dataLayer.push({
‘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


Step-3
: 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

 

Announcement about my books

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Himanshu Sharma

Certified web analyst and founder of OptimizeSmart.com

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 eleven 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 OptimizeSmart.com and EventEducation.com

I am also the author of three books:

error: Content is protected !!