Last active
June 15, 2016 19:05
-
-
Save mixpanel-bot/1c84df3a8caef173e8cd to your computer and use it in GitHub Desktop.
Step six in Mixpanel Platform's DAU/MAU by country tutorial
This file contains 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
<!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"> | |
<script> | |
var eventName = 'Button clicked'; // replace with event name of your choice | |
var $dau = MP.api.segment(eventName, 'mp_country_code', { // use segment query on eventName, and segment the data by country | |
from: moment().subtract(30, 'days'), // 'from' date should be one month ago | |
to: moment().subtract(1, 'days'), // 'to' date should be yesterday; partial data for today impacts DAU more than it does MAU | |
unit: 'day', // we want the number of button clicks for each day of the month | |
type: 'unique' // daily counts should be unique; multiple clicks by the same person in one day should be counted only once | |
}); | |
var $mau = MP.api.segment(eventName, 'mp_country_code', { // use segment query on eventName, and segment the data by country | |
from: moment().subtract(30, 'days'), // 'from' date should be one month ago | |
to: moment().subtract(1, 'days'), // 'to' date should be yesterday; partial data for today impacts DAU more than it does MAU | |
unit: 'month', // we want the number of button clicks that occured over the month | |
type: 'unique' // multiple clicks by the same person during any point in the month should be counted only once | |
}); | |
$.when($dau, $mau).done(function(dau, mau) { | |
// average the DAU values and divide them by the MAU ones | |
// (we sum the MAU in the case where the 30 days spans over two months) | |
var dauMau = dau.avg().divide(mau.sum()).values(); | |
var sortedData = _.chain(dauMau) // enables function chaining | |
.pairs() // convert each object to an array for sorting | |
.sortBy(function(dauMau) { // sort by the dau/mau value in descending order | |
return -dauMau[1]; | |
}) | |
.object() // convert each array back to an object | |
.value(); // end the chaining and return the value | |
$('<div></div>').appendTo('body').MPChart({ // create chart | |
chartType: 'bar', // make it a bar chart | |
data: sortedData // set its data | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Any news?
hi @diegodotta those are warnings, not errors; I got at least the 2nd also. Does the report work for you? what browser are you on? I tried mine on firefox and after I fixed the event and date range it worked.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting this error and a blank page:
mixpanel-platform.js:45 - 'webkitIndexedDB' is deprecated. Please use 'indexedDB' instead.
moment.js:324 - Deprecation warning: Accessing Moment through the global scope is deprecated, and will be removed in an upcoming release.
:(