The most common way is through the “Nielsen families”. These are families distributed across the US which report what they watch. They then extrapolate. TV studios do their own testing as well. Finally, DVRs collect lots of data as well (anonymously).