So, you want to create a banner rotation system for your website, eh? Well, you have a number of options on how to do it. If you do not need to keep track of how many times the banners are displayed, and how often they are clicked, then the simplest approach is to use Microsoft's Ad Rotator, a component that comes free with ASP! There is a great article already on 4Guys that explains how to use the Ad Rotator. So, if this solution fits for you, by all means, read the Ad Rotator article!
If you want to keep track of the number of times the banners are displayed, and how often they are clicked, you will need to take a somewhat different approach. There are really two ways to do this: use text files to keep track of your impressions and click throughs, or use a database. For this article, I am going to discuss using text files. There is an article on 4Guys which discusses displaying advertisements using a database. That article, by Bart Silverstein, is called Automatically Configured Advertisement Display.
To keep track of all of our banners, we will create a text file named
This text file will have the following format:
Each record will be separated by an asterik (*) on its own line. So, if we had three
BANNERS.TXT just might look like this:
This is the banner for 4GuysFromRolla.com
This is the banner for ASPMessageBoard.com
This is a banner advertising Yahoo!
Notice that between each record there is an asterik (*). This is important. Also note
that each banner has a unique
BannerID (the first number in each record).
The second number is the
AdvertiserID. When an advertiser goes to view his
banner stats, he will see a report for all of the banners that have his advertiser ID.
The third number is the weight. This is how often each banner will appear. An easy way
to calculate the percentage of times a given banner will appear is to divide the weight by
the sum of the banner weights. So, the first banner has a weight of 20, and will show
20 / (20 + 30 + 50) = 0.20, or 20% of the time. (If you make sure that all of
the weights add up to 100, then the weight for a given banner is also the exact percentage
of times it will show.)
There are three files you'll need to add to your website to get this working. One is
banner.asp. You'll need to include this file into all the pages that you
want to display a banner on. (If you're unfamiliar with how to include files in ASP, be sure
to check out this article.) In the file,
to display a banner at a given location, just insert this single ASP line of code:
<% ShowBanner %>
That's all there is to it!
You'll have to make some minor modifications to
Namely, you'll have to change some of the constants there to make it a better fit on your
Also, you'll need to add the subdirectories to whatever directory you put your
banner scripts in. These two directories must be named
clickthrus. They will keep track of each banners impressions and
Banner.asp, as well as the other two ASP files, are available for download
at the bottom of this article.)
You may want to read a couple of articles before delving into
I highly recommend you have a firm grasp on the FileSystemObject
and on using split and join. If you don't know what
FSO or split and join are, then please read these two articles first!! Thanks!
The next file you'll need is named
adredir.asp, and it is the file that is
called when someone clicks on a banner. This file is responsible for two tasks: first, it
needs to update the click through stats, and second it needs to send the user to the
The last file is
report.asp. This file will display a report for a given
AdvertiserID. I recommend that you have a unique ASP page for each advertiser's report.
So, let's say we had Yahoo! as an advertiser. I might make their stats page available at
YahooReport.asp, I would
need to first include
report.asp, and then, wherever I wanted to report
displayed, would need to add the line:
<% PrintReport 5 %>
(assuming Yahoo's advertiser ID was 5). That's all there is to it! I hope you find this helpful! Remember, some of the topics covered in the included .ASP files are rather advanced, so you may need to read some primer articles first!
After looking through the
banner.asp file, you may wonder why I have a
CategoryID. Well, this isn't used at all in the implementation here, but
one could easily implement a system using the
CategoryID where certain banners
only appear in certain sections of the site. For example, if your site dealt with ASP
information and Humor, and you wanted Humor banners to appear in the humor section and
ASP banners to appear in the ASP section, you could do so by specifying a category when
ShowBanner. Right now, though, that's not supported, but I encourage you
to add this functionality! :)