Scripting & Web Development Support

ASP
&
VB


 

Rotating Adverts on a Webpage

CGI/Perl
ASP and VB
Java (JSP)
PHP
Ad Rotator

Description from: http://www.chilisoft.com/caspdoc/

 The Ad Rotator behaves identically to the Content Rotator, except that it can also keep track of clicks.

The Ad Rotator component creates an Ad Rotator object that automates the rotation of advertisement images on a Webpage. Each time a user opens or reloads the Webpage, the Ad Rotator component displays a new advertisement based on the information you specify in a Rotator Schedule File.
 
You can record how many users click each advertisement by setting the URL parameter in the Rotator Schedule file to direct users to the Redirection File. When you specify this parameter, each jump to an advertiser's URL is recorded in the Web server activity logs.
 
The Ad Rotator relies on two additional files for parameters and functionality:
 

Redirection File

An optional file that implements redirection and enables the Ad Rotator component to record how many users click on each advertisement.

Rotator Schedule File

A text file that contains the display schedule and file information for advertisements. This file must be available on a Web server virtual path.

The control makes use of no registry settings.

The Ad Rotator Control is registered with the ProgId of "MSWC.AdRotator". The following VBScript excerpt shows creating an instance of the control.
 

Set adRot = Server.CreateObject( "MSWC.AdRotator" )

The Ad Rotator Control exposes the following properties and methods.

The properties are:

Border
Clickable  
TargetFrame


The method is GetAdvertisement.

 

Properties Details

1. The Border property enables you to specify whether to display the advertisements with a surrounding border

Syntax:

Border = size

Parameters:

size

Specifies the thickness of the border that surrounds the displayed advertisement. The default is the value set in the header of Rotator Schedule file. 0 specifies no border.

2. The Clickable property enables you to specify whether the advertisements are displayed as hyperlinks.

Syntax:

Clickable = value

Parameters:

value

Specifies whether the advertisement should be a hyperlink. This parameter can set to either TRUE or FALSE. If false only the image is displayed - without a "click-through" hyperlink. The default value is TRUE.

3. The TargetFrame property specifies the target frame into which the link should be loaded. This property fulfils the same function as the TARGET parameter in an HTML anchor statement.

Syntax:

TargetFrame = frame

Parameters:

frame

Specifies the name of the frame in which to display the advertisement. This parameter can also be one of the HTML frame-keywords, such as _TOP, NEW, CHILD, _SELF, _PARENT, or _BLANK. The default value is NO FRAME.

 

Method Details

The GetAdvertisement method retrieves the next advertisement from the Rotator Schedule file. Each time the script is run, such as when a user opens or refreshes a page, the method retrieves the next scheduled advertisement.

Arguments:

rotationSchedulePath

Specifies the location of the Rotator Schedule file relative to the virtual directory. For example, if the physical path was C:\Inetpub\Wwwroot\Ads\Adrot.txt (where Wwwroot is the "/" virtual directory) you would specify the path \Ads\Adrot.txt.

Return Values:

Returns HTML that displays the advertisement in the current page.

Example:

The following example gets an advertisement from the Adrot.txt file in the /Ads/ virtual directory.
<% Set NextAd = Server.CreateObject("MSWC.AdRotator") %>
<%= NextAd.GetAdvertisement("/ads/adrot.txt") %>

Example HTML Output:

Assuming the following fragment of a redirection file is chosen by the control:

REDIRECT /foo/bar.asp
WIDTH 88
HEIGHT 40
BORDER 1
*
/ads/picture.gif
http://www.chilisoft.com/info/index.html
Hello from Chilisoft.
90

The HTML that is produced is:

<A HREF= "/foo/bar.asp?url=http://www.chilisoft.com/
info/index.html&image=/ads/picture.gif TARGET="_blank">

<IMG SRC="/ads/picture.gif" ALT="Hello from Chilisoft" WIDTH=88 HEIGHT=40 BORDER = 1>

</A>

The Redirect script "foo/bar.asp" is invoked and can record click through information before redirecting the client browser to the user's desired location.

The Rotator Schedule file contains information that the Ad Rotator component uses to manage and display the various advertisement images. In it you can specify the details for the advertisements, such as the size of the advertisement space, the image files to use, and the percentage of time that each file should be displayed.
 
The Rotator Schedule file has two sections. The first section sets parameters that apply to all advertisement images in the rotation schedule. The second section specifies file and location information for each individual advertisement and the percentage of display time that each advertisement should receive. The two sections are separated by a line containing only an asterisk (*).
 
In the first section there are four global parameters, each consisting of a keyword and a value. All are optional. If you do not specify values for the global parameters, the Ad Rotator uses default values. In this case, the first line of the file must contain only an asterisk (*).

Syntax:

[REDIRECT URL]
[WIDTH numWidth]
[HEIGHT numHeight]
[BORDER numBorder]
*
adURL
adHomePageURL
Text
impressions

Parameters:

URL
Specifies the path to the dynamic-link library (.dll) or application (.asp) file that implements redirection. This path can be specified either fully (http://MyServer/MyDir/redirect.asp) or relative to the virtual directory (/MyDir/redirect.asp).

numWidth
 Specifies the width of the advertisement on the page, in pixels. The default is 440 pixels.

numHeight
Specifies the height of the advertisement on the page, in pixels. The default is 60 pixels.

numBorder
 Specifies the thickness of the hyperlink border around the advertisement, in pixels. The default is a 1-pixel border. Set this parameter to 0 for no border.

adURL
The location of the advertisement image file.

adHomePageURL
The location of the advertiser's home page. If the advertiser does not have a home page, put a hyphen (-) on this line to indicate that there is no link for this ad.

Text
Alternate text that is displayed if the browser does not support graphics, or has its graphics capabilities turned off.

impressions
A number between 0 and 10000 that indicates the relative weight of the advertisement.

For example, if a Rotator Schedule file contains three ads with impressions set to 2, 3, and 5, the first advertisement is displayed 20 percent of the time, the second 30 percent of the time, and the third 50 percent of the time.

Remarks:

If the sum of the impressions parameters for all items exceeds 10000, an error will be generated the first time the Rotator Schedule file is accessed by a call to the GetAdvertisement method.

Example 1:

The following example script demonstrates how you can use a rotator schedule file to display a variety of advertisements and how to include a redirection file.

---ADROT.TXT---
REDIRECT /scripts/adredir.asp
WIDTH 440
HEIGHT 60
BORDER 1
*
http://kabaweb/ads/homepage/chlogolg.gif
http://www.bytecomp.com/
Check out the ByteComp Technology Center
20
http://kabaweb/ads/homepage/gamichlg.gif
-
Sponsored by Flyteworks
20
http://kabaweb/ads/homepage/ismodemlg.gif
http:// www.proelectron.com/
28.8 internal PC modem, only $99

80
http://kabaweb/ads/homepage/spranklg.gif
http://www.clocktower.com/
The #1 Sports site on the net
10

The Redirection file is a file that you create. It usually includes script to parse the query string sent by the AdRotator object and to redirect the user to the URL associated with the advertisement that the user clicked on.
 
You can also include script in the Redirection file to count the number of users that have clicked on a particular advertisement, and save this information to a file on the server.

Example 2:

The following example redirects the user to the advertiser's home page.

---ADREDIR.ASP---
<% Response.Redirect(Request.QueryString("url")) %>

  • An example of a creating a simple ad rotating system using ASP can be found at the following URL:

http://www.kamath.com/tutorials/tut006_adrotator.asp