Send user IDs

Stay organized with collections Save and categorize content based on your preferences.

The User-ID feature lets you associate your own identifiers with individual users so you can connect their behavior across different sessions and on various devices and platforms.

This article describes how to send user IDs from your website once you've generated the user IDs. 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 instead.


Before you begin

This guide assumes that you've done the following:

It also assumes that you have the following:

  • Access to the Tag Manager container for the website
  • The Editor (or above) role to the Google Analytics account

Send user IDs

Step 1: Update your data layer

Before you send user IDs to Analytics, create a Google Analytics 4 Configuration tag and add the generated user ID to your data layer as follows:

dataLayer.push({
  'user_id': 'USER_ID'
});

Step 2: Create a data layer variable

  1. In Google Tag Manager, click Variables.
  2. In the User-Defined Variables section, click New.
  3. Click Variable Configuration > Data Layer Variable.
  4. Enter a name for the variable at the top.
  5. In the Data Layer Variable Name field, enter a name for your user ID variable (such as "user_id").
  6. Click Save.

Step 3: Modify your Configuration tag

Finally, modify the Configuration tag so all events associated with the tag use the Data Layer variable:

  1. In Tag Manager, click An image of the Tags icon Tags.
  2. Select your Google Analytics 4 Configuration tag.
  3. In the Tag Configuration section, click Fields to Set.
  4. Click Add Row.
  5. In the Field Name field, enter "user_id" so Analytics recognizes the user ID.
  6. In the Value field, select the Data Layer variable you created.
  7. Click Save.
  8. Click Submit to publish the changes.