How do I tag 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. This enables you to analyze the user experience of individual users via user session analysis. With user tags, you can track specific user behavior throughout your application environment, across sessions, devices, and browsers.

By default, Dynatrace assigns a unique, random ID to each new user. You can however assign more meaningful 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 the Dynatrace 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. Go to Settings > Web and mobile monitoring > Custom user actions.
  2. Click 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 metadata

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, a meta tag, a JavaScript variable, or even a cookie attribute. 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. From the navigation menu, click Applications.
  2. Select the application you want to configure.
  3. Click the Browse () button and select Edit.
  4. Click the User tags tab.
  5. Click Add user tag rule.
  6. From the Expression type to capture drop list, select CSS selector.
  7. Type the CSS selector value into the CSS selector field.
  8. To ensure that there is a clean extraction of the username value, you can apply a regex cleanup rule.

In the example below, the text of the DOM element is Hello <username>!.

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 tag 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, select User sessions from the navigation 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]({% link_to_id single-user-sessions%}) and view further details.

Note: Due to the 30-minute user session timeout, it takes about 30 minutes before you can filter on tags. Only completed user sessions are available on the user sessions page.

Additional notes

  • 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. JavaScript code 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.