By continuing to use our website, you consent to the use of cookies. Please refer our cookie policy for more details.

    How to Implement Google Analytics User-ID Feature in Google Tag Manager Easily

    When dealing with Google Analytics (GA), the number of users is not an accurate representation of the actual number of visitors on your website.

    Why? Because whenever a visitor lands on your website, Google Analytics stores a cookie and assigns a unique Client ID to them. When the visitor navigates to other pages, the ID continues to persist across pages and Google Analytics can identify that it is the same user navigating to different pages.

    However, if the same user accesses the website from a different device, a new Client ID is assigned to the user making your Google Analytics statistics inaccurate and often very extensive.

    What is the solution?

    You can use the Google Analytics’ User-ID feature and connect engagement data from different sessions, initiating from multiple devices to the same users.

    The feature helps you get data from multiple sessions and generate a unified and holistic interpretation of the user’s association with your business.

    Let’s take a look at how you can use User-ID in Google Tag Manager (GTM) and acquire it as a variable in GTM:

    Chapter 1: User-ID feature in Google Analytics (GA)

    When an ID associated with multiple sessions is sent to GA, the reports are unified and offer a more holistic view of the user’s association with the brand. It improves the accuracy of User Metrics and also unlocks a new set of reports.

    How does it work?

    • It modifies data in the User Explorer report and replaces the Client ID with the User-ID that you provide
    • This unlocks Audience > Behaviour > and allows you to see the total visitors that have User-IDs assigned through the User-ID Coverage report
    • From Audience > you can see how devices are overlapping with Cross-Device reports
    • You will also be able to identify what are the most used devices among your visitors – whether it was a desktop, mobile phone, or tab
    • Additionally, you will be able to identify which device generated the highest conversions

    Thus, the User-ID feature increases the accuracy of user metrics, even for non-User-ID views.

    Chapter 2: Enabling User-ID reporting in GA

    To enable the User-ID feature, you must follow the steps below:

    1. Enable User-ID reporting in GA

    • Get Edit permission for GA property
    • Sign in to GA, choose the property you wish to edit and enter Admin
    • From the Property column, click on User-ID under Tracking Info
    • Go through the User-ID Policy
    • Agree to it and click on Next Steps

    2. Create a view exclusively for data with User-ID

    • Create a new view in the same GA property by clicking the Create button in the same wizard
    • Remember, it is possible to create multiple User-ID views in the same property, but it is not possible to transform standard views into User-ID views

    3. Send a User-ID with GTM from your platform to GA

    Chapter 3: Enabling User-ID feature

    Before we discuss the method, let’s clarify one thing not everything can be labeled as a User-ID. GA’s Terms of Services don’t allow you to track personally identifiable information like email address, social security numbers, etc.

    So, if you use email addresses to identify different users in your CRM, it is not possible to use your email address as User-ID in Google Analytics.

    Use a User-ID that is less readable, for example, johnpumpkin@companyname.com cannot be used as a User-ID, but 547576erptrue3212 can!

    How do you enable this feature?

    Simple, ask your developer to push the User-ID into the Data Layer by using the following code:

    When working on a regular website that refreshes the whole page during navigation, place the code above the GTM container in a way that it is available with the All Pages GTM Trigger.

    However, the location of the code doesn’t really matter when working on single page applications.

    Additionally, you can push this code in every new page load, i.e. previous data values are removed when a page is refreshed entirely. In this case, the code will look like this:

    Once the code is pushed, return to your GTM account, go to the current website’s container and enable Preview and Debug mode.

    After that, visit your website and refresh it. Make sure you are logged out when refreshing. Successful authentication would bring out a login in the Preview console.

    Look for userID parameter after switching to the Data Layer tab in the Preview console.

    You need to turn User-ID information into a GTM Variable before you can use it in your tags or triggers. For this, you will have to create a Data Layer Variable for the specific User-ID.

    Storing the ID in a cookie

    User-ID can also be stored in a cookie. Here is how it works:

    • Customer visits your website for the first time
    • The User-ID is pushed into the Data Layer using a developer’s code
    • A customized JavaScript Variable confirms if that User-ID is in the DL and then stores the information in a cookie
    • In case the User-ID in not available in the DL, then the value of the cookie is used
    • Send the cookie’s value with each Google Analytics hit

    Let’s take a look at the details now:

    Firstly, you need to create a 1st Party Cookie Variable.

    Remember, the name field is case-sensitive. This cookie originates from a JavaScript code, which is as follows:

    In case you name your variables anything else apart from {{dlv – User-ID}} & {{cookie – User-ID}}, then you should rename them in the aforementioned script.

    So, if userid is present in the DL, a cookie is stored in a browser as userid. If not, then the cookie’s values are restored in the script.

    In case the userid isn’t found anywhere, variable returns undefined and the User-ID is not sent to GA.

    To pass the User-ID with every GA hit, enter your GA Settings Variable > Click on More Settings > select Fields to Set and enter the following values.

    Also, if you use a different name for ‘Custom JavaScript Variable’, then the same name needs to be used in the value field.

    Don’t forget to ask your legal team about the permissions you have to store User-ID in a cookie.

    Chapter 4: Updating Google Analytics Settings Variable

    Now that you know how to enable the User-ID features in GA, we can now go ahead and use it in GA tags.  

    To do this, update your GA Settings Variable. When you have configured the User-ID, leaving any exclusions on a tag level, all the Universal Analytics tags will inherit the setting automatically.

    In the GTM container, enter Variables and select the GA Setting Variable being used in Universal Analytics Tags.

    Click ‘More Settings’ > ‘Fields to Set’ and enter the following details:

    • userId
    • Variable that returns to User-ID

    Note: In order to see every hit, such as events, page views or more, in GA User-ID view, the User-ID needs to pass with every hit. That is why we configure User-ID on the level of GA Settings Variable apart from Pageview tag.

    Chapter 5: Checking the preview and debugging the console

    One popular way to do so is with a browser extension. Used by a majority of GTM users, Tag Assistant or a GA debugger for testing GA tracking is an easy way to go.

    Install the Tag Assistant extension and a blue tag icon will appear on the top right corner of your browser.

    The extension is in ‘sleep mode’ by default and doesn’t check anything that happens on a page. You must enable it by clicking the blue tag icon.

    When you refresh the page, if any Google products are implemented on the page, you will be able to see a particular number in the icon. This represents the count of tags found.

    Get a detailed list of the tags by clicking the icon again. You can derive more details from GA and see the data that was passed, the number of events that were fired, scopes of improvement and more.

    Note: You might have to scroll down a little in the Tag Assistant window to find the ID.

    Chapter 6: Visitor Consent (GDPR)

    No matter where you are located, if you’re tracking traffic originating from the European Union, the User-ID setup in GTM will not be successfully completed unless you make it GDPR compliant.

    You can have consent banners on your website with GTM in order to get user consent. The process is as follows:

    • User visits a website
    • A banner asking for consent to track personal information appears
    • The user gives consent by agreeing
    • Consent is stored in a cookie

    To Wrap Up

    The User-ID feature will help you identify cross-device data while giving you accurate user and session counts. Since it helps link together sessions by the same user on different devices, there might be a decrease in visitors.

    Have any other questions about User-ID in GTM? Reach out to us through the comments section.

    To find out more about our digital marketing services, email us at info@grazitti.com or visit our website.

    Subscribe to latest updates

    Get in Touch