index.js refactoring for google analytics event tracking