-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
93 lines (84 loc) · 3.47 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!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 class="mixpanel-platform-section">
<div id="eventSelect1" style="float: left;"></div>
<div id="birth" class="mixpanel-platform-label" style="margin-left: 10px;">cohorts</div>
<div id="dateSelect" style="float: right;"></div>
<div style="clear: both;"></div>
<div id="eventSelect2" style="float: left;"></div>
<div id="retention" class="mixpanel-platform-label" style="margin-left: 10px;">retention</div>
<div id="blank" style="float: right;"></div>
<div style="clear: both;"></div>
<div id="graph"></div>
</div>
<div id="table"></div>
<script>
MP.api.ready(function() {
var eventSelect1 = $('#eventSelect1').MPEventSelect();
var eventSelect2 = $('#eventSelect2').MPEventSelect();
var dateSelect = $('#dateSelect').MPDatepicker();
var eventGraph = $('#graph').MPChart({chartType: 'line'});
var eventTable = $('#table').MPTable({
showPercentages: true,
firstColHeader: 'Date'
});
var params = {
'from': '2015-01-01', //moment(),
'to': '2015-01-01', //moment(),
'unit': 'month',
'interval_count': 12,
'born_event': '$signup'
};
var runQuery = function() {
var eventName1 = eventSelect1.MPEventSelect('value'),
eventName2 = eventSelect2.MPEventSelect('value'),
dateRange = dateSelect.MPDatepicker('value');
params['from'] = dateRange.from.toISOString().substring(0, 10);
params['to'] = dateRange.to.toISOString().substring(0, 10);
params['born_event'] = eventName1;
if (eventName1 && eventName2) {
var current_date = dateRange.from;
MP.api.retention(eventName2, params).done(function(results) {
data = results.values();
processResults(data);
});
}
}
var processResults = function(data) {
console.log(data);
var keys = Object.keys(data);
var finalResults = {};
for(i=0; i<keys.length; i++) {
finalResults[keys[i]] = {};
finalResults[keys[i]]['$'] = 0;
finalResults[keys[i]]['$'] = data[keys[i]]['first'];
var counts = Object.keys(data[keys[i]]['counts']);
for(j=0; j<counts.length; j++) {
finalResults[keys[i]][j+1] = 0;
finalResults[keys[i]][j+1] = data[keys[i]]['counts'][counts[j]];
}
}
eventTable.MPTable('setData', finalResults);
}
dateSelect.on('change', function(e, dateRange) {
runQuery();
});
eventSelect1.on('change', function(e, eventName) {
eventSelect2.MPEventSelect();
$("#birth").show();
$("#retention").show();
runQuery();
});
eventSelect2.on('change', function(e, eventName) {
runQuery();
});
});
</script>
</body>
</html>