mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
Add a wrapper to mixpanel so that we can selectively enable metrics collection
(imported from commit 1d72f2e98c4c756a8a988d08731282e4195b8e1a)
This commit is contained in:
@@ -308,6 +308,7 @@ PIPELINE_JS = {
|
||||
'js/templates.js',
|
||||
'js/settings.js',
|
||||
'js/tab_bar.js',
|
||||
'js/metrics.js'
|
||||
],
|
||||
'output_filename': 'min/app.js'
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Global variables, categorized by place of definition.
|
||||
var globals =
|
||||
// Third-party libraries
|
||||
' $ jQuery Spinner Handlebars XDate zxcvbn Intl'
|
||||
' $ jQuery Spinner Handlebars XDate zxcvbn Intl mixpanel'
|
||||
|
||||
// index.html
|
||||
+ ' page_params'
|
||||
|
||||
31
zephyr/static/js/metrics.js
Normal file
31
zephyr/static/js/metrics.js
Normal file
@@ -0,0 +1,31 @@
|
||||
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"];
|
||||
|
||||
function wrap_method(name, source_container, target_container) {
|
||||
source_container[name] = function metrics_wrapper () {
|
||||
if (enable_metrics()) {
|
||||
return target_container[name].apply(target_container, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
$.each(methods, function (idx, method) {
|
||||
wrap_method(method, exports, mixpanel);
|
||||
});
|
||||
|
||||
$.each(people_methods, function (idx, method) {
|
||||
wrap_method(method, exports.people, mixpanel.people);
|
||||
});
|
||||
return exports;
|
||||
}());
|
||||
Reference in New Issue
Block a user