Here's the thing. You agree to let those companies do that. They provide you with a service, and in exchange they collect data about you. That's the trade you're making. Without that data, they can't make any money as they rely heavily on advertising.