Daily Hits

Another popular web statistic to track is the number of Daily Hits your website receives.  There are several ways to accomplish this using a global.asa file, text file, database, or by using Google Analytics.  In this example, we are using an include file to record the hits in a database.

To do this, create a page called /DailyHits.asp and place it in your /includes/ directory with the code below:

<!--#include virtual="/includes/connection.asp" -->

<%
DIM mySQL, objRS
mySQL = "SELECT * FROM tblDailyHits WHERE DateVisited = #" & Date() & "#;"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText

DIM iRecordCount
iRecordCount = 0

IF objRS.EOF THEN
objRS.AddNew
ELSE
objRS.MoveFirst
iRecordCount = objRS("Hits")
END IF
objRS("Hits") = iRecordCount + 1
objRS.Update
%>

<p>We have <% =objRS("Hits") %> hits today.</p>

<%
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>

Next, we add our /DailyHits.asp include file to every page on our website as seen below:

 

<!-- #include virtual="/includes/dailyhits.asp" -->

<p>The rest of your page here.</p>

Now, you have a count of how many Daily Hits you are receiving on your website.

< Back to ASP Scripts