Make Revenue With Your Own Banner Management System - Handling the banner clicks
(Page 10 of 11 )
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.
Next: Conclusion >>
More ASP Articles
More By Mitchell Harper