Having done this in the past (long ago), you put two magnets (same weight and type) on opposing sides of the driveshaft. Use reference to the UJoint to determine equidistants. Double stick tape on the backside to keep the magnets from slipping sideways (not to keep them attached to the shaft!). Then, use stainless wire to wrap over the magnets to affix to them to the shaft. There will be LOTS of force on these magnets so do a good job and keep things weight balanced (including number of turns in the tie wrap). The shape of the magnet (square with idents for the wire) makes a difference (don't use round).
The magnets get mounted as close to the U Joint towards the transmission since that is the side that has the least lateral movement with suspension travel. You also mount the hall effect transducer on a horizontal plane with the driveshaft to account for up / down of the suspension. Figure in the suspension travel 1/2 way (vehicle weighted down) when affixing the transducer location. For most transducers, mount with a 1/8 inch air gap.
You use software to calibrate the number of pulses = 1 mile with a transform formula. Transmission ratios are before the driveshaft so no affect on driveshaft speed / road speed calculations. Air pressure in tires has more affect, but only a smaller percentage. Measure the road surface to the axle midpoint which is the radius of the circle and then calculate the circumferance of the circle divided by rear axle gear ratio divided by two (number of magnets) should get you close to the transform number.
Another more modern way is that most all vehicles use a "speed sensor" which is mounted on the transmission. Some are mechanical reed switches that click off output shaft rotation (driveshaft). Some are hall effect sensors which monitor a pulse wheel in the transmission. These can be tapped into electrically for their signal return. But, keep in mind that these circuits are usually monitored for health by the transmission controller and can throw a diagnostic code and light if they don't see the voltage that the controller expects under the circumstances that it is being monitored. So, use a optical or other semiconductor sniff of the voltage state to not induced any resistance or voltage.
"OBD2" is a better idea, unfortunately "OBD2" specification does not include odometer. Each OEM stores, presents, calculates Odometer in a unique way. There are also multple storage places in multiple control modules for the odometer. So, you need a scan tool that goes beyond OBD2 and into "Enhanced Data" which is OEM specific.
And as a tease, a solution for this problem is in the works