As far as I'm aware, they use a similar technique.
Say site A is the site to be advertised and site B is the site which advertises site A. The code put on site A is usually a small blank image or a script file. The image/script file is located on server A (or an intermediate, e.g. an advertising company's server). The loading of this file does two things. First, and most obviously, it can give information to the browser or user, by serving content. Secondly, and most importantly, the web request to the server fires some server-side magic on server A.
E.g. the browser on B loads a request from server A. The request on server A fires code which can give information to A's databases, gathered from the headers sent to the server by the browser during the request.
About 6 years back I started up a website which I updated daily with notes from science/maths lessons in school, with my own twist and some examples it became an added resource for people doing similar courses. I advertised on a local science forum with a small banner ad, which in fact linked to a PHP file. Every time the image loaded, I updated a text file with an incremented value. Every time the link was clicked, it ran a script which then updated a different file with an incremented value. When users left that page, another file was incremented. Pretty basic, but I figured this was a good way of keeping an eye on the statistics given to me by the forum admin when it came to paying for it.
It seemed like good value. A week or so later, I became suspicious when I found that I had a LOT of hits (considering the forum size and the simple content) to the page in the ad, but NONE of which went on to click for further information. When I updated my process to record as much info as possible on every page load and every click, and I found that most of the requests were from the same IP address, at highly regular intervals. The server admin had a bot running which faked an ad-click every 5 minutes. The requests to my server for the ad image were also faked. Turns out the advert only showed up on the forum when I was logged in, no other user even saw it.
Statistics are your friend.