2013-05-20 23:33:57 +02:00
|
|
|
var metrics = (function () {
|
|
|
|
|
2013-05-22 22:51:28 +02:00
|
|
|
var exports = {};
|
2013-05-20 23:33:57 +02:00
|
|
|
|
|
|
|
function enable_metrics() {
|
2013-06-14 23:53:22 +02:00
|
|
|
return page_params.enable_metrics;
|
2013-05-20 23:33:57 +02:00
|
|
|
}
|
|
|
|
|
2013-05-22 22:51:28 +02:00
|
|
|
if (! enable_metrics()) {
|
|
|
|
mixpanel.disable();
|
2013-05-20 23:33:57 +02:00
|
|
|
}
|
|
|
|
|
2013-06-14 20:53:35 +02:00
|
|
|
function include_in_sample() {
|
|
|
|
// Send a random sample of events that we generate
|
|
|
|
return Math.random() < 0.1;
|
|
|
|
}
|
|
|
|
|
2013-06-14 21:53:30 +02:00
|
|
|
function send_resize_event() {
|
|
|
|
mixpanel.track('window resized', {height: $(window).height(),
|
|
|
|
width: $(window).width()});
|
|
|
|
}
|
|
|
|
|
|
|
|
mixpanel.register({user: page_params.email, realm: page_params.domain});
|
|
|
|
send_resize_event();
|
|
|
|
|
2013-05-20 23:36:12 +02:00
|
|
|
$(function () {
|
|
|
|
$(document).on('compose_started.zephyr', function (event) {
|
2013-06-14 20:53:35 +02:00
|
|
|
if (! include_in_sample()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-14 21:50:15 +02:00
|
|
|
mixpanel.track('compose started', {type: event.message_type,
|
2013-06-14 23:16:15 +02:00
|
|
|
trigger: event.trigger});
|
2013-05-20 23:36:12 +02:00
|
|
|
});
|
2013-05-21 19:34:30 +02:00
|
|
|
$(document).on('narrow_activated.zephyr', function (event) {
|
2013-06-14 20:53:35 +02:00
|
|
|
if (! include_in_sample()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-22 22:08:42 +02:00
|
|
|
var operators = event.filter.operators();
|
|
|
|
var stream_operands = event.filter.operands('stream');
|
2013-07-16 22:52:02 +02:00
|
|
|
var subject_operands = event.filter.operands('topic');
|
2013-05-22 22:08:42 +02:00
|
|
|
var reported_operators;
|
|
|
|
if (operators.length === 1) {
|
|
|
|
reported_operators = operators[0][0];
|
|
|
|
} else if (operators.length === 2
|
|
|
|
&& stream_operands.length !== 0 && subject_operands.length !== 0) {
|
|
|
|
reported_operators = 'stream and subject';
|
|
|
|
} else {
|
|
|
|
reported_operators = 'multiple';
|
|
|
|
}
|
|
|
|
|
2013-06-14 21:50:15 +02:00
|
|
|
mixpanel.track('narrow activated', {operators: reported_operators,
|
2013-06-14 23:16:15 +02:00
|
|
|
trigger: event.trigger});
|
2013-05-21 19:34:30 +02:00
|
|
|
});
|
2013-06-14 21:53:30 +02:00
|
|
|
|
|
|
|
$(window).on('resize', $.debounce(3000, send_resize_event));
|
2013-05-20 23:36:12 +02:00
|
|
|
});
|
|
|
|
|
2013-05-20 23:33:57 +02:00
|
|
|
return exports;
|
2013-05-22 22:51:28 +02:00
|
|
|
}());
|