

ASP ADVANCED
This chapter explores a
number of additional ActiveX components.
In the first section, you learn how to use the Ad Rotator
component. This component can
be used to display banner advertisements on your Web site.
The second section discusses the Content Rotator component.
This component randomly displays different HTML content on a Web
page. Finally, in the third
section, you learn how to use both the Counter and the Page Counter
components. These two
components can be used for tracking the number of visitors to your Web
site.
The Ad Rotator
Component
Many commercial Web sites
are built on the assumption that they'll make money through banner
advertisements. The
assumption is that a Web site is very much like a magazine or a television
show. Like a TV show, a Web
site with compelling content attracts a population of viewers. Where
viewers go, it's assumed, advertisers will soon follow with advertising
dollars.
So far, however, this
strategy hasn't worked for most Web sites.
The problem is that very few corporations are paying for
advertisements on the Internet. Even
worse, the few corporations willing to advertise on the Internet tend to
advertise only on the same select group of Web sites.
Netscape and the Internet search engines such as Yahoo!, Infoseek,
and Excite tend to draw all the advertising money.
This leaves very few advertising dollars for the little guys.
Nevertheless, selling
banner advertisements is the primary way of making money on the Internet.
Unless you plan to generate revenue directly from your Web site's
visitors--an even riskier proposition--you'll need to use banner
advertisements. In this
section, you learn how to incorporate banner advertisements into your Web
pages.
Using the Ad Rotator
Component
Using the Ad Rotator
component, you can create a Web page that displays a different banner
advertisement every time it's viewed.
You can assign advertisements different weights so that they're
displayed at different frequencies. You
can also record the number of times an advertisement has been clicked to
determine the advertisement's click-through rate.
The Ad Rotator
component has a single method. The
GetAdvertisement( ) method is used to
retrieve information about a banner
advertisement. Here's an
example of how it's used:
<HTML>
<HEAD><TITLE> Home Page </TITLE></HEAD>
<BODY>
<CENTER><H1>Welcome to our web site!</H1></CENTER>
<HR>
<%
Set MyAd=Server.CreateObject("MSWC.AdRotator")
%>
<CENTER><%= MyAd.GetAdvertisement("adrot.txt")
%></CENTER>
</BODY>
<HTML>
This Active Server Page
displays a banner advertisement at the bottom of the page. Here, the
script creates an instance of the Ad Rotator component by using the
Server.CreateObject( ) method. Next,
the banner advertisement is actually displayed by calling the
GetAdvertisement( ) method.
Notice that the GetAdvertisement( ) method takes
a parameter. This parameter specifies a file that
contains the information about the advertisements to be displayed. In this
example, the name of this is adrot.txt. You learn how to create this file
in the next section.
The Rotator Schedule
File
Before you can use
the Ad Rotator component, you need
to create a special file called the Rotator
Schedule file. The Rotator Schedule file
contains all the information about the banner advertisements. It's
a normal text file that you can
create and edit with any text editor.
The
Rotator Schedule file has two sections.
In the first section, you provide general information about all the
advertisements you want to display. In
the second section, you specify the information for each advertisement.
Listing below shows an example of this file.
Listing
The adrot.txt file.
REDIRECT /adredir.asp
WIDTH 200
HEIGHT 30
BORDER 0
*
bannerad.gif
http://www.aspsite.com
The Active Server Pages Site
80
http://www.collegescape.com/gifs/csad.gif
http://www.collegescape.com
Collegescape
20
The two sections of
information in this file are divided by an asterisk( * ). The first
section contains four parameters that affect all the advertisements in the
file. Here's an
explanation of what these parameters do:
- REDIRECT. Specifies
a redirection file for the advertisements. When a banner advertisement
is clicked, the user is redirected to this file.
- WIDTH. The
width of the banner advertisement image, specified in pixels. Is you
omit this parameter, the value of this parameter defaults to 440
pixels.
- HEIGHT.
The height of the banner advertisement image, specified in
pixels. If you omit this
parameter, the value of this parameter defaults to 60 pixels.
- BORDER.
The size of the border around the banner advertisement
image. By default, the
advertisement has a border that's one pixel thick.
In the adrot.txt file shown
in Listing above, the REDIRECT parameter points to the Active Server Page
named adredir.asp. The WIDTH
and HEIGHT parameters specify that the width of the banner advertisement
image should be 200 pixels and the height should be 30 pixels.
Finally, the BORDER parameter is set to 0, which results in no
border being displayed.
The second section contains
information specific to each advertisement.
Here, the Rotator Schedule file contains information on two
advertisements. The first
banner advertisement is for the Active Server Pages site.
The second advertisement is for a Web site named Collegescape.
For each advertisement, you
provide four lines of information. The
first line gives the path to the image for the advertisement.
This image may be located on the local computer or anywhere else on
the Internet.
The second line contains
the URL for the advertiser's home page, When users click an advertisement,
they can be redirected to this page (see the next section).
If you place a hyphen (-) on this line, the advertisement won't
function as a hyperlink.
The third line indicates
alternative text to display when a browser doesn't support graphics. It's
equivalent to the ALT attribute of the HTML <IMAGE> tag.
You can place any non-HTML text here that you want.
Finally, the fourth line
specifies how often a particular advertisement should be shown.
It indicates the relative weight to be given to the
advertisement. In the
example, the first advertisement will be displayed 80% of the time, and
the second advertisement will be displayed 20% of the time.
The Redirection File
You can specifv a Redirection
file that applies to all the advertisements in a particular Rotator
Schedule file. When users
click a banner advertisement, they're brought to this file.
This file can be an Active Server Pages file.
The main function of this
file is to record the number of times a particular banner advertisement
has been clicked. Once this
information is recorded, the user is typically redirected to the
advertiser's home page. Listing
below shows an example.
Listing The
adredir.asp file.
<%
Response.AppendToLog
Request.QueryString("url")
Response.Redirect Request.QueryString("url")
%>
This Redirection file
contains a two-line Active Server Pages script.
The first line records information about which advertisement has
been clicked in the server log. Next,
the script uses the Redirect method to send the user to the advertiser's
home page.
Whenever the Redirection
file is called, two query strings are passed.
The url query string contains the path to the advertiser's home
page. This is the same path
that you entered as the path for the advertiser's home page in the Rotator
Schedule file.
The second query string is
named image. The image query
string contains the path of the banner image.
The value of this query string indicates the path you entered for
the banner image in the Rotator Schedule file.
You actually can
place anything you want in the Redirection file.
For example, you could make the Redirection file a normal HTML file
that displays your Web site's advertisement rates.
Here's
an example (see figure below):--
<HTML>
<HEAD><TITLE> Ad Rates </TITLE></HEAD>
<BODY>
<H1> Advertisement Rates </H1>
To advertise at this Web site, please contact
<A HREF="mailto:admaster@mysite.com"> Ad Info </A>.
<P>
By advertising at this Web site, you will reach thousands of developers a
day.
We offer a number of advertising packages:
<OL>
<LI>The Gold Package: $30 CPM
<LI>The silver Package: $20 CPM
<LI>The Bronze Package: $10 CPM
</OL>
</BODY>
</HTML>
Advertisement
Information
Ad
Rotator Properties
The
Ad Rotator component has three properties.
Before calling the GetAdvertisment( ) method, you can set these
properties to control how an
advertisement is displayed. The
following list explains each property:
-
Border.
This property overrides the BORDER parameter specified in
the Rotator Schedule file. You
can use this property to indicate the size of a banner advertisement's
border (in pixels) for a particular page.
-
Clickable.
This property specifies whether the banner advertisement
should function as a hyperlink. It
can have the value True
or False.
-
TargetFrame.
This property indicates the name of the frame into which
the banner link should be loaded.
The
TargetFrame property is particularly useful.
If you set the TargetFrame property to the name of a new frame,
when a user clicks
a
banner advertisement the advertiser's home page loads into the frame. By
doing this, you prevent the user from permanently leaving your Web site.
Here's an example of how this property is used:--
<HTML>
<HEAD><TITLE> Home Page </TITLE></HEAD>
<BODY>
<CENTER><H1>Welcome to our web site!</H1></CENTER>
<HR>
<%
Set MyAd=Server.CreateObject("MSWC.AdRotator")
MyAd.TargetFrame("AdFrame")
%>
<CENTER><%= MyAd.GetAdvertisement("adrot.txt")
%></CENTER>
</BODY>
</HTML>
|