From 94daecd039f14889fc970e741a2b919ad069debc Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Fri, 14 Jun 2013 14:53:35 -0400 Subject: [PATCH] Send only 10% of the events we generate to mixpanel (imported from commit f5b1b68f81346a90998a8ab6e789151b0e55dba1) --- zephyr/static/js/metrics.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/zephyr/static/js/metrics.js b/zephyr/static/js/metrics.js index 348bd1c066..805b9e618a 100644 --- a/zephyr/static/js/metrics.js +++ b/zephyr/static/js/metrics.js @@ -10,8 +10,17 @@ if (! enable_metrics()) { mixpanel.disable(); } +function include_in_sample() { + // Send a random sample of events that we generate + return Math.random() < 0.1; +} + $(function () { $(document).on('compose_started.zephyr', function (event) { + if (! include_in_sample()) { + return; + } + mixpanel.track('compose started', {user: page_params.email, realm: page_params.domain, type: event.message_type, @@ -23,6 +32,10 @@ $(function () { }); }); $(document).on('narrow_activated.zephyr', function (event) { + if (! include_in_sample()) { + return; + } + var operators = event.filter.operators(); var stream_operands = event.filter.operands('stream'); var subject_operands = event.filter.operands('subject');