Set up a UserID

The necessary tools: Analytics + Tag Manager

The UserID feature is one of the mechanisms used to recognize visitors on your website. It can be applied when your website or app has a mechanism to strictly recognize the visitor. In other words, you can capture a trustworthy ID, for example, an email, user name or other ID.

After setting up the UserID feature, the UserID is used as a single source of truth.

Before you start

Here are some things to know about UserID before you begin working with it:

  • With UserID 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.
  • When the visitor logs out and the UserID value is no longer available, he or she will be tracked as a new visitor and Piwik PRO will use the cookie as a source of information.

Set up a UserID

You can set up the UserID in our Tag Manager. You only need to create a variable that will be catching the userID value. The value can be anything you like but it’s important for it to be unique. In the example below, the value will be an email address of a logged-in user.

First of all, you need to verify if the email address is provided anywhere on your page for you to grab.

When you find it, just right-click it and inspect it to reveal the code.

Our code has an id parameter so it can easily be grabbed by Tag Manager

Now all you need to do is setup your tracking code so it will be passing the variable to Piwik PRO.

That’s it – you are now tracking UserID in the Piwik PRO.

Set up a UserID manually

If for some reason you are unable to use automatic setup within Piwik PRO Tag Manager, you’ll need to add UserID method to your Piwik JavaScript tracking code manually.

All you need to add is following line:

_paq.push(['setUserId', 'USER_ID_HERE']);

Just before the _paq.push(['trackPageView']); line in your standard JavaScript tracking code.

Of course, you will need to pass the correct value in the USER_ID_HERE place.

Was this article helpful?

of people found this helpful

Technical Support

If you have any questions, drop us a line at support_SPC@piwik_SPC.pro.

We’re happy to help!