If you are on the internet, you use Google. If the website you visit has Google AdSense, it will track you. It will associate your ip address with the content of the page you accessed. When you access a similar page, it will remember your intrerests and supply a relevant ad to the new page, even if the two pages have nothing to do with each other. They can do this because they are tracking you. If you have a gmail account, same thing. If you have ever emailed anyone with a gmail account, same thing. If you have an android phone, same thing.
This why the Ghostery Add-On for Firefox is an essential when surfing.