Add a wrapper to mixpanel so that we can selectively enable metrics collection

(imported from commit 1d72f2e98c4c756a8a988d08731282e4195b8e1a)
This commit is contained in:
Zev Benjamin
2013-05-20 17:33:57 -04:00
parent 22e2eb3305
commit a4bda36ab4
3 changed files with 33 additions and 1 deletions

View File

@@ -308,6 +308,7 @@ PIPELINE_JS = {
'js/templates.js',
'js/settings.js',
'js/tab_bar.js',
'js/metrics.js'
],
'output_filename': 'min/app.js'
},

View File

@@ -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'

View 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;
}());