History & Introduction
One of the most common misconceptions in web analytics is that a user actually represents an individual who has visited your site on one or more occasions.
Traditionally a user who visits your site on multiple devices (e.g. mobile, desktop) would in fact be classed as multiple users.
Slightly cheesed off analyst: "
OK, so we can safely assume that users in web analytics are actually defined by the number of devices that are used to access a site, right?"
If an individual on a single device visits your site in more than one browser or removes their cookies, their user ID will be reset and their sessions will be attributed to multiple users.
Because browser cookies are the only way we can truly brand users to recognise them on subsequent visits, this couldn't be helped. Universal Analytics' cross-device capabilities get us a lot closer to tackling this dilemma by assigning user IDs to users whenever they log in.
So how does it work? Aside from cookies, another more reliable way to identify users is when they have logged in to your site using a username and password. Once a user log in is created, there will usually be a unique ID that is bound to the username to help identify them (the ID may even be the username itself).
When this user logs in in future, their ID will be used by the site to retrieve their information and preferences from the back end. By also sending this user ID off inside hits to Google Analytics, wherever the user logs in from then on (i.e. from their phone, tablet or desktop), this will be regarded as the same user in GA.
Enabling User ID in GA
Before you can start to use the
cross-device reports in GA and session unification, you must enable it in Google Analytics. There are two parts to this, turning user IDs on in your web-property then creating a user ID enabled view inside that property.
To enable it, go to the
Admin tab at the top of the page. Select a Universal Analytics property from the web-properties dropdown (middle of the screen) then select Tracking Info > User-ID:
Follow the three simple steps agreeing to the user-ID policy, enabling/disabling session unification (more on this later) and finally create a new user-ID-enabled View at the third and final step.
Once the web-property is user ID enabled you will get the option to turn it on for any future Views you create under that property. Unfortunately it's not possible to enable it for an existing standard View nor disable it for a user-ID-enabled View.
This is decided on View creation and cannot be altered in future.
Phew, now that's sorted we can get on to the more interesting stuff!
Setting User IDs For Your Tags
Typically for each user login, there is some kind of user ID associated with it. By making this available on the page that the user is directed to after logging in (cue developers), this ID can be fired off as a parameter when the tracker is created for that page. Here is an example that would be found on the 'welcome' page after logging in where the visitor's user ID is set as the tracker is created:
The second method is to set the user ID using the "set" method. This is
recommended as the best practice solution because it sets the user ID for all subsequent hits that occur on the page including any events that are triggered in-page later on:
NOTE: The set method must be inserted after the tracker is created and before any hits are fired.
Setting User IDs in GTM
Don't hard code tags on your site? You can also set user IDs using GTM.
Simply go to your main universal analytics page view tags, expand
fields to set and add a new field. Put &uid as the name for your field and set the value of this using a macro.
I'd recommend using a
dataLayer macro as the value. This way you can implement a small piece of code on your webpage that pushes the value of the user's unique ID to the dataLayer ready for GTM to pick up like so:
Make sure the user ID data layer push goes on your page before your GTM container (in the <head>) and after the dataLayer is defined.
That's it! Once you've published your container in GTM it will start setting user IDs for signed in visitors to track their behaviour across multiple browsers and devices.
Headaches & Session Unification
As mentioned previously, the user ID must be set for every hit where the user is logged in on your site and a user ID is available. Any hits not including a user ID will be attributed to a separate user.
Fortunately this can be easily dealt with by ensuring the "set" method with user ID (see section on setting user IDs for your tags) is included on all of your pages.
Unfortunately this is also the case when a user begins a session with their user ID set on every logged in hit then signs out before the end of their session; the user ID is unavailable, not set, and any subsequent hits are lost to a completely different user.
Oh no! It was all going so well! Let's end this section on a good note…
Although subsequent user-ID-less hits won't be attributed to the original user, there is a neat way to ensure hits with no ID prior to log in are linked to the user who eventually logs in during that session.
In other words, by enabling
session unification in Admin > Tracking Info > User-ID, any hits sent before log in will be attributed to the user ID eventually assigned:
Offline Tracking – The Whole Package!
This doesn't have to stop at tracking users across devices. User IDs can also be set
offline, for example when users scan a loyalty card in your store during a purchase, you can introduce Google's Measurement Protocol which would fire off an ecommerce transaction to GA.
Let's assume your customer's on site user logins and loyalty cards share the same unique ID. By setting a user ID when the loyalty card is scanned in store, the ecommerce hit that's sent will be attributed to that customer's ID. Then when they later shop online, the same ID will be picked up from their username allowing you to stitch the two scenarios together for a single user.
Pretty awesome stuff!