Notification

G Suite is now Google Workspace: everything your business needs to get work done.

Google Analytics 4

The Google Analytics user ID

The Google Analytics User ID is used to associate multiple user sessions and activities with a unique ID. With it, you can get a more accurate user count, analyze the signed-in user experience, and understand user behavior across devices.

Configuring Google Analytics tags to capture the User ID involves two steps:

Step 1: Create a User ID variable in Tag Manager

  1. Create a Tag Manager variable called user_id. Your variable can retrieve the user ID value from either a first party cookie or from the data layer:
    • If you're using a 1st party cookie to store a user ID on the client web browser, you can use the 1st party cookie variable to read the user ID value from the cookie. Create a new 1st Party Cookie variable, and enter the name of your cookie in the Cookie Name field.
    • If the user ID is available on the page itself, you can create a data layer variable. Create a new Data Layer variable and enter the variable name in the Data Layer Variable Name field.

Step 2: Add the user ID field to your Google Analytics tag

The steps for adding the user ID field to your tag vary depending on whether you are using Universal Analytics or GA4.

Add the user ID field to your GA4 tag

For user ID based features to function correctly in GA4, the user_id field must be attached to every event. Setting the user ID field in the Configuration Tag automatically attaches it to all events. For this reason, it is recommended to add the user ID field to the Configuration Tag rather than adding it individually to each event tag.

To add the user ID field to a GA4 Configuration Tag:

  1. In the Configuration Tag settings, select Fields to Set.
  2. Click Add Row. Enter these values for the new field:
    Field Name Value
    user_id {{user_id}}
  3. Save the tag and publish the changes.

To add the user ID field to a GA4 event tag:

  1. In the event tag settings, select Event Parameters.
  2. Click Add Row. Enter these values for the new field:
    Field Name Value
    user_id {{user_id}}
  3. Save the tag and publish the changes.

Removing the user ID for signed-out user activity

The Google Analytics User ID policy requires that you stop any measurement based on user ID once a user signs out of your website. When using tags to track events that the user completes after signing out of your website, you must disable the user ID field so that the user ID is not recorded for that activity.

If the user ID is stored in a cookie, tags can read the user ID value from the cookie even after the user has signed out. Also, if the user ID is set in the Configuration Tag and the user signs out but does not navigate away from the page, their user ID will remain stored in the data layer even after the cookie is deleted.

To stop recording the user ID after a user signs out:

  1. Delete the user ID cookie.
  2. If the user_id field is set in a Configuration Tag, fire a new Configuration Tag with no user ID set to clear the value from the data layer.

Note that a user ID value of “null” is interpreted as “not set.” All other values including false and 0, are treated as valid user IDs. For example, if you assign a user ID of 0 to users who are not signed into your site, their activity will be attributed to the user ID 0 in Analytics. 

If the user signs back into your site, a new cookie can be set and your tags will resume sending the user ID to Google Analytics.

Was this helpful?

How can we improve it?
Search
Clear search
Close search
Main menu
15672030647917630344
true
Search Help Center
true
true
true
true
true
102259
false
false