In the US, the detection method is electrical, through the rails. The method is ever-evolving but began around the turn of the 20th century when a battery at the far end of the track sent current down the rails to the signal and was shunted when a train entered the circuit.