linear encoder, optical?

You will find that in most cases, encoders are either coupled axially to the motor on a through-shaft, or off-axis on the load (through gears, belts, etc). It’s certainly possible to do an edge-encoder (I think some DC turntables used to do this for speed control), but it’s likely to be a DIY effort.