Created
November 26, 2025 06:52
-
-
Save fcoclavero/8561f487d98e8f66bfafd6d143948203 to your computer and use it in GitHub Desktop.
Mixpanel
This file contains hidden or 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
| /* ======================================================== | |
| * 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()); | |
| } |
This file contains hidden or 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
| 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