CoverYourASP --> Advertising --> Part 3: Managing clickthroughs

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
81 active users
3553 visitors today
3479 pages today
(only part of today)
Tools I use

CoverYourASP
Copyright © 1999-2013 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

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';
else
   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.

Part 4: The BannerStats table...

Featured sponsor
My favorite resources


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...


New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!