port analytics.js into project. closes #768