Refactor click tracking queries