Reducing reused code for /public/js/metrics.js