2013-05-20 23:33:57 +02:00
|
|
|
var metrics = (function () {
|
|
|
|
|
|
|
|
var exports = {people: {}};
|
|
|
|
|
|
|
|
function enable_metrics() {
|
|
|
|
return page_params.domain === "humbughq.com";
|
|
|
|
}
|
|
|
|
|
|
|
|
var methods = ["disable", "track", "track_pageview", "track_links", "track_forms",
|
|
|
|
"register", "register_once", "alias", "unregister", "identify",
|
|
|
|
"name_tag", "set_config"];
|
|
|
|
var people_methods = ["set", "set_once", "increment", "append", "track_charge",
|
|
|
|
"clear_charges", "delete_user"];
|
|
|
|
|
2013-05-22 22:01:15 +02:00
|
|
|
function wrap_method(name, source_container, target_container_func) {
|
2013-05-20 23:33:57 +02:00
|
|
|
source_container[name] = function metrics_wrapper () {
|
|
|
|
if (enable_metrics()) {
|
2013-05-22 22:01:15 +02:00
|
|
|
// We must reference mixpanel indirectly here because
|
|
|
|
// mixpanel loads asynchronously with stub methods and
|
|
|
|
// replaces its methods when it fully loads
|
|
|
|
var target_container = target_container_func();
|
2013-05-20 23:33:57 +02:00
|
|
|
return target_container[name].apply(target_container, arguments);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
$.each(methods, function (idx, method) {
|
2013-05-22 22:01:15 +02:00
|
|
|
wrap_method(method, exports, function () { return mixpanel; });
|
2013-05-20 23:33:57 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$.each(people_methods, function (idx, method) {
|
2013-05-22 22:01:15 +02:00
|
|
|
wrap_method(method, exports.people, function () { return mixpanel.people; });
|
2013-05-20 23:33:57 +02:00
|
|
|
});
|
2013-05-20 23:36:12 +02:00
|
|
|
|
|
|
|
// This should probably move elsewhere
|
|
|
|
$(function () {
|
|
|
|
$(document).on('compose_started.zephyr', function (event) {
|
|
|
|
metrics.track('compose started', {user: page_params.email,
|
|
|
|
realm: page_params.domain,
|
|
|
|
type: event.message_type,
|
2013-05-22 16:33:48 +02:00
|
|
|
trigger: event.trigger},
|
|
|
|
function (arg) {
|
|
|
|
if (arg !== undefined && arg.status !== 1) {
|
|
|
|
blueslip.warn(arg);
|
|
|
|
}
|
|
|
|
});
|
2013-05-20 23:36:12 +02:00
|
|
|
});
|
2013-05-21 19:34:30 +02:00
|
|
|
$(document).on('narrow_activated.zephyr', function (event) {
|
2013-05-22 22:08:42 +02:00
|
|
|
var operators = event.filter.operators();
|
|
|
|
var stream_operands = event.filter.operands('stream');
|
|
|
|
var subject_operands = event.filter.operands('subject');
|
|
|
|
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-05-21 19:34:30 +02:00
|
|
|
metrics.track('narrow activated', {user: page_params.email,
|
|
|
|
realm: page_params.domain,
|
2013-05-22 22:08:42 +02:00
|
|
|
operators: reported_operators,
|
2013-05-22 16:33:48 +02:00
|
|
|
trigger: event.trigger},
|
|
|
|
function (arg) {
|
|
|
|
if (arg !== undefined && arg.status !== 1) {
|
|
|
|
blueslip.warn(arg);
|
|
|
|
}
|
|
|
|
});
|
2013-05-21 19:34:30 +02:00
|
|
|
});
|
2013-05-20 23:36:12 +02:00
|
|
|
});
|
|
|
|
|
2013-05-20 23:33:57 +02:00
|
|
|
return exports;
|
|
|
|
}());
|