They are only made for pneumatic generally. As these are usually aluminum cylinder, the hydraulic kind use a steel cylinder usually and the sensors I mentioned in PM do not work on these.
Magnet senors do not work on steel.
I have several 2 wire kind with LED indicator.
Often they attache with a jubilee style clamp that can be adjusted for position on the cylinder.The piston carries a magnetic ring on it.
Al.