azure-application-insightsms-app-analytics

How to calculate DAU/MAU using Application Insights Analytics?


Assuming I have a definition of a user I can calculate sum of all daily users and all monthly users.

customEvents
| where timestamp > ago(30d)
| where <condition>
| summarize by <user>, bin(timestamp, 1d)
| summarize count() by bin(timestamp, 1d)
| summarize DAU=sum(count_)

customEvents
| where timestamp > ago(30d)
| where <condition>
| summarize by <user>
| MAU=30*count

The question is how to calculate DAU/MAU? Some join magic?


Solution

  • Edit:

    There is a much easier way to calculate usage metrics now - "evaluate activity_engagement":

    union *
    | where timestamp > ago(90d)
    | evaluate activity_engagement(user_Id, timestamp, 1d, 28d)
    | project timestamp, Dau_Mau=activity_ratio*100 
    | render timechart
    

    -------

    The DAU is really stright forward in Analytics - just use a dcount.

    The tricky part of course is calculating the 28-day rolling MAU.

    I wrote a post detailing exactly how to calculate stickiness in app analytics a few weeks back - The trick is that you have to use hll() and hll_merge() to calculate the intermediate dcount results for each day, and then merge them together.

    The end result looks like this:

    let start=ago(60d);
    let period=1d;
    let RollingDcount = (rolling:timespan)
    {
    pageViews
    | where timestamp > start
    | summarize hll(user_Id) by bin(timestamp, period)
    | extend periodKey = range(bin(timestamp, period), timestamp+rolling, period)
    | mvexpand periodKey
    | summarize rollingUsers = dcount_hll(hll_merge(hll_user_Id)) by todatetime(periodKey)
    };
    RollingDcount(28d)
    | join RollingDcount(0d) on periodKey
    | where periodKey < now() and periodKey > start + 28d
    | project Stickiness = rollingUsers1 *1.0/rollingUsers, periodKey
    | render timechart