Track user ID

The Universal 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.

Tag configuration

To set up Google Tag Manager to track the User ID, follow these steps:

  1. First, create a Tag Manager variable called userId​. Your variable can retrieve the user ID value from either a first party cookie or the data layer.
    • If you're using a 1st party cookie to persist a user ID on the client side, 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.
  2. In your Universal Analytics tag, open More settings and then Fields to Set.
  3. Click Add Field. Enter these values for the new field:
    Field Name Value
    userId {{userId}}
  4. Save the tag and publish the changes.

Remove the User ID

The Google Analytics User ID policy requires that you stop tracking user ID once a user signs out of your website.

If the user ID is persisted in a cookie, Google Tag Manager can read the user ID value from the cookie, you should delete the cookie whenever a user signs out. This will clear the signed-in state from a given cookie.

Once the cookie is deleted, Google Tag Manager will not send the user ID to Google Analytics. Should the user sign back in and re-establish a cookie , Google Tag Manager will resume sending the user ID to Google Analytics.

Was this article helpful?
How can we improve it?