Rotary encoders

Hi,
I was wondering if it is possible to add a rotary encoder (compatible with AP) to this type of inexpensive motors.


I will use those motors for a 4WD rover and I thought about using an optical wheel encoder but the accuracy is quite limited.

Yes, you can buy many with hall effect quadrature encoders.
https://www.robotshop.com/en/catalogsearch/result/?q=encoder&order=relevance&dir=desc

You will need a motor where the axle protudes from the back. If the endcap is closed, you can not fix the magnets there. If you fix an encoder to the wheels, you will only get the resolution that the given encoder provides (not the added resolution through the gearing) and you will face problems with dirt and mechanical sturdiness.