Set up a user ID
Necessary tools: Analytics + Tag Manager
A user ID is a piece of additional information about the visitor that can be collected on your website. It can be a visitor’s email, username or another identifier.
The user ID is stored along with a visitor ID held in a cookie in the visitor’s browser. You can use it to create a segment and see all sessions of one visitor. In some cases, it is also used to recognize a returning visitor.
Before you start
Here are some things to know about the user ID before you begin working with it:
- With the user ID you can recognize a visitor across many devices. For example, when a visitor is logged in and switches between a laptop, mobile, and tablet, he or she will be seen as the same visitor. The visitor ID will be different for this person, but the user ID will be the same.
- The user ID helps to attribute sessions to the visitor and is treated as a last resort identification mechanism, for example when the visitor has disabled cookies.
Set up a user ID
In this example, we’ll show you how to add a user ID when a visitor is logged in with an an email, and the email is available on all pages.
To set up a user ID, follow these steps:
- Find an ID on the page. For example, we’ll find a visitor’s email address.
- Inspect an element to see the code. In our case, the code is:
- The code has an id element email so we’ll use it to set a variable in Tag Manager. A variable will grab information about an id from the website, and it’ll pass it to the user ID feature.
- Log in to Piwik PRO.
- Go to Menu > Tag Manager.
- Navigate to Variables.
- Click Create new variable.
- Name the variable.
- Select a variable type. In our example, it’ll be DOM element.
- Set additional elements. In our case, we’ll set an element ID to
- Click Save.
- Navigate to Tags.
- Pick Piwik PRO tag from the left-hand list.
- Toggle Set user ID.
- Type in a variable that you set in previous steps. In our case, the variable is
- When your’re done, click Save for the tag.
- Test your tag in debug mode
- When you’re happy how the tag works, click Publish.
Set up a user ID manually
If for some reason you are unable to use automatic setup in Tag Manager, you’ll need to add user ID feature manually to the tracking code.
To add a user ID manually, follow these steps:
- In your tracking code, find
- Add the following code right before
USER_ID_HERE with a correct value.