Skip to content

Instantly share code, notes, and snippets.

@ttrefren
Last active September 3, 2016 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttrefren/5d134da6a7ef7f9f6340139e279b2979 to your computer and use it in GitHub Desktop.
Save ttrefren/5d134da6a7ef7f9f6340139e279b2979 to your computer and use it in GitHub Desktop.
// get distribution of active days per company over a week.
// e.g. "100 companies were active 1 day, 200 were active 2 days, ..., 65 were active 7 days"
function main() {
return Events({
from_date: "2016-08-21",
to_date: "2016-08-26"
})
// dedupe into (day, company_id) tuples, because all we care about is
// that the company was present that day
.groupBy([event_to_date, "properties.company_id"], mixpanel.reducer.noop())
// group again by company_id and count the number of unique days
.groupBy(["key.1"], mixpanel.reducer.count())
// group AGAIN by the count to figure out your usage distribution across companies
.groupBy(["value"], mixpanel.reducer.count())
}
function event_to_date(e) {
return new Date(e.time).toISOString().split('T')[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment