Solved

Analyzing DAU / MAU in Mixpanel

  • 19 February 2019
  • 16 replies
  • 4369 views

Badge

Analyzing DAU / MAU can be difficult since you are measuring 2 metrics which are based on different time periods. Through Mixpanel's custom reporting language JQL and custom reporting capabilities, such an analysis can be made and easily visualized. An example of a custom application which calculates DAU / MAU that can be copied into your Mixpanel project can be found below.


<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="https://cdn.mxpnl.com/libs/mixpanel-platform/css/reset.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.mxpnl.com/libs/mixpanel-platform/build/mixpanel-platform.v0.latest.min.css">
    <script src="https://cdn.mxpnl.com/libs/mixpanel-platform/build/mixpanel-platform.v0.latest.min.js"></script>
  </head>
  <body class="mixpanel-platform-body">
    <div class="mixpanel-platform-section">
      <div id="dateSelect" style="float: right;"></div>
      <div id="eventSelect" style="float: left;"></div>
      <div id="propSelect" style="float: left;"></div>
      <div id="valSelect" style="float: left;"></div>
      <div style="clear: both;"></div>
      <b>DAU / MAU</b>
      <div id="daumauGraph"></div>
      <div style="clear: both;"></div>
      <br>
    </div>
    <div id="daumauTable"></div>
    <script>
      var dateSelect  = $('#dateSelect').MPDatepicker();
      var revenueGraph  = $('#revenueGraph').MPChart({chartType: 'line'});
      var daumauGraph  = $('#daumauGraph').MPChart({chartType: 'line'});
      var revenueTable  = $('#revenueTable').MPTable({
        firstColHeader: 'Event'
      });
      var daumauTable  = $('#daumauTable').MPTable({
        firstColHeader: 'Event'
      });
      var eventSelect = $('#eventSelect').MPEventSelect();
      var propertySelect = $('#propSelect').MPPropertySelect();
      var valueSelect = $('#valSelect').MPSelect();
      $('#propSelect').hide();
      $('#valSelect').hide();
      var params = {
        from: null,
        to: null,
        event_selectors: []
      }
      var queryEvent = 'Log In';
      params['event_selectors'] = [{ event: queryEvent }];

      var runQuery = function() {
        var dateRange = dateSelect.MPDatepicker('value');
        var dateRange = dateSelect.MPDatepicker('value');
        var dateRange = dateSelect.MPDatepicker('value');
        params['from'] = dateRange.from.toISOString().substring(0,10);
        params['to'] = dateRange.to.toISOString().substring(0,10);
        
        console.log(params);
        
        MP.api.jql(function main() {
            return Events({
              from_date: params.from,
              to_date: params.to,
              event_selectors: params.event_selectors
            })
            .groupByUser([event => new Date(event.time).toISOString().substring(0,10)], mixpanel.reducer.count())
            .groupBy([item => item.key[1]], mixpanel.reducer.count())
          }, params).done(function(results) {
          console.log(results);
          MP.api.jql(function main() {
            return Events({
              from_date: params.from,
              to_date: params.to,
              event_selectors: params.event_selectors
            })
            .groupByUser([event => new Date(event.time).toISOString().substring(0,7)], mixpanel.reducer.count())
            .groupBy([item => item.key[1]], mixpanel.reducer.count())
          }, params).done(function(uniques) {
            console.log(uniques);
            var daumauFinal = {};
            daumauFinal['DAU/MAU'] = {};
            for(i=0; i<results.length; i++) {
              var index = 0;
              for(z=0; z<uniques.length; z++) {
                if(uniques[z]['key'][0] == results[i]['key'][0].substring(0,7)) {
                  index = z;
                }
              }
              //console.log(uniques[index]);
              daumauFinal['DAU/MAU'][results[i]['key'][0]] = results[i].value / uniques[index].value;
            }
            console.log(daumauFinal);
            daumauGraph.MPChart('setData', daumauFinal);
            daumauTable.MPTable('setData', daumauFinal);
          })
        });

      };

      dateSelect.on('change', runQuery);
      eventSelect.on('change', function(e, newEvent) {
        params['event_selectors'] = [{ event: newEvent }];
        propertySelect = $('#propSelect').MPPropertySelect('setEvent', newEvent);
        $('#propSelect').show();
        runQuery();
      });
      propertySelect.on('change', function(e, property) {
        MP.api.query('https://mixpanel.com/api/2.0/events/properties/values', {event: eventSelect.MPEventSelect('value'), name: property}).done(function(jsons) {
          var dropdownItems = [];
          for (var i = 0; i<jsons.length; i++){
            dropdownItems.push({'value': jsons[i], 'label': jsons[i]});
            valueSelect.MPSelect('initEl', {items: dropdownItems})
          }
        });
        $('#valSelect').show();
      })
      valueSelect.on('change', function(e, value) {
        params.event_selectors = [];
        var selector = '(properties["' + propertySelect.val() + '"] == "' + value + '")';
        params.event_selectors = [{'event': queryEvent, 'selector': selector}];
        runQuery();
      });

    </script>
  </body>
</html>

icon

Best answer by stephanie 23 April 2019, 18:33

View original

16 replies

Userlevel 4
Badge +2

Thanks, Solutions Team!


Badge

I'm new to Mixpanel and JQL. If I copy and paste this code into the JQL console it will show errors.


Cand you @MixpanelSolutions or @Michael explain a bit more?


Thanks!


Userlevel 5
Badge +4

Hi @bochenn, Stephanie here from Mixpanel! The code above is meant to be pasted in your "Build an App" application to calculate Daily Active Users(DAU) or Monthly Active Users(MAU). You can find "Build an App" under your Applications section (top right grid of squares) in your Mixpanel account.

However, we now support the ability to easily calculate DAU (daily active users), WAU (weekly active users), and MAU (monthly active users) for any event (or custom event) of your choice, and with this, you can also easily calculate the stickiness of your product (DAU/MAU or DAU/WAU).

DAU, WAU, MAU and stickiness ratios (DAU/WAU and DAU/MAU) are popular ways for web and mobile applications to understand how users are using their product and how often they are coming back to use the product, and you can now calculate and visualize this metric for your product from right within Insights with just a few clicks. To see what it looks like, please take a look at the screenshot attached.

Don’t hesitate to let me know if you have any feedback or any questions!

Thanks,


Badge

Thanks @Stephanie!


Can you tell me how to calculate the stickiness DAU/MAU? I don't find it in the insights.


Thanks




Userlevel 5
Badge +4

@bochenn you can do your stickiness ratio (DAU/WAU or DAU/MAU) in our formulas. Below I have shared a screenshot calculating (A)DAU / (B)MAU using formulas to help see.




Badge

@stephanie if my description of "Active" user is user who does something for certain period, e.g. watch movie for 20 mins, then I need to use "DAU/WAU/MAU" feature in insight with "Cohort" feature. Is this correct?


So I just added the DAU JQL script and created a new report that is meant to track DAUs events but when I go to the chart it says “We couldn't find any data for your query.” is this something that it won’t start tracking for a while or typically how long does it take to collect data? 

How to calculate the metric for DAU/MAU for a custom event, for example MAU?DAU for a certain period? I was able to get the chart but the metric isn’t available.

How to calculate the metric for DAU/MAU for a custom event, for example MAU?DAU for a certain period? I was able to get the chart but the metric isn’t available.

Same problem here @stephanie / @mixpanelsolutions. I can create DAU/MAU graph which is nice but I would like to show it as a metric instead to show the average stickiness in a given time period. That option is not available.

Is there a solution in place?

Userlevel 1

**BUMP** 12/30/2021 and still am not able to report on a DAU/WAU/MAU count as a metric. Is there a workaround in place yet? @mixpanelsolutions 

Userlevel 1

For anyone else who ends up at this chain looking for answers to the question posed by @BornM, I’ve opened a separate request, specifically to address metrics not being supported with the pre-built DAU/WAU/MAU function. Please upvote so we can get this added to the MP agenda!

The current work around is to set the filter to count “uniques” and then add a filter with the property “Time.” Then filter to last 1 day for DAU, last 1 week for WAU, and last 1 Month for MAU.

Badge

@wtykidwell could you please show a screenshot of this? My brain is not currently working… maybe tomorrow, but I’m not following fully how you have this setup. Thank you!

Userlevel 1

@kirkn If I want to calculate Daily Active Users for my event App Session and show it as a # Metric, normally that’s impossible. To get around this, instead of selecting Count Users → DAU in position 1, I’m going to select Count Unique. I can add a filter in position 2 using “Time” to filter the results to the last 1 day. Only then, I am able to change the chart type to # Metric in position 3.

This is the solution MixPanel’s support team directed me towards.

Badge

Awesome, thank you @wtykidwell !

Mine is slightly different in step 2 for “Time” and my only option is “User > First Seen”, but I think it generally captures the same data / concept.

When you hover over “User > First Seen” - it says:

First seen is a datetime profile property that captures the timsetamp of the very first event for this user/group. This can be used to filter/segment reports by users who were "new" in a particular timeframe.

 

Userlevel 1

@kirkn The only difference I can see is that “User → First Seen” is a timestamp of the first instance, where “User → Time” is a timestamp for the most recent instance. If you aren’t seeing that as a mixpanel property, I’d reach out to MP and see why it’s not enabled for you.

For my purposes of calculating DAU/WAU/MAU, it’s important to use the most recent instance. But you’re right in that both are using the same concept.

@wtykidwell Thanks for that workaround, but I think that it does not replace DAU/WAU/MAU, let me explain:

 

Assume you have 7 users, every day only 1 user visits your page, and each day it’s another user.

Day 1: User #1

Day 2: User #2

Day 7: User #7

 

Unique users in the past 7 days would show 7, but DAU for the past 7 days should show 0 DAU since none of the users visited on each day during that time period. Only the graphs look alike but the metric shown with unique is incorrect for DAU. That’s at least how I understand this metric, please correct me if I’m wrong.

 

 

Reply