Tracking User ID

In your Universal Analytics tag, open the More settings → Fields to Set option and click Add Field. Enter these values for your new field:

Field Name         Value
userId {{userId}}

This setting assumes you've already created 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 variable of type 1st Party Cookie, 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 variable of type Data Layer Variable and enter the variable name in the Data Layer Variable Name field.

Unsetting the User ID

The Google Analytics User ID policy requires that you stop tracking user ID once a user signs out of your website. So, you'll need to unset the user ID if the user signs out.

If the user ID is being persisted in a cookie, and Google Tag Manager reads the user ID value from the cookie, you simply need to delete the cookie whenever a user signs out. This is a typical practice anyway, since you usually want to clear the signed-in state from cookies once a user signs out.

Once the cookie has been deleted, Google Tag Manager won't find it and will stop sending the user ID to Google Analytics. Once the cookie is present again (i.e. the user signs back in), Google Tag Manager will resume sending the user ID to Google Analytics.

Was this article helpful?
How can we improve it?