One of my two Apple Magic Mice started only tracking well on harder/shinier surfaces. Cleaning the sensor didn’t help.
The iFixit forums suggest “a nice 4 foot drop onto concrete”. I tried 1 m drops onto a rug, and bizarrely after about five drops that completely fixed the problem.