Given that I don't seem to be doing the sleep thing right now, I might as well explain a bit more.
There are multiple ways that your day to day passage through the WWW is tracked, that can result in the semi-spooky adverts that you describe, there are two prime methods.
The first, most likely option is one of the ad giants. you visit page A from WeSellStuff.com, and the 3rd party service embedded in the page makes a note of what you are looking at. When you visit site B that also uses that service, the advert space on the page retrieves the data stored on your computer in cookies, looks for an appropriate advertiser on its books for those products and displays it. One of the biggest is doubleclick.net - what a surprise, it's google. As you point out, they will not know that you bought the item, they just know that it is relevant to you which makes the ad more likely to be valuable to the advertiser.
The second, more tricksy method is web beacons, or some variant thereof. If you use Yahoo, then you will have agreed to their use as part of your TOS. This uses clever tech to identify your passage around the net, such as image/script loading that Kim mentions. Yahoo are (or at least, were?) one of the worst offenders in this respect. You can block some of the worst aspects of this behaviour by blocking 3rd party cookies. Facebook tried with the Facebook Beacon, overstepped the mark because it couldn't be blocked and got their wrists slapped a few years back. It is likely that they have some sort of tracking tech in play, but it may be confined to those who use the Facebook API, eg using third party games within FB (but, may not as well).
You can see what cookies are being set by any site if you use something like ublock origin (click on the "Shield" to see any page data), which by default will kill any of the more aggressive tracking and can be modified to reject more if you want. As, indeed, can your browser, just by throwing away all cookies after a session. Want to see just how many cookies you have? In Chrome, go to settings, advanced, privacy and security, content settings, Cookies, See all cookies and site data. Wot a lot there are. Apart from doubleclick, quantxxxx is another AI tracking giant.