Not all states track a party affiliation (mine doesn't), but most of those that do do it to track voting in primaries.
On the other hand, IIRC my history, before maybe the 1970s the U.S. parties did use more private processes, selecting candidates in the 'smoke-filled room' (the image is of fat old men smoking cigars and making deals). Some say the quality of candidate was better then.