User-ID: Measuring Real Users Instead of Devices



When Universal Analytics was released by Google, it marked a fundamental shift in the way we analyze our data – by truly enabling us to focus on users instead of visits. A key aspect of this shift to a user-oriented perspective on data is the ability to track cross-device behavior for individuals. Real individuals – real unique users!

This is absolutely crucial for businesses today, where customers come across multiple touchpoints across a variety of channels and devices every day. For a number of reasons, the User-ID is a significant change to Analytics. It allows us to:

  • Measure the amount of users to our digital properties with far greater accuracy.
  • Unlock greater insights with user-specific reports that are otherwise unavailable in standard reports.
  • Segment prospective customers from current customers more effectively.
  • More accurately attribute value to key conversion channels by improving upon conversion paths.


When a person loads a page on your website, Google Analytics automatically assigns that person a Client ID, which is unique to the specific browser and device and stored in cookies. A single person may be assigned many Client IDs, such as if they visit your website from their mobile phone and then later return on their desktop computer. Each unique Client ID that is sent to Google Analytics is reported as an individual User.

If you have some way of identifying an individual person, whether through a login feature on your website or some customized promotions, you likely already have an internal way to refer to them. We refer to this as a User-ID, which is simply a unique string of characters assigned to one individual so that they can be recognized as a single user. Regardless of the number of devices they use to visit your website or mobile application, as long as they log in or identify themselves as an individual, we can pass that information to GA via the User-ID field. By setting the User-ID, you can create a View that essentially overrides the functionality of the Client ID, in favor of the User-ID in order to tie each of those touchpoints to a single user.

How to Implement

So now that we have a little background, let’s review the steps to actually implement the User-ID override feature for Google Analytics, in Google Tag Manager of course!

Step 1: Identify your visitors with unique User-IDs

You will need to either generate unique IDs for your users or pull them from an existing resource, such as a customer database/CRM or cookie. Consider your options – if your website has user login functionality, that is a great place to start.

For example, many ecommerce websites offer users the ability to create an account where their preferences, personal information and purchase history can be saved. Publisher sites often offer memberships for premium content. Educational institutions have student portals for coursework and tuition-related information.

Each of these is a great example of incentivized self-identification, where users gain some sort of value for logging in. This is the optimal environment for setting up the User-ID – without this type of functionality, configuring the User-ID is going to be much more difficult to do.

There are other opportunities, however, if you want to get even more creative. Campaigns could also be used to define users. For example, if you have an email list (which also contains a unique ID per user on your email list) you could send out an email promotion which contains a dynamically generated link back to your website. That link would contain a unique ID for each subscriber, which would be collected once the user clicks on the link and comes to your website.

For the ambitious, and to really use all of the features that Universal Analytics offers, loyalty cards can be tied to a unique identifier per user – and purchases made with loyalty cards can be sent to Google Analytics via the Measurement Protocol or Data Import.

Step 2: Configure GTM to Collect the User-ID and Assign It To Users.

Your website is ready to go, now let’s send that information to Google Analytics! Start by creating a variable in GTM for the User-ID value so that GTM knows where to look for the IDs.

Best case scenario would be to pass the information programmatically to the data layer, and then grab that inside of GTM with a Data Layer Variable.

Your data layer may look like the following once a user logs in:

data layer variable for User-ID

Another alternative would to be grab the ID out of a cookie that you already have on your site. You can set up a First Party Cookie variable with the name of the cookie you will be getting the IDs from:

cookie for User-ID

User-ID is passed to Google Analytics attached to a hit, like a pageview or event. Most commonly, we’ll just use the general pageview tag that is already firing on every page. Click into your existing Google Analytics tag and choose Configure Tag to edit the existing settings. Under More Settings > Fields to Set, add a new field and name it “userId.” As you start typing in user, GTM will default to the correct spelling for you (which looks a little different than the JS version.) For the value, fill in the variable that you created earlier.

User-ID field to set

According to the Google Developer Guide, there is no maximum length for the User-ID value.

You can also set a custom dimension containing the User-ID if you wish. This will allow you to segment your data in your non-User-ID-specific Views and see a larger picture of your data. Just remember not to pass in a User-ID that may contain personally identifiable information, like a person’s name.

Step 3: Configure the User-ID settings in Google Analytics

After you have your User-ID ready to send to Google, now you need to make sure GA is set up properly. Inside of Google Analytics, you need to read and agree to the User-ID policy and then enable the feature in the Admin settings at the Property level, under Tracking Info > User-ID.

enable User-ID

Note: This may require an update to your privacy policy.


Of course, users need to log in before you can assign them an ID, and not all of your users will log in each and every time they visit your website – so it may take a little time to actually assign a decent amount of User-IDs. It is also important to keep in mind that users who have logged into your website in the past will not automatically have an ID assigned to them.

Often a user will browse your website for a period of time, before they decide to login. It is possible to group these hits set prior to when the User-ID was assigned, but only those collected during the same session during which the ID is assigned for a given user. To do this, you must enable the session unification feature in the Admin settings when you configure the User-ID.

User-ID session unification settings

For more details about session unification, take a look at the Google Analytics Help files.

In addition to that, I also recommend that you check out Simo Ahava’s article about persisting the User-ID in a cookie so that each time users return to your website and do not log in you can still recognize their User-IDs.

Step 4: Configure a User-ID View

You will also need to configure a specific View that will include only hits that were made by users who were assigned a User-ID. In this View, each of your standard reports will be based off the User-IDs rather than the Client IDs. Granted, you will not have as much data in this new View as you do in your standard Views, but you gain a new perspective on individual users and their behavior.

Multi-Channel Funnel reports and Acquisition reports may be more accurate as they reflect upon users rather than cookies, for example. Frequency and recency of returning users may also be more accurate.

In addition, you also receive new reports that are only available in User-ID-specific Views. These reports help paint a more realistic picture of the number of devices used to access your website, which devices purchases are made on most frequently, and more.

The new reports listed below can be found under “Cross Device” within the Audience section of Google Analytics:

cross device User-ID reports

Device Overlap

The Device Overlap report shows which devices users are visiting your website from, including the “overlap” or those who visit your website from a combination of devices.

User-ID device overlap

Beneath that is a break down of the revenue and transaction rate for each combination:

User-ID device overlap

Device Paths

The Device Paths report enables you to see what sequence users are accessing your website from various devices. It also directly ties to revenue and transactions:

User-ID device paths report

You’ll also notice “Path Options” at the top of that report. These options allow you to specify that you want to see the steps that occurred before or after a particular event occurred, such as any goal completion, any transaction, a specific event, pageview, etc. You can also toggle the columns of the report to show data specific to goals or ecommerce by changing your selection from the top of the report.

User-ID device paths options

Acquisition Devices

This report shows which devices users originally used to access your website (from the time that the User-ID was set for them). You can see revenue from each device in comparison to revenue from each originating device:

User-ID acquisition device report

Now that User-ID is set up, you’ll hopefully be able to unlock insights by tying various devices and sessions to individual users.

Amanda Schroeder is a Senior Consultant and comes from the marketing industry where she found a need for accurate, insightful data that could aid in making results-driven decisions. Amanda’s passion for building solid measurement strategies and connecting all the pieces of integrated digital and traditional marketing campaigns has led her to her current role at LunaMetrics.

  • Antti Nylund

    Great article about user id and its use cases. Simo Ahava link goes to 404 fyi 🙂

    • lunametrics

      All fixed – thank you!

  • David

    Is there a way to also subdivide users on mobile web vs. mobile native app?

    We’d like to implement this, but to understand which users are also on a native app would be great – it seems to be browser-only?

    • Amanda Schroeder

      Hi David,

      You are correct, the reports do not show mobile app traffic in comparison to mobile web, desktop and tablet traffic. You could set a custom dimension for the app platform (iOS App or Android App, for example) – which you could then segment your users with.

    • Amanda

      Hi David,

      You are correct, the reports do not show mobile app traffic in comparison to mobile web, desktop and tablet traffic. You could set a custom dimension for the app platform (iOS App or Android App, for example) – which you could then segment your users with.

  • James Porter

    Great article. Probably the clearest thing I’ve ever read on how to implement user-id. Thanks

    • Amanda

      Glad to hear it!

  • Outstanding article. Thank you!

  • Great article Amanda, I was wondering how to generate or pick up the userID for an email tracking signature pixel

  • Great!! I have following your introduction But I have some issue for coockie. Can you please help me for setup coockie with custom java script var..? I have tries with following script But still not working my coockie
    if ({{customer in_datalayer}}) {
    var cookieName = “userId”;
    var cookieValue = “{{customer_in_datalayer}}”; //
    var expirationTime = 5256000;
    var expirationTime = expirationTime * 1000;
    var date = new Date();
    var dateTimeNow = date.getTime();
    var expires = ‘expires=’+d.toGMTString();
    date.setTime(dateTimeNow + expirationTime);
    var expirationTime = date.toUTCString();
    document.cookie = cookieName+” =”+cookieValue+”; expires=”+expirationTime+”; path=”+cookiePath; //Set cookie
    return {{customer_in_datalayer}};
    } else if ({{customer_in_cookie}}) {
    return {{customer_in_cookie}};

    • Amanda

      Hi there, I see a couple problems with the code you have.

      You are missing a cookiePath variable – that must be set before you can reference it when you create the cookie with document.cookie = …

      Also, you will want to get rid of the quotes you have around the value in this line:

      var cookieValue = “{{customer_in_datalayer}}”;

      so it instead looks like this:

      var cookieValue = {{customer_in_datalayer}};

      And then you’ll want to change “d” to “date” in this line:

      var expires = ‘expires=’+date.toGMTString();

      Hope that helps! We also have a cookie handler recipe for GTM that you are welcome to try out – it is much cleaner:


  • Imanuel Abraham (mrsarajar)

    I was able to setup the userid on GTM using Javascript Variable. Seems simpler than DataLayer

    • Tejin

      Hi Imanuel, I am trying to achive the same. Can you please share the code or how did you implement it. I tried all the steps mentioned but somehow the result is not what I expected. I would prefer to setup on GTM using javascript as well.Please help. Thanks

  • In many of the times I had seen the option called user-id in Google analytics but I never used it. I just came here to know about the whole setup process of user-id and I must say you have explained it in a great way Amanda. Now I am going to apply it on my own analytics account soon, thank you.

  • I was familiar with user id I know from this place its really resource you have shared. I am really grateful to you Amanda.
    Surely I will use this to my analytics account.

  • Abhilash St

    Do we have to include this code in every page that we want to track ?

    ga(‘set’, ‘userId’, {{USER_ID}});

    Please help. Thanks

    • Amanda

      Yes, every page where the user can be identified (i.e. logged-in pages).

  • Great post Amanda, thanks.

    Are transaction IDs also a way to assign a User-ID to a customer? If so, what would the customer need to do when he/she comes back to the site/app so GA assigns the generated sessions to the ID? Do they need to login?


  • Excellent writing. This is really wonderful tips for us.

  • Audrey Chou

    Thank you for this article, Amanda! One issue we’re running into is that the user number in User-ID view is at least 30% higher than the number I pulled directly from the database. Since the User-ID view eliminate the factor of different device and browser usage–I assume the numbers should be somewhat close to the numbers in the database. I can’t figure out what’s causing the issue. Could you help?

Contact Us.

Follow Us



We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203


4115 N. Ravenswood
Suite 101
Chicago, IL 60613


2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187