Learn what filters are and how to use them to categorize your metrics.
A filter is a key-value pair used to add additional metadata to your metrics. Filters provide context about your data, allowing you to categorize, segment, and analyze metrics effectively.
Filters are helpful when you want to:
production
or development
.us-east
or eu-west
.Filters are defined as a map of key-value pairs in your metric payload. Here's how to add filters when capturing a metric.
environment
, region
).filters
object when sending your event.Below is an example of creating a metric with filters using the Measurely TypeScript SDK:
import { Measurely } from "measurely-sdk";
// Initialize Measurely with your API key
const measurely = new Measurely("YOUR_API_KEY");
// Define your filters
const filters = {
environment: "production",
region: "us-east",
};
// Create a metric payload with value and filters
const payload = {
value: 42,
filters: filters,
};
// Capture the metric
measurely.capture("example_metric", payload)
.then((result) => {
if (result.success) {
console.log("Metric captured successfully!");
} else {
console.error("Error capturing metric:", result.message);
}
})
.catch((error) => {
console.error("Unexpected error:", error);
});
environment
, region
, or user_type
.