I did a quick search on "third party cookies". As far as I know, a cookie can only be sent back to it's own domain (and path) by the browser via the HTTP request.
For example, I'm visiting the website A who contains an image from an advertising website B. My browser sees the url of the image and makes a HTTP request for that image to the website B. The website B get that HTTP request and set cookies in the HTTP response "Set-Cookie: user=arandomstring". There my browser now contains cookies from the website A and a cookie named "user" from the website B. The next time when I go to another website C who also contains an image from the same advertising website B, the website B would only get the "user" cookie set by himself. am I right? How can website B knows which websites (website A) have I visited in order to display his customized adverts?