Skip to content

Instantly share code, notes, and snippets.

@wetzler
Last active August 29, 2015 14:10
Show Gist options
  • Save wetzler/15204426171990e5ceb3 to your computer and use it in GitHub Desktop.
Save wetzler/15204426171990e5ceb3 to your computer and use it in GitHub Desktop.
Keen IO Query Example: Users who did X action C times from D1 to D2, with filters
# Scenario:
We want all users who did event X,
where event X had property Y and Z with values A and B,
where event X happened C times within the dates D1 and D2.
# Solution:
You can arrive at the final result using this query:
var users_who_did_x = new Keen.Query("count", {
eventCollection: X,
groupBy: 'uuid',
timeframe: {
"start" : D1,
"end" : D2
},
filters: [
{
"property_name" : Y,
"operator" : "eq",
"property_value" : A
},
{
"property_name": Z
"operator":"eq",
"property_value": B
}
]
});
This query would return you a list of ALL user IDs meeting those criteria, along with a count of how many times each user did X, like this:
result: [
{
uuid: "Jenny",
result: 1
},
{
uuid: "Johnny",
result: 3
},
{
uuid: "Jelly",
result: 2
},
{
uuid: "Julie",
result: 2
},
]
If C = 2 then your result is Jelly & Julie.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment