Article

Create your own Banner Management Application

Page: 1 2 3 4 5 6 7

Step3: Handling Banner Clicks

Now, for the last - and easiest - step of our project, tracking the click-thrus. A click-thru occurs when a visitor clicks on any of the advertisements displayed on your site. When the visitor clicks the advertisements link, the click-thru count for that banner is updated, and then the visitor is re-directed to the page that contains the information/products relevant to that advertisement.

Remember how our GetBanner() function didn’t link the banner directly to its URL, and linked it to bannerclick.asp instead? Well, bannerclick.asp acts as the intermediate page between our site and the advertiser's site, updating the click-thru rate for that banner and then re-directing the user to the site of the advertiser, as mentioned above.

Without further ado, lets create a new page called bannerclick.asp and save it in the same directory as bannercode.asp. Now type this code into your bannerclick.asp file:

<%@ Language="VBScript" %>      
<!-- METADATA Type="TypeLib" File="c:\program files\common        
files\system\ado\msado15.dll" -->      
     
<%      
 dim objConn      
 dim objRS      
 dim strBannerURL      
     
 set objConn = Server.CreateObject("ADODB.Connection")      
 set objRS = Server.CreateObject("ADODB.Recordset")      
       
 objConn.Open "Provider=SQLOLEDB; Data Source=localhost; Initial        
Catalog=myAdStuff; UId=sa; Pwd="      
 objRS.ActiveConnection = objConn      
 objRS.LockType = adLockReadOnly      
 objRS.CursorType = adUseForwardOnly      
       
 objRS.Open "select bannerURL from banners where bannerId=" &        
Request.QueryString("bannerId")      
 if objRS.EOF then              
   Response.Write "Invalid banner id"      
   Response.End      
 end if      
         
 strBannerURL = objRS("bannerURL")      
 objRS.Close      
     
 objConn.Execute "UPDATE banners SET bannerClickThrus =        
bannerClickThrus + 1 WHERE bannerId = " &      
Request.QueryString("bannerId")      
 objConn.Close      
         
 set objConn = nothing      
 set objRS = nothing      
     
 Response.Redirect(strBannerURL)      
%>

There shouldn’t be much new code here. I’ll just run through a couple of lines, the ones that matter.

 objRS.Open "select bannerURL from banners where bannerId=" &      
Request.QueryString("bannerId")      
     
 if objRS.EOF then      
   Response.Write "Invalid banner id"      
   Response.End      
 end if      
     
 strBannerURL = objRS("bannerURL")

This part of our code opens our recordset object, and selects only the bannerURL field from the record whose id matches the Request.QueryString("bannerId") variable (which comes from the link off the banner). If a record with this id doesn’t exist, then we write "Invalid banner id" to the browser and simply end the page. If it does exist, we assign the value of the bannerURL field to the strBannerURL variable.

 objConn.Execute "UPDATE banners SET bannerClickThrus =        
bannerClickThrus + 1 WHERE bannerId = " &        
Request.QueryString("bannerId")

If we skip a couple of lines down, we use our connection object to increase the number of click-thrus for this banner by one, again using the Request.QueryString("bannerId") as the id of the banner to update.

Response.Redirect(strBannerURL)

Last but not least, we re-direct the visitor to the actual URL behind the banner, and presto, it's all done.

Conclusion

Now that you have an idea of how to write a banner ad management system for your Website, think about how you can use it to generate a steady stream of revenue. Why not combine the code that I’ve described with a couple of other SitePoint.com articles that relate to advertising, and really get serious? If there are trillions of dollars being thrown around the Internet, there should be at least a couple of thousand dollars with your name on them ...right?

Please Note: To keep this article as small as possible, rigorous error handling has been omitted in some cases.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Rate This Article

  • 1
    Poor
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
    Great

Comment on This Article

Have something to say?

Post A Comment

You need to be a member of the SitePoint Forums to comment on this post. Sign Up

Already a member? Post using your SitePoint Forums account: