In some situations, you can get multiple metrics in a single query.
You can use the Multi-Analysis query type to run several types of analyzes on the same collection. The multi-analysis is described in detail here: https://keen.io/docs/data-analysis/multi-analysis/
Getting multiple metrics from individual collections is slightly different. keen-js allows you to pass an array of requests to the .run() function, which are then executed simultaneously in the background. While it is true that keen-js still runs multiple requests behind the scenes, passing an array of request objects mimics a single request 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 is also an example in keen-js that shows how to combine the results of several queries into one graph: https://github.com/keen/keen-js/blob/master/docs/visualization.md#combine-results-of- two-queries p>
source share