Banner Ads and AdRotator

In the beginning, there wasn't a lot of money floating around on the Web—certainly not as much as there is now! Most users got their access for free through universities and big business had yet to discover it. After the audience began to grow, of course big business began to look for ways to make money. (Many of the original users thought that this was appalling, actually, but it's this infusion of funds that helped drive prices down.) Early on, businesses settled on two main ways of making money: e-commerce and advertising. (The idea of subscription content was so heretical that it's still a tough sell in most industries.) At first the goal of advertising was to make money for those hosting the ads. Back then there weren't the millions of sites there are today. Just having a Web site was enough to distinguish you, in most cases. Today, with so many sites on the Web, it's almost crucial to have some sort of ad campaign going, even if you just join one of the free link exchanges.

We all know that a picture is worth a thousand words, so it should come as no surprise that advertising on the Web didn't take long to start incorporating images. The most common form of Web advertising these days is the banner ad. A banner ad is a more or less standard sized image (usually horizontal) that is also a clickable link to an advertiser's site (see Figure 3.5). At first, this was an effective tactic. Banner ads were new, so they attracted attention, and the click-through rate was good. These days, though with banners saturating the Web, users hardly notice them anymore, and the response rate is dropping. As such, big business has put a lot of time, effort, and money into determining ways to reverse this trend.

Figure 3.5. Banner ads, such as this one for InterGal Inc., are currently one of the most common methods of advertising on the Web.


One thing that came out of the ever-increasing pressure was the realization that the more times a user sees a particular banner, the less likely he or she is to click it. This led to the idea of a rotating banner. Every time users come to a page, they get a different ad. (Usually it's determined randomly from a pool.) Active Server Pages has a component, AdRotator, which enables you to insert banners easily. You can set up an ad and determine the banners that run, whether they are clickable, and how often they run relative to each other.

Using AdRotator

The AdRotator component actually consists of three main pieces in addition to the ads themselves:

  • The actual AdRotator object itself

  • The schedule file

  • The redirection file

The first thing you need to do is gather the ads you're going to use. You'll find them on the CD, under ads in the Chapter 3 directory. Drag the whole folder into your Web server's home directory.

Next, you need to create a schedule file. This is the file that tells the AdRotator where to go and how often to go there. Create a new file called adRotatorSched.txt and save it in the ads directory. Put the text in Listing 3.27 in it. (Make sure you keep the asterisk on the first line.)

Code Listing 3.27. AdRotatorSched.txt: Determining which banners will run and how often
*
/ads/intergal.gif
http://localhost/ads/intergal.asp
Intergal, Inc.:  Get Safe, get insured.
3
/ads/korman.gif
http://localhost/Ads/korman.asp
Korman's Costume Shop:  Our costumes are out of this world
5
/ads/ad3.gif
http://localhost/Ads/intbooks.asp
Interplanetary Books:  Everything from Alpha to Zed
2

The four items in each listing are as follows:

  • The image to be displayed.

  • The URL of the sponsor's site.

  • The ALT text to be included in the ad for people who can't/won't see the image.

  • Relative weights for each ad. In this case, on the average for every 10 times the page is viewed, the first ad comes up 3 times, the second 5 times, and the last one 2 times.

Now you're ready to put the ad on your home page. Normally the banner ad goes at the top of the page, but it's also acceptable to put it on the bottom; so because you have a banner-type graphic at the top, that's what you should do. Open the index.asp file and add the entry in Listing 3.28 to create the AdRotator object and get the HTML for the ad.

Code Listing 3.28. index.asp: Adding a rotating banner
…
27:<A href="mySpace/mySpace.asp">
28:<IMG SRC="images/myspace.gif" BORDER=0 ALIGN="middle" ALT="mySpace" HEIGHT="39" WIDTH="39">
29:mySpace</A> -- carve out your niche
30:<BR>
31:<A href="register.asp">
32:<IMG SRC="images/register.gif" BORDER=0 ALIGN="middle" ALT="Register" HEIGHT="39"
 WIDTH="39">
33:Register</A> -- jump on board
34:<P>
35:<%
36:    set AdvObject = Server.CreateObject("MSWC.AdRotator")
37:    adHTML = AdvObject.GetAdvertisement("ads/AdRotatorSched.txt")
38:    Response.Write adHTML
39:%>
40:
41:</BODY>
42:</HTML>

On line 36 we create the AdRotator object, then on line 37 we get the HTML for an ad to display on line 38.

Save the file and open it in your browser. You can only guess which ad you'll see. If you reload the page, you'll probably see the ad change. Reload a few times and watch the frequency of each ad. You'll notice that the relative frequencies match the schedule file. Click the ad, and you'll be taken to the advertiser's site.

You could leave it like this, but from a business standpoint, you need to do one more thing. If you sell ad space, you need to provide the advertiser with a report of how many times their ad has been clicked. To do this, you need insert a step in this process. Instead of going directly to the advertiser's site, you go to a page of your own, where you can log the action, and then you send the browser on to the advertiser. To do this, you create a redirect file.

But first, tell the AdRotator that you're going to use a redirect file. You put three listings in the schedule file so far. Each one contains information that applies only to that ad. Now you add information that applies to all ads, unless you specifically change it when you call them (see Listing 3.29).

Code Listing 3.29. AdRotatorSched.txt: Setting up for redirection
001 1: REDIRECT http://localhost/ads/goToSponsor.asp
002 2: WIDTH 500
003 3: HEIGHT 72
004 4: BORDER 0
005 5: *
006 6: /ads/intergal.gif
007 7: http://localhost/ads/intergal.asp
008 8: Intergal, Inc.:  Get Safe, get insured.
009 9: 3
010 10:/ads/korman.gif
011 11:http://localhost/Ads/korman.asp
012 12:Korman's Costume Shop:  Our costumes are out of this world
013 13:5
014 14:/ads/ad3.gif
015 15:http://localhost/Ads/intbooks.asp
016 16:Interplanetary Books:  Everything from Alpha to Zed
017 17:2
018 

Lines two and three are fairly obvious; they set the dimensions for the ad. Line 4 tells the AdRotator whether to set a border attribute. It's line 1, though, that's interesting. Save the schedule file and refresh the index.asp file. Click the ad and look at the location bar of your browser. The URL for the ad is now something like http://localhost/goToSponsor.asp?url=http://localhost/ads/intergal.asp&image=/ads/intergal.gif. It's important to take a look at what this means. The first part, http://localhost/goToSponsor.asp is pretty obvious. The rest of it,

?url=http://localhost/ads/intergal.asp&image=/ads/intergal.gif

is called the querystring. You learn more about querystrings in Chapter 4, "Database Access Using ASP," but for now, you need to understand only that this is one way to pass information to an Active Server Page. A series of name-value pairs is listed as part of the URL separated by asterisks.

Create a blank file—not a copy of template.asp—in the ads directory called goToSponsor.asp and add the text shown in Listing 3.30.

Code Listing 3.30. goToSponsor.asp: Redirecting the user to the sponsor's page
0: <%@ LANGUAGE="VBSCRIPT" %>
1: <%
2:     sponsorURL = Request.querystring("url")
3:     Response.Redirect sponsorURL
4: %>

First, understand that Request is an object, just like Response. On the line 2, you ask it to retrieve the value of URL from the querystring and assign that value to the variable sponsorURL. On line 3, you tell the server to send the browser to another page—literally to redirect it. So overall, this page finds out where to send the browser and sends it there.

In real life, you would want to record this information in a log or a database, but for now you just pass it on. The transaction is recorded in your access logs for you to retrieve later.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.198.120