Discourse is a Single Page Application and all the page markup is create client-side via our EmberJS application.
Using direct DOM manipulation like document.write
is in direct conflict with the whole thing and has a really low change of “just working”.
I’d recommend trying to adapt you ads system to use our House Ads in the official Ad Plugin system. Maybe you can have a single ad in the house ads inventory, and use the page change hook to contact the ad server and replace the ad with the response? Or maybe your ad system can write to the House Ads inventory directly via API?