Mixpanel Community Icon

Troubleshooting Mixpanel JQL: Discrepancies in Session Start Event Counts

·
·

We are using Mixpanel to log a single event Session Start . This is in our staging environment and we don't have a lot of data there. For example, in the last 7 days we have 1529 events for the project in total (I am getting this number from the Events tab in the Mixpanel UI when filtering for 7 days). What I'm trying to do is count all of the Session Start events per user so that I can inject it into MongoDB so that we can report against it. The results that I see from the Mixpanel web UI are different than what I see when querying the API via JQL. For example, via the web UI, I see 14 unique user IDs when using a breakdown of Session Start events by User ID, as seen in the attached screenshot. When querying via the API, I only see four users active in the past week. Here is the JQL I am using

 function main() {
      return Events({
        from_date: "2025-01-15",
        to_date: "2025-01-22"
      })
      .filter(function(event) {
        const dollarFound = event.distinct_id.indexOf('$')
        return event.name === "${filterEvent}" && dollarFound != 0;
      })
      .groupBy(["distinct_id"], mixpanel.reducer.count());
    }
  `

I have tried using .groupByUser(mixpanel.reducer.count()), in the above query (and removing the filter), and expanding the date range to 2025-01-13 ..2025-01-23 (9 days in the past and one day in the future), and I still only get 4 results (there are $device results if I remove the filter). The results have some overlap with what is in the screenshot, and I am fairy confident I am querying the correct project ID (2380236). I feel like there must be something trivial I am missing about my understanding of JQL. If somebody could help me look at this I would appreciate it. Thanks.

  • Avatar of Ashley W.
    Ashley W.
    ·
    ·

    If I’m understanding you correctly, I think what you want is to use JQL to break down the number of “Session Start” (manually tracked) events by the number of unique users right? Same as this report: https://mixpanel.com/s/KAqol If so, you can use the following JQL query - you’ll find that the JQL output and the report results will line up.

    function main() {
      return Events({
        from_date: '2025-01-16',
        to_date:   '2025-01-23',
        event_selectors: [{event: "Session Start"}]
      })
      .groupBy(["properties.$user_id"], mixpanel.reducer.count())
      .map(function(row){
        return {
          $user_id: row.key[0],
          num_of_session_start: row.value
        }
      })
    } 

  • Avatar of Dan S.
    Dan S.
    ·
    ·

    Ashley W. thank you so much - this is a perfect solution. You can close this ticket. I appreciate the great support.

  • Avatar of Ashley W.
    Ashley W.
    ·
    ·

    You're most welcome! :)