---
title: Generate Custom Metrics From RUM Events
description: Create custom metrics from your RUM events.
breadcrumbs: >-
  Docs > RUM & Session Replay > Platform > Generate Custom Metrics From RUM
  Events
---

# Generate Custom Metrics From RUM Events

## Overview{% #overview %}

Real User Monitoring (RUM) allows you to capture events that occur in your browser and mobile applications using the Datadog RUM SDKs and collect data from events at a [sample rate](https://docs.datadoghq.com/real_user_monitoring/guide/sampling-browser-plans). Datadog retains this event data in the [RUM Explorer](https://app.datadoghq.com/rum/explorer), where you can create search queries and visualizations.

RUM-based custom metrics are a cost-efficient option to summarize the data from your set of RUM events. You can visualize trends and anomalies across your RUM data at a granular level for up to 15 months.

**Note:** Custom metrics are computed based on 100% of the ingested RUM traffic, not only the data retained in the RUM Explorer. This ensures accurate metrics even when using [RUM without Limits](https://docs.datadoghq.com/real_user_monitoring/rum_without_limits/) retention filters that may retain only a subset of your sessions.

**Billing Note:** Metrics created from RUM events are billed as [Custom Metrics](https://docs.datadoghq.com/metrics/custom_metrics/).

## Create a RUM-based custom metric{% #create-a-rum-based-custom-metric %}

To create a custom metric from RUM event data, navigate to [**Digital Experience** > **Application Management** > **Generate Metrics**](https://app.datadoghq.com/rum/generate-metrics) and click **+ New Metric**.

{% image
   source="https://datadog-docs.imgix.net/images/real_user_monitoring/generate_metrics/new_metrics_button-2.bdb931e2a6712b8ee5a336f3205ecc86.png?auto=format"
   alt="Click + New Metric to create a RUM-based custom metric" /%}

To create a custom metric from a search query in the [RUM Explorer](https://docs.datadoghq.com/real_user_monitoring/explorer/), click the **Export** button and select **Generate new metric** from the dropdown menu.

{% image
   source="https://datadog-docs.imgix.net/images/real_user_monitoring/generate_metrics/generate_metric_example.6fefd6989acf01b8ecf7b943fa0101bd.png?auto=format"
   alt="Generate a RUM-based custom metric" /%}

1. Give your [custom metric](https://docs.datadoghq.com/metrics/custom_metrics/) a name that does not start with `datadog.estimated_usage`, such as `rum.sessions.count_by_geography`. For more information, see the [naming convention](https://docs.datadoghq.com/metrics/custom_metrics/#naming-custom-metrics).

1. Select an event type you want to create a custom metric for, such as `Sessions`. Your options include **Sessions**, **Views**, **Actions**, **Errors**, **Resources**, and **Long Tasks**. For more information, see [Search RUM Events](https://docs.datadoghq.com/real_user_monitoring/explorer/search/#event-types).

1. Create a search query that filters your RUM events using the RUM Explorer's [search syntax](https://docs.datadoghq.com/real_user_monitoring/explorer/search_syntax/) such as `@session.type:user`.

1. Choose a field to track from the dropdown menu next to **Count**.

   - Select `*` to generate a count of all RUM events that match your search query.
   - Optionally, enter an event attribute such as `@action.target` to aggregate a numeric value and create a corresponding `count` or `distribution` metric.

If the RUM attribute facet is a measure, the metric value is the RUM attribute value.

1. Select a path to group by from the dropdown menu next to **group by**. The metric tag name is the original attribute or tag name without the `@`. By default, custom metrics generated from RUM events do not contain tags unless they are explicitly added. You can use an attribute or tag dimension that exists in your RUM events such as `@error.source` or `env` to create metric tags.
Important alert (level: danger): RUM-based custom metrics are considered as [custom metrics](https://docs.datadoghq.com/metrics/custom_metrics/) and billed accordingly. Avoid grouping by unbounded or extremely high cardinality attributes such as timestamps, user IDs, request IDs, and session IDs.
1. For custom metrics created on sessions and views, select **The active session/view starts matching the query** or **The session/view becomes inactive or is completed** to set the matching criteria for sessions and views. For more information, see Add a RUM-based metric on sessions and views.

1. Add percentile aggregations for distribution metrics. You can opt-in for advanced query functionality and use globally accurate percentiles (such as P50, P75, P90, P95, and P99).
Important alert (level: danger): Enabling advanced query functionality with percentiles generates more [custom metrics](https://docs.datadoghq.com/metrics/custom_metrics/) and is [billed accordingly](https://docs.datadoghq.com/account_management/billing/custom_metrics/).
1. Click **Create Metric**.

Your RUM-based custom metric appears in the list below **Custom RUM Metrics**, and there may be a short delay for your metric to become available in [dashboards](https://docs.datadoghq.com/dashboards/) and [monitors](https://docs.datadoghq.com/monitors/).

Datapoints are not created for metrics with historical data. Datapoints for your RUM-based custom metric generate on a ten second interval. Metrics data is retained for 15 months.

### Add a RUM-based metric on sessions and views{% #add-a-rum-based-metric-on-sessions-and-views %}

Sessions and views are considered active when there is ongoing application or user activity in a RUM application. For example, as a user opens new pages, these pageviews are collected in the user session. As a user interacts with buttons on a page, these actions are collected in the pageviews.

Let's assume you have a RUM-based custom metric that counts the number of user sessions containing more than five errors, and a session ID `123` that reaches five errors at 11 AM and closes at 12 PM.

- By accounting for the session or view as soon as it matches the query, you increment the count metric's value by one at the 11 AM timestamp.
- By accounting for the session or view that is inactive, you increment the count metric's value by one at the 12 PM timestamp.

## Manage RUM-based custom metrics{% #manage-rum-based-custom-metrics %}

You can generate a count metric of RUM events that match a query or a [distribution metric](https://docs.datadoghq.com/metrics/distributions/) of a numeric value contained in RUM events, such as the request duration.

### Update a RUM-based custom metric{% #update-a-rum-based-custom-metric %}

To update a metric, hover over a metric and click the **Edit** icon to the right hand corner.

- Filter query: Change the set of matching RUM events that are aggregated into metrics.
- Aggregation groups: Update tags to manage the cardinality of generated metrics.
- Percentile selection: Click the **Calculate percentiles** toggle to remove or generate percentile metrics.

Because you cannot rename an existing metric, Datadog recommends creating another metric.

### Delete a RUM-based custom metric{% #delete-a-rum-based-custom-metric %}

In order to stop the computing of datapoints from your custom metric and billing, hover over a metric and click the **Delete** icon to the right hand corner.

## Usage{% #usage %}

You can use RUM-based custom metrics for the following actions:

- Visualize trends over a set period of time in a [dashboard](https://docs.datadoghq.com/dashboards/querying/#configuring-a-graph)
- Trigger an alert when a metric behaves differently than it has in the past in an [anomaly monitor](https://docs.datadoghq.com/monitors/types/anomaly/)
- Trigger an alert when a metric is predicted to cross a threshold in the future in a [forecast monitor](https://docs.datadoghq.com/monitors/types/forecasts/)
- Create [metric-based SLOs](https://docs.datadoghq.com/service_level_objectives/metric/) to track user-centric performance objectives for your teams and organizations

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

- [Learn how to capture RUM events from your browser and mobile applications](https://docs.datadoghq.com/real_user_monitoring/)
- [Learn how to create queries in the RUM Explorer](https://docs.datadoghq.com/real_user_monitoring/explorer/)
- [Learn about RUM event types](https://docs.datadoghq.com/real_user_monitoring/explorer/search/#event-types)
- [Generate metrics from ingested logs](https://docs.datadoghq.com/logs/log_configuration/logs_to_metrics/)
- [Generate RUM-based metrics to track historical trends in customer experience](https://www.datadoghq.com/blog/track-customer-experience-with-rum-metrics/)
