Ads are super complex these days, unless you have the ability to do like Daring Fireball and some others and accept only ads you manually curate.
My friend worked in the industry. It's a whole thing. Front-end javascript to do all manner of tracking and fingerprinting and ad insertion; then that info gets rolled up and send to a third-party back-end that packages it all up, and presents it for automated real-time ad bidding to literally thousands of other third-parties, who figure out how much that impression might be worth to their ad clients based on the data and what the clients are trying to sell, everyone does the math and puts in a bid, the highest paying ad is chosen to send back to the end user, the ad buyer is billed, etc, across many hops and interfaces, and it all has to in theory happen within a second or so. There's so many parties, and some of them inject very poorly behaved ads very much on purpose, and each entity along the way might want to prevent this so they have to get reports that it is happening, then add code to filter out poorly behaved ads (lest whoever pays them drops them for allowing it through their system), then the vendors of poorly behaved ads write new code ... it's a never-ending game of cat and mouse with literally thousands of companies involved in the exchanges.
(And yet when I complain that some sites don't work without javascript, whereas in 2005 devs would say "A good site has to work without JS or allow a non-JS option for a simpler/cruder user interface, I test both with and without" today all the young'uns say "javascript is an integral part of the browser experience and we shouldn't cater to people living in the stone ages." Thanks, for loading ten megabytes of crap to view ten kilobytes of text, and tracking me everywhere.)
My friend worked in the industry. It's a whole thing. Front-end javascript to do all manner of tracking and fingerprinting and ad insertion; then that info gets rolled up and send to a third-party back-end that packages it all up, and presents it for automated real-time ad bidding to literally thousands of other third-parties, who figure out how much that impression might be worth to their ad clients based on the data and what the clients are trying to sell, everyone does the math and puts in a bid, the highest paying ad is chosen to send back to the end user, the ad buyer is billed, etc, across many hops and interfaces, and it all has to in theory happen within a second or so. There's so many parties, and some of them inject very poorly behaved ads very much on purpose, and each entity along the way might want to prevent this so they have to get reports that it is happening, then add code to filter out poorly behaved ads (lest whoever pays them drops them for allowing it through their system), then the vendors of poorly behaved ads write new code ... it's a never-ending game of cat and mouse with literally thousands of companies involved in the exchanges.
(And yet when I complain that some sites don't work without javascript, whereas in 2005 devs would say "A good site has to work without JS or allow a non-JS option for a simpler/cruder user interface, I test both with and without" today all the young'uns say "javascript is an integral part of the browser experience and we shouldn't cater to people living in the stone ages." Thanks, for loading ten megabytes of crap to view ten kilobytes of text, and tracking me everywhere.)