Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 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
35 active users
2090 visitors today
4760 pages today
(only part of today)
Tools I use

CoverYourASP
Copyright © 1999-2010 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

Tiki Statues - Tiki Masks - Tiki Totems



Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?