I use 3x12mm rare earth magnets (eBay, Amazon, craft stores, etc.) for cadence, but of course it won't be attracted to titanium pedal spindles like I have of some of my bikes. For those I place it on the end of the spindle which is slightly recessed in the crank arm and hold it in place with a piece of electrical or gorilla tape. For those where it does stick to the spindle, I put a piece of electrical tape down first, which makes it much simpler to remove when removing the pedals for transport or shipping.
Also, it's straightforward to stick it inside of the crank arm with some strong all-weather double stick tape or some rtv silicone adhesive if that's a more appropriate setup for your situation.