Refactor the analytics plugin.