The setUserId() method sets the user ID for a specific user. It can be the same identifier as in your CMS, CRM or sales system. The user ID helps to recognize the user across devices.

Syntax

await PiwikProSdk.setUserId("userId");

Parameters

userId (string, required)

A non-empty, unique identifier of the user. Example: customer ID. It needs to be unique for each user. Can be up to 1024 bytes (1024 ASCII characters).

Examples

To set a user ID as ABC123 and send it with a screen view:

await PiwikProSdk.setUserId("ABC123");

Notes

  • The user ID won’t be sent if setAnonymizationState(true) is set.
  • For more on the user ID, see this article.