---
title: "Metrics"
description: "Reference documentation for the Metrics endpoints in the Klaviyo REST API."
url: "https://developers.klaviyo.com/en/v2024-02-15/reference/metrics"
revision: "2024-02-15"
llmsTxt: "https://developers.klaviyo.com/en/v2024-02-15/reference/metrics/llms.txt"
---

# Metrics

## Before you begin

Check out our general [API overview](https://developers.klaviyo.com/en/reference.md) before getting started with specific endpoints.

Before you can create custom metrics:

1. Ensure you have metrics (e.g., *Placed Order*) in your account and real event data for those metrics.
2. Use [Get Metrics](https://developers.klaviyo.com/en/reference/get_metrics.md) to fetch the set of available metrics in an account and [Get Properties for Metric](https://developers.klaviyo.com/en/reference/get_properties_for_metric.md) to confirm a metric’s available properties that can be used in custom metric filters.

You’ll then be able to use the Custom Metrics API to create custom metrics based on the existing metrics in an account.

## Using custom metrics

By default, Klaviyo provides metrics that track your business’s performance and measure success (e.g., a *Placed Order* event from a Klaviyo e-commerce integration). However, there may be instances where you need to create custom metrics to more accurately capture how your business runs. For examples of useful custom metrics, check out our [strategic guide on using custom metrics](https://help.klaviyo.com/hc/en-us/articles/22311212640027).

Our Custom Metrics API allows you to manage custom metrics programmatically, i.e., custom conversion metrics that are based off of metrics in your account (native Klaviyo, integration-specific, and API metrics).

> [!NOTE]
> Standard accounts can only have 1 custom metric. Upgrade to Klaviyo’s [Advanced KDP](https://www.klaviyo.com/products/advanced-cdp) or [Marketing Analytics](https://www.klaviyo.com/solutions/analytics) plan to create up to 50 custom metrics. Advanced KDP also automatically detects and provides default custom metrics based on an account's active integrations. To learn more about these plans, visit our [billing guide](https://help.klaviyo.com/hc/en-us/articles/115000976672).

## Use cases

Here are some example use cases supported by the Custom Metrics API:

* Create a custom metric to better model the important conversion metrics that are specific to an account's business, e.g., a custom metric based on *Placed Order* that filters out recurring subscriptions or an “Ordered Product - Retail” metric for products ordered online (vs. in-person).
* Update the definition for a custom metric.
* Use a custom metric "Revenue" as the conversion metric in our campaign & flow [Reporting APIs](https://developers.klaviyo.com/en/reference/reporting.md) to understand attributed revenue for flows & campaigns (see [Use the Reporting API on custom metrics](#use-the-reporting-api-on-custom-metrics)).
* Delete a custom metric.
* Fetch metrics related to a custom metric, i.e., metrics that define a given custom metric.

> [!NOTE]
> After you create your own custom metrics (e.g., a custom metric based on *Placed Order* that excludes subscriptions), applicable reporting will be updated in the UI.

## Data model

A custom metric has the following structure:

* `id`

    The ID of the custom metric.

* `attributes`
    * `name`

        The name of the custom metric.

    * `definition`

        The definition of a custom metric. It is composed of a list of `metric_groups`, which are combined with a logical AND.

        * `aggregation_method`

            Method of aggregation for custom metric measurements (`value` or `count`). A metric with a `value` aggregation method is treated as a revenue metric, e.g., *Placed Order*; the metric must have a `"$value"` property to use this kind of aggregation.  A metric with a `count` aggregation method is used for reporting on the count of the metric.

        * `metric_groups`

            An array of objects that defines which events the custom metric should include. For each metric group, you must provide an identifier for an existing metric, e.g., *Placed Order*. Then, you may filter the metric’s properties to further define which events should be included.

            * `metric_id`

                The ID of the metric that composes the custom metric.

            * `metric_filters`

                An optional array of objects for filtering on properties of the metric.

                * `property`

                    The property for the given metric that you’d like to filter on, e.g., `ItemNames`.

                * `filter`

                    The filter that is to be applied to the property, e.g., a filter that checks if a specific item is present in a list. See the API reference documentation for a complete list of filters.

            * `value_property`

                The property that calculates the conversion value (only used for custom metrics with an `aggregation_method` of `value`). If null, the default `$value` property will be used.

> [!WARNING]
> Each custom metric you create can be composed of up to 5 different metrics and up to 3 metric filters per metric group. (see *Limitations* for more information).

## Get Custom Metrics

The [Get Custom Metrics](https://developers.klaviyo.com/en/reference/get_custom_metrics.md) endpoint is useful for retrieving information about custom metrics in an account. You can include related metrics in your response and use sparse fieldsets to request only specific fields in your response, e.g., only show aggregation method fields for custom metrics in your account. Similarly, [Get Custom Metric](https://developers.klaviyo.com/en/reference/get_custom_metric.md) is useful for fetching data for a given custom metric.

Use sparse fieldsets to only show the desired fields in your response. See the example request to Get Custom Metrics below:

```json Request
curl --request GET \
     --url 'https://a.klaviyo.com/api/custom-metrics/?fields%5Bcustom-metric%5D=name,definition.aggregation_method' \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'revision: 2025-04-15'
```
```json Response
{
    "data": [
        {
            "type": "custom-metric",
            "id": "01J2EZE52CT203GP5BGJPP9H5A",
            "attributes": {
                "name": "Placed Order - Online",
                "definition": {
                    "metric_groups": [
                        {
                            "metric_id": "SDXgcj",
                            "metric_filters": [
                                {
                                    "property": "Source Name",
                                    "filter": {
                                        "type": "list",
                                        "operator": "not-contains",
                                        "value": "pos"
                                    }
                                }
                            ],
                            "value_property": "$value"
                        }
                    ],
                    "aggregation_method": "value"
                }
            },
            "relationships": {
                "metrics": {
                    "data": [
                        {
                            "type": "metric",
                            "id": "SDXgcj"
                        }
                    ],
                    "links": {
                        "self": "https://a.klaviyo.com/api/custom-metrics/01J2EZE52CT203GP5BGJPP9H5A/relationships/metrics/",
                        "related": "https://a.klaviyo.com/api/custom-metrics/01J2EZE52CT203GP5BGJPP9H5A/metrics/"
                    }
                }
            },
            "links": {
                "self": "https://a.klaviyo.com/api/custom-metrics/01J2EZE52CT203GP5BGJPP9H5A/"
            }
        },
        {
            "type": "custom-metric",
            "id": "01J2EZE4YJQCCZ4NTTA6RSPY24",
            "attributes": {
                "name": "Ordered Product - Count",
                "definition": {
                    "metric_groups": [
                        {
                            "metric_id": "RaFtaN",
                            "metric_filters": [],
                            "value_property": null
                        }
                    ],
                    "aggregation_method": "count"
                }
            },
            "relationships": {
                "metrics": {
                    "data": [
                        {
                            "type": "metric",
                            "id": "RaFtaN"
                        }
                    ],
                    "links": {
                        "self": "https://a.klaviyo.com/api/custom-metrics/01J2EZE4YJQCCZ4NTTA6RSPY24/relationships/metrics/",
                        "related": "https://a.klaviyo.com/api/custom-metrics/01J2EZE4YJQCCZ4NTTA6RSPY24/metrics/"
                    }
                }
            },
            "links": {
                "self": "https://a.klaviyo.com/api/custom-metrics/01J2EZE4YJQCCZ4NTTA6RSPY24/"
            }
        }
    ],
    "links": {
        "self": "https://a.klaviyo.com/api/custom-metrics?fields[custom-metric]=name,definition.metric_groups,definition.aggregation_method"
    }
}
```

## Create Custom Metric

To create a custom metric, you’ll need to provide a definition object that includes the aggregation method and metric groups that define what events your custom metric includes.

The example request payload below for [Create Custom Metric](https://developers.klaviyo.com/en/reference/create_custom_metric.md) creates a custom metric based on *Placed Order* that filters out recurring subscriptions:

```json Request
{
    "data": {
        "type": "custom-metric",
        "attributes": {
            "name": "Placed Order - Ecommerce",
            "definition": {
                "aggregation_method": "value",
                "metric_groups": [{
                    "metric_id": "T4kAe8",
                    "value_property": "Revenue",
                    "metric_filters": [{
                        "property": "Source Name",
                        "filter": {
                            "type": "string",
                            "operator": "does not equal",
                            "value": "subscription"
                        }
                    }]
                }]
            }
        }
    }
}
```

Here’s how the resulting custom metric definition appears in Klaviyo’s custom metric builder (**Metrics** > **Create custom metric**):

<img src="https://files.readme.io/a489aa7e9b036822c97fc5a4d5e81f75a32b13dc971e394e5edffee5546f915c-placedorder_nonrecurring.jpg" alt="custom metric in the Klaviyo custom metric UI" loading="lazy" />

## Use the Reporting API on custom metrics

You can use the [Reporting API](https://developers.klaviyo.com/en/reference/reporting.md) on custom metrics to retrieve attributed value for campaigns and flows.

1. Use Get Custom Metrics to get the metric ID for the custom metric you’d like to use for calculating conversion-based statistics.
2. Then, create a campaigns or flows report to request statistics for a given campaign or flow using the Reporting API.

The example below is a request payload to Query Campaign Values that fetches campaign performance data using a custom metric for calculating conversion-based statistics:

```json Request
curl --request POST \
     --url https://a.klaviyo.com/api/campaign-values-reports/ \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'revision: 2025-04-15' \
     --data '
{
  "data": {
    "type": "campaign-values-report",
    "attributes": {
      "timeframe": {
        "key": "last_12_months"
      },
      "conversion_metric_id": "01J2EZE52CT203GP5BGJPP9H5A",
      "filter": "equals(campaign_id",\"01GMRWDSA0ARTAKE1SFX8JGXAY\")",

      "statistics": [
        "opens",
        "open_rate"
      ]
    }
  }
}
'
```

## Limitations

* Accounts can only have one custom metric. To access up to 50 custom metrics, the [Advanced Klaviyo Data Platform](https://www.klaviyo.com/products/advanced-cdp) is required.
* A custom metric group can contain up to 5 metrics.
* A metric defined within the custom metric group can have up to 3 filters on its properties.

## Common errors

| Status code | Reasons                                                                                                                                                                                                                                                                                                                                                                                        |
| :---------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 400         | <ul><li>The payload is formatted incorrectly.</li><li>The `metric_groups` limit or `metric_filters` limit has been exceeded.</li><li>The request is missing a required parameter or has an invalid parameter.<li>The payload references a field that does not exist, e.g., a metric’s `value_property` defaults to `$value`, however this field does not exist for the given metric.</li></ul> |
| 403         | <ul><li>The request attempts to create more custom metrics than is allowed for the account.</ul>                                                                                                                                                                                                                                                                                               |
| 429         | <ul><li>[Rate limit](https://developers.klaviyo.com/en/docs/rate_limits_and_error_handling.md) exceeded. See rate limits for endpoints in the API reference documentation.</ul>                                                                                                                                                                                                       |

## Additional resources

* [How to configure custom conversion metrics](https://help.klaviyo.com/hc/en-us/articles/22311085738395)
* [Understanding when and how to use custom conversion metrics](https://help.klaviyo.com/hc/en-us/articles/22311212640027)

## Metrics API overview

### Before you begin

Check out our general [API overview](https://developers.klaviyo.com/en/reference.md) before getting started with specific endpoints.

Our [Metrics API](https://developers.klaviyo.com/en/reference/get_metrics.md) enables a zoomed out view of your metric data so that you can dive deeper into your business’s performance with Klaviyo. A metric is a category of event, or action a person can take. For example, when a customer places an order, a _Placed Order_ event is created for the profile, that event being an instance of the _Placed Order_ metric. All _Placed Order_ events collected or sent via the same mechanism (a given integration or our APIs) will share the same _Placed Order_ metric represented by its `metric_id`.

The Metrics API allows you to fetch metric information, including a given metric’s `metric_id`, which can then be used to [query aggregate metric data](https://developers.klaviyo.com/en/docs/using_the_query_metric_aggregates_endpoint.md). These metrics include:

- Native Klaviyo metrics.
- Other integration-specific (e.g., Shopify) metrics.
- API metrics.

### Use cases

Here are some example use cases supported by the Metrics API:

- Retrieve a metric’s ID (`metric_id)` and use it to query and aggregate event data associated with the metric.
- Filter metrics by integration name and/or category, e.g., Shopify-created metrics.
- Query aggregate event data associated with a metric by passing a JSON request body with metric attributes and filters (e.g., aggregate _Placed Order_ events that span over a holiday weekend).

### Data model

A retrieved metric will have the following:

- `id`

    The metric id.

- `name`

    The metric name, e.g, _Opened Email_.

- `created`

    The timestamp of when the metric was created.

- `updated`

    The timestamp of when the metric was last updated.

- `integration`

    The integration object used to capture the metric, e.g., Klaviyo.

  - `id`

      The integration ID.

  - `name`

      The name of the integration, e.g., `Klaviyo`.

  - `category`

      The category of the integration, e.g., `Internal` for Klaviyo.

### Get Metrics

The [Get Metrics](https://developers.klaviyo.com/en/reference/get_metrics.md) endpoint is useful for retrieving information about multiple metrics on your account, including their names, IDs, and the integrations used to capture them. Similarly, the [Get Metric](https://developers.klaviyo.com/en/reference/get_metric.md) endpoint is useful for fetching the same information about a single metric at a time.

You can use sparse fieldsets to only show the desired fields in your response. See the example request to [Get Metrics](https://developers.klaviyo.com/en/reference/get_metrics.md) below:

```curl Request
curl --request GET \
     --url 'https://a.klaviyo.com/api/metrics/?filter=equals(integration.name,"Klaviyo")&fields%5Bmetric%5D=name,integration' \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'revision: 2023-10-15'
```
```json Response
{
    "data": [
        {
            "type": "metric",
            "id": "REcTBe",
            "attributes": {
                "name": "Sent SMS",
                "integration": {
                    "id": "0rG4eQ",
                    "name": "Klaviyo"
                }
            },
            "links": {
                "self": "https://a.klaviyo.com/api/metrics/REcTBe/"
            }
        },
        {
            "type": "metric",
            "id": "RcsmFp",
            "attributes": {
                "name": "Marked Email as Spam",
                "integration": {
                    "id": "0rG4eQ",
                    "name": "Klaviyo"
                }
            },
            "links": {
                "self": "https://a.klaviyo.com/api/metrics/RcsmFp/"
            }
        },
    ...
}
```

Note that an equals filter, `?filter=equals(integration.name,"Klaviyo")`, has been applied to only include native Klaviyo metrics in the response. Sparse fieldsets are also used to only display the metric’s `name`, `integration.id`, and `integration.name`.

### Query metrics

The Metrics API allows for filtering and including certain metric data, such as filtering by native Klaviyo metrics like _Opened Email_ or _Clicked Email_. Check out the supported query parameters below and [test them out with our latest Postman collection](https://developers.klaviyo.com/en/docs/use_klaviyos_postman_collections.md). Note that support for given operators and fields is endpoint-specific. Review the [API reference documentation](https://developers.klaviyo.com/en/reference/get_metrics.md) for more information on allowed fields and query operators.

> [!WARNING]
> Filtering by `integration.name` and/or `integration.category` is case-sensitive. The `integration.name` should identically match the brand name of the integration it references. See the table below for acceptable values.

| Integration | `integration.name` | `integration.category` |
| --- | --- | --- |
| Klaviyo | `"Klaviyo"` | `"Internal"` |
| API | `"API"` | `"API"` |
| Other core integrations<br />(Shopify, PrestaShop, BigCommerce, etc.) | `"Shopify"`<br />`"PrestaShop"`<br />`"BigCommerce"` | `"eCommerce"` |

### Query Metric Aggregates

> [!WARNING]
> When <a href="https://developers.klaviyo.com/en/docs/using_the_query_metric_aggregates_endpoint.md" target="_blank">using the Query Metric Aggregates endpoint</a> to export data, the dates you filter and group by are determined by the time the event occurred, not the send date of the campaign or flow. This differs from the performance data shown in Klaviyo's UI, which is calculated by send date. For campaign and flow performance data as displayed in the app, we recommend using the <a href="https://developers.klaviyo.com/en/reference/reporting.md" target="_blank">Reporting API</a>.

The [Query Metrics Aggregates](https://developers.klaviyo.com/en/reference/query_metric_aggregates.md) endpoint is useful for pulling aggregated metric data out of Klaviyo and creating your own custom reports. For example, if you wanted to directly retrieve a count of how many orders had been placed on a monthly basis for the past year, you can make a query for a _Placed Order_ metric:

```curl Request
curl --request POST \
     --url https://a.klaviyo.com/api/metric-aggregates/ \
     --header 'Authorization: Klaviyo-API-Key your-private-api-key' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'revision: 2023-10-15' \
     --data '
{
  "data": {
    "type": "metric-aggregate",
    "attributes": {
      "measurements": ["count"],
      "filter": [
          "greater-or-equal(datetime,2023-01-01T00:00:00Z)",
          "less-than(datetime,2024-01-01T00:00:00Z)"
      ],
      "metric_id": "XWKwsS",
      "interval": "month",
      "page_size": 500,
      "timezone": "UTC"
    }
  }
}
'
```

Our Query Metrics Aggregates endpoint offers robust support for filtering results and grouping by time, event, or profile. Some use cases include:

- Extracting email engagement or ecommerce event data from Klaviyo to send to a data warehouse (e.g., syncing event data to Snowflake).
- Analyzing a count of SMS events by timezone.
- Reviewing _Clicked Email_ events to compare engagement between different email versions sent out for A/B testing.

For a comprehensive list of native Klaviyo metrics and their associated attributes for grouping and filtering, refer to the [list of supported attributes](https://developers.klaviyo.com/en/docs/supported_metrics_and_attributes.md).

### Next steps

Try out the following:

- Retrieve a `metric_id` from a call to [Get Metrics](https://developers.klaviyo.com/en/reference/get_metrics.md) with your Klaviyo test account via [Postman](https://www.postman.com/klaviyo).
- Use the [Create Event](https://developers.klaviyo.com/en/reference/create_event.md) endpoint to create events for this metric over a period of time.
- Use the retrieved `metric_id` to make a call to the [Query Metric Aggregates](https://developers.klaviyo.com/en/reference/query_metric_aggregates.md) endpoint. Try out the endpoint with native Klaviyo metrics and/or other integrations.

### Additional resources

- [Use the Query Metric Aggregates endpoint](https://developers.klaviyo.com/en/docs/using_the_query_metric_aggregates_endpoint.md)
- [Export data from Klaviyo](https://developers.klaviyo.com/en/docs/export_data_from_klaviyo.md)
- [Supported attributes (for filtering and grouping with the Query Metric Aggregates endpoint)](https://developers.klaviyo.com/en/docs/supported_metrics_and_attributes.md)

## Endpoints

- [Get Metrics](https://developers.klaviyo.com/en/v2024-02-15/reference/get_metrics.md): `GET /api/metrics/`
- [Query Metric Aggregates](https://developers.klaviyo.com/en/v2024-02-15/reference/query_metric_aggregates.md): `POST /api/metric-aggregates/`
- [Get Metric](https://developers.klaviyo.com/en/v2024-02-15/reference/get_metric.md): `GET /api/metrics/{id}/`
