User IDs are your own unique identifiers that you assign to individual users. This guide explains how to send user IDs to Google Analytics, so you can connect user behavior across different sessions, devices, and platforms.
To learn more about the User-ID feature, see Measure activity across platforms. To learn how to set a user ID for an app, see Set a user ID.
Setting custom dimensions based on user IDs leads to dimensions with too many unique values. Having too many unique values causes issues with Google Analytics data and reporting accuracy. Learn more about best practices for setting custom dimensions.
Before you begin
Before you can send user IDs, make sure you've completed the following:
- Create a Google Analytics account and property.
- Create a web data stream for your website.
- Place the Tag Manager snippets on your website.
- Install the Google tag in Tag Manager.
- Have access to the Tag Manager container for the website.
- Have the Editor role (or above) to the Google Analytics account.
Send user IDs
The value you send for user_id
depends on the state of
the user:
- User has never signed in: Don't send the
user_id
parameter. - User is signed-in: Send their user ID.
- User was signed-in, then signed out: Send
null
.
Step 1: Update your data layer
Before you send user IDs to Analytics, make the user_id
available in your
data layer on your website.
if (/* your logic for determining if the user is signed in */) { dataLayer.push({ 'user_id': 'USER_ID' }); } else if (/* your logic for determining if the user signed out */) { dataLayer.push({ 'user_id': null }); } else { // Do nothing if the user never signed in. }
- Replace the comments with your checks for if the user is signed-in, and if the user was signed-in but then signed out.
- If a user is signed-in, replace USER_ID with their user ID.
- When a user signs out, set
user_id
tonull
. Don't send an empty string (""
), a blank string (" "
), or the quoted words"null"
or"NULL"
.
Step 2: Create a data layer variable
In Google Tag
Manager, click Variables.
In the User-Defined Variables section, click New.
Click Variable Configuration > Data Layer Variable.
Enter a name for the variable at the top.
In the Data Layer Variable Name field, enter a name for your user ID variable (such as "user_id").
Click Save.
Step 3: Modify your Google tag
Finally, modify the Configuration tag so all events associated with the tag use the Data Layer variable:
- In Tag Manager, click
Tags.
- Select your Google tag.
- Under Configuration settings section, add a new row with the following
parameters:
- Parameter:
user_id
- Value: Select the Data Layer variable you created.
- Parameter:
- Click Save.
- Click Submit to publish the changes.