Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to use multiple counts to achieve an OR filter on arrayed values in Keen IO (even though we don't recommend arrays if possible!)
// example event model
// User_Created_Event = {
// "full_name": "Macy Bode",
// "communities": [6,7,8],
// "email": "dev@dev.com"
// },
// Find the number of users in Community 6 or 7
Keen.ready(function() {
var countA = new Keen.Query("count", {
eventCollection: "User Created",
filters: [{
"property_name": "communities",
"operator": "eq",
"property_value": 6
}]
});
var countB = new Keen.Query("count", {
eventCollection: "User Created",
filters: [{
"property_name": "communities",
"operator": "eq",
"property_value": 7
}]
});
var countAnB = new Keen.Query("count", {
eventCollection: "User Created",
filters: [{
"property_name": "communities",
"operator": "eq",
"property_value": 6
},
"property_name": "communities",
"operator": "eq",
"property_value": 7
}]
});
client.run([countA, countB, countAnB], function(response){
// number of users in community 6 or community 7 is the number in each minus those in both
var solution = response[0].result + response[1].result - response[2].result
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.