The way that the ad network supplies the ad is for publishers to include a short snippet like this:
document.write("Click on this ad!");
Nice and simple to drop in to HTML, but our results page is built dynamically from an AJAX call that fetches JSON. At first I thought I could just built a new script tag and append it to the div I wanted, but that resulted in a blank page with just the ad in the DOM. I’m assuming that without an enclosing context that the document.write is overwriting the root html node.
Instead what worked was to temporarily override document.write just before the ad is loaded and write the content of the ad into the DOM where I wanted. This works, but feels a bit evil. I’d be interested in finding a prettier solution than this.