Refactor analytics and only use in production