Notice: This blog is no longer updated. You may find a broken link or two

You can follow my new adventures @mikeonwine

For publishers one of the must frustrating aspects of dealing with ad-networks is probably the powerless feeling you get when one of your user’s complains about a particularly offensive, annoying or suggestive ad that they just saw. So what can you do? Here’s a quick and easy method to provide a “report this ad” button for your site.
Here’s the normal process of ad call:
– You put a tag on your page, script src=”some.adserver.com/someparameters”>
– Browser requests javascript, and it returns something like — document.write(‘‘);
– User sees some.ad.com/ad.jpg

So how do you create a button to ‘report an ad’? Simple! You simply create a wrapper function around document.write() to capture all the output. Then, all you need to do is a little bit of smart javascript and badabing you’re done! Credits to this page for the document.write JS;.

So how do you wrap document.write()? Rather easily! Check it out this IE specific example:

(function(){
        var documentWrite = document.write ;
        var createWrapper = function(s){
                writeOutput = writeOutput + "\\n\\n" + s;
                return s;
        };

        document.write = function(s){
               documentWrite(createWrapper(s) );
               document.close();
        }
})();

As you can see this is remarkably simple. Every time document.write() is called we simply append the call to a variable ‘writeOutput’, which you can then do whatever you want with. I’ve created a fully functional example that has the full browser compatible javascript. It takes the writeOutput from an RMX Direct tag and puts it in a textarea at the top. You can grab the javascript by just viewing the source. The PHP code for “report_ad.php” is extremely simple:

$adcontent = htmlentities($_POST["adcontent"]);
$report = htmlentities($_POST["addetails"]);

echo "<b>Here is the email you send yourself:</b><br><br>\n";

echo "<b>Subject:</b> Uhoh, someone reported an ad!<br>\n";
echo "<b>User Comments:</b> $report<br><br> Here is what happened on the page when the user saw the ad:<br><br>\n";

Now, it’s important to realize that this isn’t a perfect way to do it. If the advertiser is wrapping content in an IFRAME then this method will simply show you the IFRAME source. Also, I’m not sure this will work for all networks. I’ve tested it with RMX Direct and Fastclick/Valueclick and it seems to work for both. In the document.write() output you can clearly see the source for the flash files being served. In any case, I hope this will be useful to somebody.

Related Posts:



  • http://www.offtheisland.com/ Cam

    Best Hack Day idea Ever!

  • http://www.mikeonads.com/2008/05/02/networks-friend-or-foe/ Mike On Ads » Blog Archive » Networks: Friend or Foe?

    [...] This makes extracting the information much more difficult. But, as I’ve shown before in this post, there are some clever tricks you can do with Javascript already to increase how much data you can [...]