Skip to content

Instantly share code, notes, and snippets.

@kohiomobz
Created August 14, 2015 07:21
Show Gist options
  • Save kohiomobz/93046c386cb46792a48b to your computer and use it in GitHub Desktop.
Save kohiomobz/93046c386cb46792a48b to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<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 id="table"></div>
<script>
MP.api.ready(function() {
var dauEventName = 'user-info: Session end';
var revenueEvent = 'revenue: in app purchase';
var revenueProp = 'number(properties["_Revenue Revenue"])';
var dauParams = {
'unit': 'day',
'type': 'unique',
'from': moment().subtract(30, 'days')
}
var $dau = MP.api.events(dauEventName, dauParams);
var $revenue = MP.api.segment(revenueEvent, revenueProp, {from: moment().subtract(30, 'days'), method: 'sum'});
$.when($dau, $revenue).done(function(dau, revenue){
var dauValues = dau.values();
var revenueValues = revenue.values();
console.log(dauValues, revenueValues);
var data = {
'ARPDAU': {
}
};
_.each(_.keys(dauValues[dauEventName]), function(key){
if (key in revenueValues && revenueValues[key] && dauValues[dauEventName][key]) {
data['ARPDAU'][key] = revenueValues[key] / dauValues[dauEventName][key];
}
});
var chart = $('<div></div>').appendTo('body').MPChart({chartType: 'line'});
chart.MPChart('setData', data);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment