
Statsig computes custom metrics from your raw events. To create custom metrics, navigate to **Metrics** from the left-hand navigation panel, then to the **Metrics Catalog** tab. Select the **Create** button.

{% figure %}
![Create custom metrics interface](/images/create-metric.png)
{% /figure %}

Statsig supports six types of custom metrics:

| Metric Type    | Description                                                                                                           | Examples                                                    |
| -------------- | --------------------------------------------------------------------------------------------------------------------  | ----------------------------------------------------------- |
| Event Count    | **Total count of events** filtered by the *Value*, *Metadata*, or *User Object* properties of an event type           | **Add to Cart** event filtered by category type             |
| User Count     | **Number of unique users** that trigger events filtered by the *Value*, *Metadata*, or *User Object* of an event type | **Active Users** based on their views of a product category |
| Aggregation    | **Sum or Average** of the *Value*, *Metadata*, and *User Object* property of an event type                            | **Total Revenue**                                           |
| Ratio          | **Rates** (e.g. cart conversion rate, purchase rate), **Normalized Values** (e.g. sessions per user, items per cart)  | **Cart Conversion Rate**, **Sessions per User**             |
| Funnel         | **Funnels**- funnel of multiple events with conversion tracking                                                       | **Sign-up Funnel**, **Checkout Funnel**                     |
| Count Distinct | **Count Distinct**- Number of unique values for a given field, often approximated with sketches                       | **Unique Songs** listened per user                          |

Statsig computes custom metrics daily for your **Metrics** dashboard, and rolls them up for the duration of the experiment in **Pulse Results** for your Feature Gates and Experiments. After you create a custom metric, it doesn't populate until the next day and doesn't backfill to previous days. Statsig calculates the metric only from the creation date forward.

Statsig lets you set a daily **max cap** for specific metrics. You can define maximum caps for various unit types associated with a metric. Statsig automatically adjusts any value exceeding the cap down to match it. For example, if purchases over $10,000 per day on your e-commerce platform shouldn't skew analysis, Statsig adjusts any transaction above that threshold down to the limit. Capped metrics are available for event count and aggregation (sum) metric types.

When creating a custom metric, you can preview the metric’s value at the bottom of the page. Select **View Output Preview** to see what the metric would have looked like based on its component values over the last 7 days, in both chart and table form.

{% figure %}
![Aggregation metric setup screen with output preview chart and table](/images/metrics/create/0869e1bf-8fea-407e-8a5f-8b97860b3867.png)
{% /figure %}

## Examples

### 1. Event count metrics

This example sets up a custom event metric to count the **number of add\_to\_cart events** filtered by a metadata property called *value*, which carries the price of the item added to the cart. Because the ID Type is set to *userID*, Statsig computes this metric as part of the test group that Statsig assigns the corresponding user to in an experiment.

{% figure %}
![Event count metric filtering add_to_cart events with value greater than 100](/images/metrics/create/95489e9b-36f2-4704-9970-da675a8a3d2e.png)
{% /figure %}

If you select the ID Type as *stableID*, Statsig computes this metric in the test group that Statsig assigns the corresponding device to in an experiment. When you select more than one ID Type, Statsig computes this metric for each ID Type you specify.

### 2. User count metrics

The example below creates a metric to count the **number of unique users** who viewed a product in the *toys* category that was priced under $10.

{% figure %}
![User count metric configuration counting viewers of toys category under ten dollars](/images/metrics/create/ae270d11-d3de-4f34-85e5-a67ad9c7cd9e.png)
{% /figure %}

**Time Window**

Statsig offers three time window options for user count metrics:

* **Daily Participation Rate**: Counts the total number of days a user has the selected event, divided by the number of days the user is in the experiment. The result is a value between 0 and 1, representing the probability of a user having the event on any given day. Works best for events expected to occur repeatedly for a given user.
* **One Time Event**: Checks if a user has the selected event at least once during their time in the experiment. The result is a binary metric with value 0 or 1 for each user. Ideal for events expected to occur only once per user, such as sign-up events.
* **Custom Attribution Window**: Lets you define a custom window after exposure to count an event toward a metric calculation.

### 3. Aggregation metrics

The example below shows a **Total Revenue** metric that sums the *value* associated with all purchase events.

{% figure %}
![Sum aggregation configuration for Total Revenue metric](/images/metrics/create/f0d4d21b-08ae-405d-a156-4d29f96ab298.png)
{% /figure %}

**\[In Beta] Currency Sum**

eCommerce customers often span multiple currency types and log payments in the currency the user actually pays. Currency sums convert payments recorded in different currencies to a single common currency. You must log two metadata fields in your event: a currency code and a value. Example metadata: `_{"currency_code": "USD", "currency_value": 123.45}_`

Statsig supports currency sums upon request. Ask in [Slack](https://statsig.com/slack).

### 4. Ratio metrics

The example below shows creating a **Cart Conversion Rate** metric. Statsig uses unique users who triggered the *purchase event* as the numerator, and unique users who triggered the *add to cart* event as the denominator. When calculating the numerator, Statsig includes only users who also had the denominator event on the same day. A user who has only a *purchase event* on a given day without an *add to cart* on that same day doesn't count toward the numerator.

{% figure %}
![Ratio metric setup for cart conversion rate](/images/metrics/create/9f8a671e-ac1f-4e2f-92cb-d154e0daecac.png)
{% /figure %}

This pattern also applies to **click-through rates (CTR)** in any part of a step-wise product journey (funnels). Statsig recommends using unique users in both the numerator and denominator for these metrics. For example, a user who reloads a page multiple times but clicks only once corresponds to a 100% CTR (1 out of 1). A user who loads a page once but clicks a button multiple times also counts as 1 out of 1. This approach handles cases where users see a key button, such as "Sign-up," multiple times a day, and Statsig counts a single click as a success.

The example below shows creating an **Items per Cart** metric. You can track the number of unique items added to a cart by logging an *add\_to\_cart* event for each item. For the numerator, select total event count. For the denominator, select unique users. Because Statsig computes this metric daily and only for users with a non-zero denominator, it can generate ratios such as 1/1, 2/1, and 5/1 for individual users. When aggregated, this translates to an average such as 10/4 = 2.5 items per cart per day.

{% figure %}
![Items per cart metric configuration using event counts](/images/metrics/create/cf6e6777-a154-4eeb-9a2d-81893810a31d.png)
{% /figure %}

{% callout type="info" %}
**A Word of Caution**

: In experimentation, ratio metrics are a frequent source of misleading information. It's possible to see an increase in

**click through rate**

alongside a net

*decrease*

in total clicks (the opposite may also happen). This situation can occur if the number of unique users viewing a button (denominator) decreases. As a best practice, Statsig recommends tracking the numerator and denominator as independent metrics when monitoring ratio indicator. Ratio metrics are often subject to statistical noise and can be tricky to use for obtaining a statistically significant result. In addition, for the numerator in ratios, Statsig excludes units that don't have a denominator value.
{% /callout %}

### 5. Funnel metrics

You can create a custom funnel metric from either the Custom Metrics Creation wizard in the Metrics Catalog or through the **Charts** tab.

{% figure %}
![Funnel metric creation wizard](/images/metrics/create/86914826-b8ce-4b4b-9514-39f31d05687a.png)
{% /figure %}

{% callout type="info" %}
**Important Note**

: Statsig handles funnel metrics differently between the Cloud and Warehouse Native platforms. Funnel metrics using the Cloud platform are

*always*

unordered, meaning that funnel steps can be completed in any order, and they have a time window of

*one day*

. This means that for the metric to record a completion, all steps must be triggered by a user within 24 hours. In contrast, funnel metrics on Warehouse Native have the option to be set with strict ordering and custom time windows.
{% /callout %}

### Components of funnel metrics

Funnel metrics have a few components:

1. **Lineage**: Surfaces the events used to generate the funnel
2. **Metric Value**: Metric value represents the overall funnel conversion rate, or the percentage of users who complete a funnel (trigger the end event) relative to all users who start the funnel (trigger the starting event)
3. **Conversion rate between stages**: This set of metrics track the percentage of users who triggered an event N relative to all users that triggered event N-1 in the funnel

{% figure %}
![Funnel lineage and stage conversion breakdown view](/images/metrics/create-user-funnels/172446711-5511e394-b353-4d38-97f1-1b681b67042b.png)
{% /figure %}

After Statsig creates and populates funnels, you can view your funnel metric like any other metric in Pulse. You can also expand the funnel metric to view Pulse performance at each step in the funnel.

In the example below, the **Square** variant shows a lift in the **overall funnel conversion rate**. Expanding the metrics to examine the entire funnel reveals two key insights:

* Both the **Square** and **Circle** variants show a lift in top-of-funnel DAU (*Land Page View Start DAU*). However, only the **Square** variant shows statistically significant increase in end-of-funnel DAU (*Purchase Event End DAU*).
* The overall funnel conversion rate improvement for **Square** is primarily due to the higher conversion from *Checkout Event* to *Purchase Event* stages in the funnel.

{% figure %}
![Funnel experiment results showing Square variant performance](/images/metrics/create-user-funnels/148440643-8e8a24bd-934d-4100-a15a-abcbcc4bb11c.png)
{% /figure %}

### 6. Count distinct metrics

{% callout type="info" %}
Sketch-based count distinct metrics are in beta. Reach out to Statsig support if you would like Statsig to enable this.
{% /callout %}

* **What it is:** A high-performance way to estimate the number of distinct values using compact sketch data structures. Example use cases include unique songs per user or unique products purchased per user.
* **Benefit:** Much faster to compute and uses significantly less memory compared to exact distinct counting, especially at high cardinality.

### Custom metrics and dimensions

For custom metrics composed of a single event (event count, event DAU, aggregation, and so on), Statsig automatically includes the dimensions of the source event in the custom metric and exposes them as dimensions of that metric. If your custom metric is composed of two or more different events, Statsig doesn't include the dimensions of those source events in the custom metric, and they aren't queryable through the "Explore" tab in Pulse Results.
