In the documentation you say:
Consolidate multiple queries into a single query (for example, multiple queries filtering on a single property may be combined into a single segmentation query).
How to do that ? i have to query the same metric but in different Events, give me an example
Great question! The tip about consolidating queries refers to using the Segmentation API with a where filter expression, so you can query multiple events or filter conditions in a single API call instead of making separate requests.
Here's a practical example using the Query API. Suppose you want to count events for both "Purchase" and "Add to Cart" in one query, filtered by a property (e.g., country == "US"):
Instead of making two separate API calls (one per event), you can use JQL to combine them into a single query:
function main() {
return Events({
from_date: params.start_date,
to_date: params.end_date,
event_selectors: [
{ event: "Purchase" },
{ event: "Add to Cart" }
]
})
.filter(function(e) {
return e.properties.country == "US";
})
.groupBy(["name"], mixpanel.reducer.count());
}
This single query:
Fetches both events at once via event_selectors
Filters them by the same property (country == "US")
Groups results by event name so you get a count per event
[JQL params example; groupBy docs]
Alternatively, if you're using the Segmentation REST API (not JQL), you can use the where parameter with an expression like:
where=properties["country"] == "US"
But note the Segmentation API only accepts a single event per call (event parameter), so for multiple events, JQL is the better approach to truly consolidate into one query. [Query API; rate limits]
ā¹ļøĀ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.
