When Nielsen first started collecting data (1950s), they handed out diaries to a group of around 5 000 selected households. Nielsen would then collect these diaries and extrapolate viewing patterns across the entire population.
After that came phone surveys. Next step (1980s) was the "people meter", a small box attached to the TV that could automatically detect which channel was tuned and which household members were in the room.
In the 1990s the set-top box made all of that redundant as the cable and satellite providers could directly see which channel every single box was tuned to at all times.