Move click tracking code so it doesn't need a loop. Closes #3058