Identify individual users for session analysis

One of the key features of Dynatrace Real User Monitoring is the ability to uniquely identify individual users across different browsers, devices, and user sessions. With user tags, you can analyze specific user behavior and the experiences of individual users via user session analysis. By default, Dynatrace assigns a unique, random ID to each new user. You can however assign more meaningful custom user tags that are comprised of, for example, user names or email addresses. You can set up custom user tagging via either the Dynatrace JavaScript API or page metadata.

User tagging via RUM JavaScript API

User tagging can be orchestrated via the Dynatrace JavaScript API for Real User Monitoring. Samples and documentation can be downloaded from the Dynatrace UI:

  1. In the Dynatrace menu, go to Settings > Web and mobile monitoring > Advanced setup.
  2. Select Download documentation and samples. A sample HTML file called identifyUser.html with a correctly formatted JavaScript snippet can be found in the samples\sessions directory.

User tagging based on page source

This approach to user tagging works by capturing available data in your application’s page source. If you take a close look at your application’s page source, you’ll likely find that usernames are already included somewhere. Usernames may be included in the text of a DOM element or a JavaScript variable (find a full list here).

For example, easyTravel, the Dynatrace demo application, includes the user name in a welcome message in the upper-right corner of the home page (see image below). Using the development tools that are built into most browsers, you can generate a unique CSS selector for this particular element.

Once you’ve identified where usernames are located in your page source, you can create user tags based on the usernames:

  1. In the Dynatrace menu, go to Frontend.
  2. Select the application you want to configure.
  3. Select Browse () > Edit.
  4. Select Capturing, and then select User tags.
  5. Select Add tag (identifier) rule.
  6. From the Expression type to capture drop list, select CSS selector. In this example, the user's identifier is extracted from the page source using the CSS selector. See Available page data sources to learn about other data sources.
  7. Type the CSS selector value into the CSS selector field.
  8. optional To ensure that there is a clean extraction of the username value, you can apply a regex cleanup rule by enabling the Enable cleanup rule switch and then typing a regular expression in the Regex field.
  9. Select Add tag (identifier) rule, and then select Save.

Note: You can add a maximum of 20 user tag (identifier) rules per application.

To verify that your user tag configuration has been applied correctly, after saving the configuration and reloading the page, take a look at the injected JavaScript in your application’s updated page source. As you can see in the example below, a property called md= is now listed in this page’s metadata expressions.

Once you’ve completed this process, go to Session segmentation in the Dynatrace menu. Click in the filter text box at the top of the page. Choose the User tag attribute, and select a user tag from the list. The chart now shows detailed session data related to the sessions of this specific user. You can click the name of the user that appears under the chart to navigate to this user’s overview page and view further details.

Available page data sources

The Source type list provides you with the following data sources from which you can extract the user's identifier:

  • CSS selector: use when the user's identifier is visible on your page. This mechanism will capture the first match's innerText/textContent value (available for browsers that support querySelector). To retrieve a specific attribute value of the element, append the '@' symbol, followed by the attribute name (i.e., '#someDomElement@someAttribute').
  • JavaScript variable: use when, for example, you are already sending your user's identifier via a tag manager to other tools. You can then reuse your data layer object. This variable must be available globally. Use dot notation for property reference with JavaScript variables ('someVar.version'). Refer to your tag manager documentation for details.
  • Meta tag: use when your user's identifier is present in one of the meta tags in the source of your page. This specifies the meta tag name that Dynatrace will use to capture its 'content' value.
  • Cookie value use when your user's identifier is present in one of your existing cookies.
  • Query string: use when your user's identifier is part of a certain query string parameter, which you can define here.
  • Server side request attribute: use when you want to use a server-side request attributes to tag each user session. Once you've defined a request attribute, all you need to do is to use it at step 6. Note that the service request attribute may not be captured for every user action/user session, as your server-side PurePath may be not captured due to adaptive capture control.

What if user tracking isn’t allowed at my company?

If your organization doesn’t allow tracking of individual users for privacy reasons, you can alternatively define user tags that correspond to team names or department names. In this way, you can monitor the experience of individual users while not disclosing any identifying information.

Additional notes and limits

  • All captured values are cropped to a maximum length of 100 characters.
  • If you use the JavaScript API to identify your users, the API may override any existing metadata rules that have been configured. So, if you define user tags through the JavaScript API, these user tags will override any other metadata-based tags that may exist.
  • All configured user tags are captured on every page. The RUM JavaScript is used to evaluate each monitored user action against each user-tag rule that you create, so keep your list of user-tag rules to a minimum to reduce overhead.
  • The last user action in a session that contains a tag will be used as the tag for the entire session.
  • You can also identify mobile users of native mobile apps.