A complete banner advertising system

Page 3 of 4
  1. Introduction
  2. Serving the ads
  3. Managing impressions and clickthroughs
  4. The BannerStats table

Managing impressions and clickthroughs

In Part 1 we saw how BannerCounter.asp was referenced in the banner HTML we output. Here's how that file works to count the impressions and clickthroughs, and redirect the clicks to the advertisers URL.

BannerCounter.asp is an asp page, but one that outputs no HTML. Simplified source is shown below (you can download the real thing later).

var nBannerID = Request.QueryString( 'ID' ) - 0;
var sRedirect = '' + Request.QueryString( 'CYAredir' );

// the field name to increment in BannerStats
// (impression or click) depending on if redir passed
var sVariable;

if ( sRedirect == 'undefined' )
    sVariable = 'ImpressionCount';
    sVariable = 'ClickCount';

// open database connection
DBInitConnection ( );

// increment count in BannerStats table
oConnection.Execute( 'UPDATE BannerStats SET ' + sVariable + '=' + sVariable + '+1 WHERE BannerDate=' + Application ( 'Date' ) + ' AND BannerID=' + nBannerID );

// close connection
DBReleaseConnection ( );

// redirect to URL if clickthrough
if ( sRedirect != 'undefined' )
Response.Redirect ( sRedirect ) ;

This file is called in two different ways. The first way is as the target of an <img> tag, where it simply increments the impression counter in the database. The second way is as the link the banner points to, where it increments the clickthough counter and then redirects the user to the advertisers URL.

The difference is the number of parameters sent in the QueryString. If no "CYAredir" is passed in, then I'm in impression mode. In this case the code above sets sVariable to "ImpressionCount", the name of the field in the BannerStats table that we want to increment. This field is then incremented in the record for that banner on todays date.

We'll see how that record gets into the BannerStats table in a minute.

If there is a "CYAredir" parameter passed in, the "ClickCount" is incremented instead, and then Response.Redirect is used to redirect the user to the advertisers URL.

You might also like...



Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Owning a computer without programming is like having a kitchen and using only the microwave oven” - Charles Petzold