-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
183 lines (172 loc) · 7.8 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!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 class="instructions">
<h1 style="font-size: 18px; color: rgb(95,105,131)">Cotap Dashboard</h1>
<p style="font-size: 13px; color: rgb(95,105,131)">Please enter a company name (or search term included in the email address of its users, e.g., "Mixpanel" or "mixpanel.com") before selecting events.</p>
</div>
<div id="dateSelect" style="float: right; margin-bottom: 15px"></div>
<form id="company" style="margin-bottom: 15px; height: 31px">
<input type="text" autofocus placeholder="Email address contains" name="company-name-field" value="" style="color: rgb(95,105,131); height: 30px; padding: 0 4px; font-size: 12px; border: 1px solid rgb(201,209,219)">
<input type="submit" name="submit" value="Submit" style="font-weight: bold; color: rgb(95,105,131); font-size: 12px; height: 31px; padding: 0 10px; margin-left: 10px; border: 1px solid rgb(201,209,219); background-color: rgb(242,244,246)">
</form>
<div class="confirmation">
<p class="confirm-text" style="color: rgb(95,105,131); font-size: 15px"></p>
</div>
<div class="event-selects">
<div id="event1" style="margin-bottom: 15px"></div>
<div id="event2" style="margin-bottom: 15px; display: none"></div>
<div id="event3" style="margin-bottom: 15px; display: none"></div>
<div id="event4" style="display: none"></div>
</div>
<div id="intervalSelect" style="float: right"></div>
<div id="typeSelect" style="float: right; margin-right: 15px"></div>
<div style="clear: both;"></div>
<div id="graph"></div>
</div>
<div id="table"></div>
<script>
// populate each dropdown with the project's events and add a date picker
var event1 = $('#event1').MPEventSelect(),
event2 = $('#event2').MPEventSelect(),
event3 = $('#event3').MPEventSelect(),
event4 = $('#event4').MPEventSelect(),
dateSelect = $('#dateSelect').MPDatepicker(),
// add type select (total, unique, average)
options = {
items: [
{label: 'Total', value: 'general'},
{label: 'Unique', value: 'unique'},
{label: 'Average', value: 'average'}
]
},
options2 = {
items: [
{label: 'Hour', value: 'hour'},
{label: 'Day', value: 'day'},
{label: 'Week', value: 'week'},
{label: 'Month', value: 'month'}
]
},
typeSelect = $('#typeSelect').MPSelect(options),
intervalSelect = $('#intervalSelect').MPSelect(options2),
// set options for MP graph and MP table (to be populated later)
eventGraph = $('#graph').MPChart({chartType: 'line', highchartsOptions: {
tooltip: {
backgroundColor: '#fffce7' // Make tooltip background yellow
}
}}),
eventTable = $('#table').MPTable({
showPercentages: true,
firstColHeader: 'Event'
}),
// set global variables for the company by which we will filter
companyName = '',
numPeople = 0;
// set default interval to daily
$('#intervalSelect').val('day');
// record search term when company name is submitted and find # users who match search term
$('#company').submit(function(e) {
e.preventDefault();
companyName = $('#company input:first').val();
// query People profiles to find the number of users who match the search term
MP.api.people({where: "(\"" + companyName + "\" in properties[\"$email\"])"}).done(function(results) {
numPeople = Object.keys(results.values().results).length;
$('.confirm-text')
.html(
"Company: <strong>" + companyName +
"</strong><br># People profiles that match: <strong>" + numPeople + "</strong>")
.css("color", "rgb(95,105,131)");
runQuery();
});
$('#company input:first').val('');
});
// get all event dropdown inputs and run segmentation queries segmented by "$email contains [search term]"
function runQuery() {
// return error if no search term was submitted
if (!companyName) {
$('.confirm-text')
.html("Error: Please enter a company name above. Be sure to change the event below and then go back to your selection to reset.")
.css("color", "red");
// reset event dropdown
$('#event1').MPEventSelect().data()['mixpanel-MPEventSelect'].input.set_label('-- Select an event --');
}
// if search term submitted run function
else {
var data = {},
eventNameCount = 0,
eventNames = [event1, event2, event3, event4];
// count how many events have been selected
$.each(eventNames, function(i, event) {
eventThere = event.MPEventSelect('value');
if (eventThere) {
eventNameCount ++;
}
})
// iterate through each event that has been selected and create segmentation graph and table
$.each(eventNames, function(i, event) {
// obtain event name and date range values from dropdowns
var eventName = event.MPEventSelect('value'),
typeName = typeSelect.MPSelect('value'),
intervalType = intervalSelect.MPSelect('value'),
dateRange = dateSelect.MPDatepicker('value'),
fromDate = dateRange.from,
toDate = dateRange.to;
// set parameters and append segmentation results to data
if (eventName) {
params = {
from: fromDate,
to: toDate,
type: typeName,
unit: intervalType,
// set parameter that looks for the specific company name by which we will filter all events
"where": "(\"" + companyName + "\" in properties[\"$email\"])",
}
MP.api.segment(eventName, params).done(function(results) {
$.extend(data, results.json);
// only create graph and table if it is the last iteration of $.each
if ((eventNames.indexOf(event) + 1) == eventNameCount) {
eventGraph.MPChart('setData', data);
eventTable.MPTable('setData', data);
$('#graph').css('margin-top', '15px');
}
});
}
});
}
};
// set functions to run when dropdowns change
event1.on('change', function(e, eventName) {
runQuery();
event2.show();
});
event2.on('change', function(e, eventName) {
runQuery();
event3.show();
});
event3.on('change', function(e, eventName) {
runQuery();
event4.show().css("margin-bottom", "15px");
});
event4.on('change', function(e, eventName) {
runQuery();
});
dateSelect.on('change', function() {
runQuery();
});
typeSelect.on('change', function() {
runQuery();
});
intervalSelect.on('change', function() {
runQuery();
});
</script>
</body>
</html>