Skip to content

Instantly share code, notes, and snippets.

@fcoclavero
Created November 26, 2025 06:52
Show Gist options
  • Select an option

  • Save fcoclavero/8561f487d98e8f66bfafd6d143948203 to your computer and use it in GitHub Desktop.

Select an option

Save fcoclavero/8561f487d98e8f66bfafd6d143948203 to your computer and use it in GitHub Desktop.
Mixpanel
/* ========================================================
* Daily active users
* How many users sent at least 5 events per day?
*/
function main() {
return Events({
from_date: "2025-10-27",
to_date: "2025-11-26"
})
// group each user's events by the day they were triggered,
// and count how many events they sent each day
.groupByUser([mixpanel.numeric_bucket('time', mixpanel.daily_time_buckets)], mixpanel.reducer.count())
// filter out days where a user sent < 5 events
.filter(function(user_count) {
return user_count.value >= 5;
})
// group by each day and count unique users
.groupBy([mixpanel.slice('key', 1)], mixpanel.reducer.count());
}
function main() {
return Events({
from_date: "2025-10-25",
to_date: "2025-11-25"
})
// 1) Count events per user
.groupByUser(mixpanel.reducer.count())
// 2) Keep only users with >= 5 events
.filter(function(group) {
// group.key[0] -> distinct_id
// group.value -> event count for this user
return group.value >= 5;
})
// 3) Count how many such users there are
.reduce(mixpanel.reducer.count());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment