It is possible to retrieve multiple metrics in a single query in certain situations.
You can use the Multi-Analysis query type to run multiple types of analyses over the same collection. Multi-Analysis is outlined in greater detail here: https://keen.io/docs/data-analysis/multi-analysis/
Retrieving multiple metrics from separate collections is a bit different. keen-js allows you to pass an array of queries to the .run()
function which it then runs simultaneously in the background. While it's true that keen-js is still running multiple queries behind the scenes, passing an array of query objects mimics a single query operation.
keen-js Example:
var count = new Keen.Query("count", {
eventCollection: "pageviews",
groupBy: "visitor.geo.country",
interval: "daily",
timeframe: "this_21_days"
});
var sum = new Keen.Query("sum", {
eventCollection: "purchases",
targetProperty: "total",
interval: "daily",
timeframe: "this_21_days"
});
client.run([count, sum], function(response) {
count = this.data[0];
sum = this.data[1];
var pageviews = new Keen.Visualization(count, document.getElementById("pageviews"), {
chartType: "metric",
title: "Pageviews"
});
var total = new Keen.Visualization(sum, document.getElementById("total"), {
chartType: "metric",
title: "Total"
});
});
There's also an example in keen-js that shows how to combine the results of multiple queries into a single chart: https://github.com/keen/keen-js/blob/master/docs/visualization.md#combine-results-of-two-queries