all posts

Building an Ad Management System - Step 1

Published to Blog on 9 Mar 2007

No, I’m not starting another project and I’m not starting another blog series. First I had a problem/question/idea, then I did a little research, and now I’m just doing a little prototyping to see what’s feasible.

I would like to use ads from other networks in addition to Adsense on my site. I wondered what it would take to build something for my sites that would rotate ads from various ad networks rather than have to put in more ad placements to serve that purpose.

Following are my requirements starting with the most important (for now). These requirements could easily be delivered in stages:

  1. A wrapper for ads that would work for multiple networks/affiliates that would encapsulate the implementation details of each of them allowing me to drop in one piece of code (whether it be code, a control, html or javascript) to display those ads. It would provide properties to allow me to define which ad network to use, the size of the ad, etc.
  2. Some sort of local configuration that would allow rotation of ads from specified networks/affiliates. This could be via an XML config file or some local data store and build upon step 1.
  3. A centralized management and configuration utility allowing me to setup ads and define which ones are displayed where. This would involve setting up some kind of ad server and should still be as easy to use on the client side as step 1. Ideally this would build upon the first two steps.
  4. Ideally the entire system would be flexible enough to allow me to use it in any of the 3 above ways that I choose. This would be especially good for failover in case the server portion was down, overwhelmed, or otherwise not responsive.

In a comment to my initial post Leo Nelson said BanManPro was the only good .NET ad management solution that he had found in his research, but he pointed me to a PHP solution called OpenAds. I looked into OpenAds, read the history, downloaded the code (it is GPL) and poked around a bit. It has some nice features and the newer branch v2.3 (AKA Max Media Manager) looks very promising.

Additionally, I found a “simple” PHP Ad Rotator on the Idealog. The author’s desires sound similar to my own. 

Based on what I’ve seen so far I believe that I have 4 options:

  1. Use the OpenAds system - PHP and MySQL will run on Windows!
  2. Port the OpenAds system to .NET - sounds fun but I don’t have time to captain an open source project at the moment.
  3. Build my own system - using ASP.NET of course. This would allow me to implement in stages and devote time to the project when it is available.
  4. Say “To heck with it” and just manually add the different ad code to my sites. But what fun is there in that?

For now my decision is to table the decision. I may look into OpenAds further if I decide I need something sooner rather than later. But as part of process leading to that decision I developed a spike to determine the feasibility of building my own .NET system. And after all that introduction we’re finally getting to what this post was supposed to be about: a description of that development spike.

I felt that the most important thing to prototype was the actual rendering of the ads, the main point of the system. Along with the rendering I needed to see if I could render ads from different networks/affiliates using a single simplified interface. To do this I chose to build an ad rendering engine that makes use of a provider model to hand off the rendering details to the provider for each specific ad network. The providers each implement IAdProvider and only really have one public method: Render().

Fundamentally the engine itself is simple, it takes a set of parameters (Ad Network, Text or Image or Both, Width, Height, Background Color, Border Color, etc), based on the network type it instantiates the proper provider for it, and then tells the provider to Render.

The difficulties, well actually a better term would be “details”, are in implementing the provider for each ad network. For now I have chosen to build two, one for Google and one for Amazon. If you’ve ever implemented Adsense you know what the javascript that you have to use looks like - the Amazon javascript is very similar. All these providers do is translate the defined properties to the proper javascript and write it to the screen. From past experience I know that other ad networks use images, iframes, and other things beside javascript. The providers for each of them would instead build out the code for that image, iframe, or whatever was necessary.

Below are two screenshots, one showing Google Adsense ads being rendered and the other showing Amazon ads:

In the pics you can see that I have written out part of the javascript, the src attribute, that is needed to define the properties for the ad. The only difference between the two sets is the AdNetwork property, GoogleAdsense in one and Amazon in the other, and some color options for prettiness sake. Requirement #1 from above has been achieved - encapsulation. Additionally, basically using the same code, I have created four different delivery mechanisms - allowing the use of an API so you could create the ads in your .NET code, a server control that you can drop onto a page, the use of a javascript tag, or the use of an IFrame tag. Figuring out the javascript implementation was tough, but I was able to do so with the help of the code provided on Idealog.

However, all that I’ve really done is create a wrapper for the javascript that Google and Amazon use so I haven’t gone beyond my requirement #1 above. Is what I have completed so far useful? Somewhat, but most importantly it is a baby step in the right direction. I implemented a spike and proved to myself that I could render ads from various networks through one simplified interface.

Ah, which brings me to the simplified interface. Because I’m choosing to deliver ads from multiple vendors I’m only implementing a subset of what each one is capable - the least common denominator. At this point I have only looked at two vendors so I haven’t had to pare down each one’s offerings too badly. But I imagine that as support is added for more vendors the options might have to be whittled down further. Luckily it seems that there is a set of standard ad sizes and that will end up being what this system is capable of - the standard ads (large banner ads, small banner ads, skyscrapers, 250x250 squares, etc). There are a lot of cool ad options that Amazon will do, though, that just won’t fit into this. One alternative is to choose a larger set and have the providers notify which ones they will support (and/or choke on the ones they do not!). Another alternative is to keep the smaller set of standardized ads but to allow for custom ads to be defined on a one-off basis. Eventually a decision would have to be made on which way to go with that.

That’s where this exercise probably ends. At some point I may decide to go through with my requirement #2, building a local configuration system that will handle the rotation of ads, but I doubt that I’ll build an all-out ad server system (at least no time in the near future). If nothing else, I learned quite a bit more about ad networks and their ads and came up with a long, in not comprehensive, list of some different ad/affiliate networks that should continue to serve as a good resource. Hopefully my sharing has allowed you to learn something as well. If you have any questions feel free to comment or email me and I’ll do my best to answer them.


Dan Hounshell
Web geek, nerd, amateur maker. Likes: apis, node, motorcycles, sports, chickens, watches, food, Nashville, Savannah, Cincinnati and family.
Dan Hounshell on Twitter