---
title: Tracking User Actions
description: >-
  Automatically track user interactions and custom actions in web applications
  to understand user behavior, performance, and feature adoption.
breadcrumbs: >-
  Docs > RUM & Session Replay > Application Monitoring > RUM Browser Monitoring
  > Tracking User Actions
---

# Tracking User Actions

## Overview{% #overview %}

Browser Monitoring automatically detects user interactions performed during a user journey and provides insights into your users' behavior without requiring you to manually instrument every single click in your application.

You can accomplish the following objectives:

- Understand the performance of key interactions (for example, a click on the **Add to cart** button)
- Quantify feature adoption
- Identify the steps that led to a specific browser error

While there is no explicit cap on the total number of actions that can be collected by the RUM Browser SDK during a session, there are technical limitations on individual event sizes and the payload sent. For further details about limitations on actions, see [RUM Browser Troubleshooting documentation](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/troubleshooting/).

## Manage information being collected{% #manage-information-being-collected %}

The `trackUserInteractions` initialization parameter enables the collection of user clicks in your application, which means sensitive and private data contained in your pages may be included to identify elements that a user interacted with.

To control which information is sent to Datadog, you can [mask action names with privacy options](https://docs.datadoghq.com/data_security/real_user_monitoring/#mask-action-names), manually set an action name, or [implement a global scrubbing rule in the Datadog Browser SDK for RUM](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/advanced_configuration/).

### Mask all action names{% #mask-all-action-names %}

To mask all action names by default, use the `enablePrivacyForActionName` initialization parameter:

```javascript
window.DD_RUM.init({
    ...
    trackUserInteractions: true,
    enablePrivacyForActionName: true,
});
```

When enabled, all action names are replaced with `Masked Element`. Action names explicitly set with the `data-dd-action-name` attribute are still displayed, allowing you to selectively expose specific action names while keeping others masked.

## Track user interactions{% #track-user-interactions %}

The RUM Browser SDK automatically tracks clicks to generate click actions. A one-click action generally represents one user click, except when the same element is clicked multiple times in a row, which is considered a single action (see [Frustration Signals "rage clicks"](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/frustration_signals/)).

## Action timing telemetry{% #action-timing-telemetry %}

For information about the default attributes for all RUM event types, see [RUM Browser Data Collected](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/data_collected/#default-attributes).

| Telemetry                | Type        | Description                                        |
| ------------------------ | ----------- | -------------------------------------------------- |
| `action.loading_time`    | number (ns) | The loading time of the action.                    |
| `action.long_task.count` | number      | Count of all long tasks collected for this action. |
| `action.resource.count`  | number      | Count of all resources collected for this action.  |
| `action.error.count`     | number      | Count of all errors collected for this action.     |

The Datadog Browser SDK for RUM calculates action loading time by monitoring page activity following every click. An action is considered complete when the page has no more activity. See [How page activity is calculated](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/monitoring_page_performance/#how-page-activity-is-calculated) for details.

For more information about configuring for sampling or global context, see [Modifying RUM Data and Context](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/advanced_configuration/).

## Action attributes{% #action-attributes %}

| Attribute            | Type   | Description                                                                                                                     |
| -------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------- |
| `action.id`          | string | UUID of the user action.                                                                                                        |
| `action.type`        | string | Type of the user action. For custom user actions, it is set to `custom`.                                                        |
| `action.target.name` | string | Element that the user interacted with. Only for automatically collected actions.                                                |
| `action.name`        | string | User-friendly name created (for example, `Click on #checkout`). For custom user actions, the action name given in the API call. |

## Declare a name for click actions{% #declare-a-name-for-click-actions %}

The Datadog Browser SDK for RUM uses various strategies to get a name for click actions. If you want more control, you can define a `data-dd-action-name` attribute on clickable elements (or any of their parents) that is used to name the action.

For example:

```html
<a class="btn btn-default" href="#" role="button" data-dd-action-name="Login button">Try it out!</a>

<div class="alert alert-warning" role="alert" data-dd-action-name="Dismiss alert">
    <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
    <span class="visually-hidden">Error:</span>
    Enter a valid email address
</div>
```

Starting with [version 2.16.0](https://github.com/DataDog/browser-sdk/blob/main/CHANGELOG.md#v2160), with the `actionNameAttribute` initialization parameter, you can specify a custom attribute that is used to name the action.

For example:

```html
<script>
  window.DD_RUM.init({
    ...
    trackUserInteractions: true,
    actionNameAttribute: 'data-custom-name',
  ...
  })
</script>

<a class="btn btn-default" href="#" role="button" data-custom-name="Login button">Try it out!</a>
```

`data-dd-action-name` is favored when both attributes are present on an element.

### How action names are computed{% #how-action-names-are-computed %}

The Datadog Browser SDK uses the following strategies to compute click action names:

1. If the `data-dd-action-name` attribute or a custom attribute (as explained above) is explicitly set by the user on the clicked element (or one of its parents), its value is used as the action name.

1. If no explicit action name attribute is set and `enablePrivacyForActionName` is enabled, the action name is set to `Masked Element`.

1. Otherwise, depending on the element type, the SDK uses other attributes such as `label`, `placeholder`, or `aria-label` from the element or its parents to construct the action name. If none of these attributes is found, the SDK uses the inner text as the action name.

## Send custom actions{% #send-custom-actions %}

To extend the collection of user interactions, send your custom actions using the `addAction` API. These custom actions send information relative to an event that occurs during a user journey.

For more information, see [Send Custom Actions](https://docs.datadoghq.com/real_user_monitoring/guide/send-rum-custom-actions).

## Action limits and sampling{% #action-limits-and-sampling %}

There is no strict limit on the number of user actions, such as clicks or custom actions, that the Datadog RUM Browser SDK can track per session or page. However, you should consider the following:

- **Sampling** - You can configure the SDK to sample a percentage of user actions using the `sampleRate` and `trackInteractions` options. This helps control the volume of data sent to Datadog. For more information, see [Advanced Configuration](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/browser/troubleshooting/).
- **Performance** - The SDK batches and sends events periodically. In cases of high-frequency actions, such as repeated clicks, the SDK may deduplicate or group actions, for example, through rage click detection to avoid flooding.

As a best practice, if you expect a high volume of user actions, consider adjusting your sampling configuration and monitor your Datadog event usage.

## Further Reading{% #further-reading %}

- [Introducing Datadog Real User Monitoring](https://www.datadoghq.com/blog/real-user-monitoring-with-datadog/)
- [Explore your views within Datadog](https://docs.datadoghq.com/real_user_monitoring/explorer/)
- [Apply visualizations on your events](https://docs.datadoghq.com/real_user_monitoring/explorer/visualize/)
- [Learn about RUM dashboards](https://docs.datadoghq.com/real_user_monitoring/platform/dashboards/)
