nathan schmoll's
aspdiscovery

back to main page

e-mail me








Tracking Page Visits Made Easy! -- Part I
With this article I will begin a two-part series on tracking page visits on your web site.

Setting up a database
We will start out by creating a database that will contain all of the URL's and how many times they are visited. In this example, we will make an Access database called "track.mdb". This database will have one table in it called "trackdb". Create two columns in trackdb called "url" and "count" (make sure that url has a maximum value of 250 characters and that count is a number field).

Creating the tracking file
Below is the script that your links will go to in order to track the visits to certain pages.

<%
tg=request.querystring
if tg="" then
%>You must enter a target URL.<%
else
set myconn=server.createobject("ADODB.Connection")
myconn.open _
"Driver={Microsoft Access Driver (*.mdb)}; _
DBQ="&server.mappath("track.mdb")&";"
sql_query="SELECT * FROM trackdb"
set rs=myconn.execute(sql_query)
WHILE NOT RS.EOF
dburl=rs("url")
if dburl=tg then
matchup="1"
end if
rs.movenext
wend
if matchup="1" then
sql_query="SELECT * FROM trackdb WHERE url='"&tg&"'"
set rs=myconn.execute(sql_query)
oldcountnumber=rs("count")
sql_query="UPDATE trackdb SET _
count='"&(cint(oldcountnumber)+1)&"' _
WHERE url='"&tg&"'"
myconn.execute(sql_query)
else
sql_query="INSERT INTO trackdb (url, count) _
values ('"&tg&"', '1')"
myconn.execute(sql_query)
myconn.close
end if
response.redirect(tg)
end if
%>

Linking to the tracking script
In this example, the name of the tracking script will be "track.asp". Let's say that you want to send a visitor to "/articles/howtobuyonline.html". You would make the link go to "track.asp?/articles/howtobuyonline.html". If there is not already a record in the trackdb table for /articles/howtobuyonline.html, one will be created by the script.

Part II
Next, I will talk about creating a script that will show all the URL's that have been passed through track.asp and how many times.

Go to next to part two >>

copyright © 2001, nathan schmoll. all rights reserved. questions? comments? suggestions? e-mail me!