Created
March 6, 2019 07:33
-
-
Save walkerofmargins/2950b20b95613d94bd8de1e0f42fb49e to your computer and use it in GitHub Desktop.
JQL Demo example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////// | |
/* Return an event count grouped by a single property */ | |
////////////////////////////////////////////////////////// | |
function main() { | |
return Events({ | |
from_date: '2018-02-10', | |
to_date: '2019-02-20', | |
event_selectors: [{ | |
event: 'Shopping List Add' | |
}] | |
// event_selectors: [{ | |
// event: 'Like Recipe' | |
// }] | |
}) | |
////////////////////////////////////////////////////////// | |
/* Aggregate – reduce with mixpanel.reducer.count() */ | |
////////////////////////////////////////////////////////// | |
// .reduce(mixpanel.reducer.count()) | |
////////////////////////////////////////////////////////// | |
/* Transform – groupBy a property */ | |
////////////////////////////////////////////////////////// | |
// .groupBy(['properties.Ingredient'], mixpanel.reducer.count()) | |
// .groupByUser(mixpanel.reducer.count()) | |
////////////////////////////////////////////////////////// | |
/* Return – return event data filtered for a specific event */ | |
////////////////////////////////////////////////////////// | |
// .filter(function(item) { | |
// return item.key[0] === 'salt' | |
// }).map(results => ({ | |
// 'Ingredient': results.key[0], | |
// 'Count': results.value | |
// })).filter(function(events) { | |
// return events['Ingredient'] && events['Count'] >= 2 | |
// }) | |
// // // // // // // // // // // | |
////////////////////////////////////////////////////////// | |
/* Filter out null values for Unit */ | |
/* Return – return event data filtered for a specific event */ | |
////////////////////////////////////////////////////////// | |
// .filter(function(events) { | |
// return events.properties.Unit | |
// }) | |
// .reduce(mixpanel.reducer.count()) | |
////////////////////////////////////////////////////////// | |
/* Return an event count grouped by multiple properties */ | |
/* Aggregate – reduce with mixpanel.reducer.count() */ | |
////////////////////////////////////////////////////////// | |
// .groupBy(["properties.Unit", "properties.Ingredient"], mixpanel.reducer.count()) | |
// .map(results => ({ | |
// '1. Total Count': results.value, | |
// '2. Unit': results.key[0], | |
// '3. Ingredient': results.key[1] | |
// })) | |
////////////////////////////////////////////////////////// | |
//Return an hour of day distribution for an event broken out by platform: | |
/* Return – return event data filtered for a specific event */ | |
/* Transform – groupBy a function to convert timestamps and the platform */ | |
/* Aggregate – reduce with mixpanel.reducer.count() */ | |
////////////////////////////////////////////////////////// | |
// .groupBy(["properties.mp_lib", mixpanel.numeric_bucket('time', mixpanel.hourly_time_buckets)], mixpanel.reducer.count()).map(results => ({ | |
// 'time': new Date(results.key[1]).toISOString().split('T')[1], | |
// 'OS': results.key[0], | |
// 'Count': results.value | |
// })) | |
////////////////////////////////////////////////////////// | |
//Return the sum of a property on a specific event: | |
/* Return – return event data filtered for a specific event */ | |
/* Transform – no transformation needed here */ | |
/* Aggregate – reduce with mixpanel.reducer.sum(), passing a property */ | |
////////////////////////////////////////////////////////// | |
// .groupBy(['properties.Count'], mixpanel.reducer.count()).reduce(mixpanel.reducer.sum('key.0')); | |
////////////////////////////////////////////////////////// | |
/* Return the 95th percentile of # of times users perform a certain event */ | |
/* Return – return event data filtered for a specific event */ | |
/* Transform – groupByUser so we can count individual users */ | |
/* Aggregate – reduce with mixpanel.reducer.count() to count each user */ | |
/* Aggregate – reduce for numeric percentiles on the results for # of times a user does the specific action */ | |
////////////////////////////////////////////////////////// | |
/* Like Recipe */ | |
// .groupByUser(mixpanel.reducer.count()).reduce(mixpanel.reducer.numeric_percentiles('value', 95)); | |
////////////////////////////////////////////////////////// | |
/* Writing your own reducer function - Number of events (same as line 21) */ | |
////////////////////////////////////////////////////////// | |
// .reduce(function(accumulators, events) { | |
// var count = 0; | |
// count = events.length; | |
// for (var i = 0; i < accumulators.length; i++) { | |
// count += accumulators[i]; | |
// } | |
// return count; | |
// }); | |
////////////////////////////////////////////////////////// | |
//Reducer using groupByUser - Number of events by distinct ID (same as line 58) | |
////////////////////////////////////////////////////////// | |
// .groupByUser(function(state, events) { | |
// state = state || { | |
// count: 0 | |
// }; | |
// for (var i = 0; i < events.length; i++) { | |
// state.count += 1; | |
// } | |
// return state; | |
// }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment