Most of the analytics tools these days provide some form of demographics data; be it age, interest area etc. Have you ever wondered how these platforms get the details (even if it is ballpark)?
Pixels, Cookies, Cookie Pool
Often, two methods are used to identify these details – first one, a direct lookup built based on cookie pools (for example DoubleClick cookie pool in the case of Google Analytics) and the second one being a probabilistic method (based on your IPs or extrapolating online behavior.
The next obvious question would be; even then, how some of these tools are able to pinpoint to a specific demographics bracket (say age of 20 – 25). Vendors get these information shared from websites that participate in advertising. For Google, some information from Google Plus is also picked up. You can get an idea of what details of yours may be tracked by Google
It is also a key thing to keep in mind that, most of these info is shared at an aggregate level based on a sample (which could be even close to the entire population captured). So these information should be taken with a pinch of salt and as a directional guidance. For example, have a look at the Oracle Bluekai Registry that gives you the details of groups under which they have put you. You might be surprised to see yourself in some of the bizarre groupings. This is due to the inherent limitation of inference models used.