Skip to content

Instantly share code, notes, and snippets.

@wetzler
Created December 8, 2014 03:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wetzler/bf72167d348be7304e97 to your computer and use it in GitHub Desktop.
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