Simple DIY Web Stats

Now, there’s a lot of web stats 3rd party plugins out there. Google analytics is awesome tool to keep track of your web stats. Statcounter is another tool to keep track of site. However all those information are kept on their website and not yours. Although, you can download the logs, those 3rd party website actually have your website information. So here’s a quick way to create a simple text file to grab some basic website statistics onto your website.

Use this code for classic ASP.

  1. create a text file on your server (.txt)
  2. enter the ASP code into your footer
  3. ASP code will get today’s date, time, url, and IP address of the person viewing your site.
  4. Then the code will read your .txt file, and add onto it the new information

This code is written for easy reading. You may condense/minimize it for your own use. If you’d like to grab more use information, ie browser type, you can ask: Request.ServerVariables(“HTTP_USER_AGENT”)
For the complete list of ASP ServerVariables, please click on this link.

<%
Dim strPath, file, file1, file2, x, tdate, ttime, ipaddress, url
strPath = "/counter.txt"   '// Enter location of a text file to save your log //'
strPath = Server.MapPath(strPath)
Set file1 = Server.CreateObject("Scripting.FileSystemObject")
set file2=file1.OpenTextFile(strPath)
x=file2.ReadAll
tdate=date() 'Get Date'
ttime=time() 'Get Time'
url=Request.ServerVariables("URL")
'Finds IP Address'
Dim strIP : strIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If strIP = "" Then strIP = Request.ServerVariables("REMOTE_ADDR")
ipaddress = strIP
'End Find IP Address'

set file = file1.createTextFile (strPath2)
file.writeline(x)
file.write(tdate)
file.write(", ")
file.write(ttime) 'Write Date, Time to file'
file.write(", "+ipaddress) 'Write IP Address to file'
file.write(", "+url)
%>

What you will end up is something similar to this.

Then you can use any spreadsheet software to pretty it up, make your own graphs, etc…
Again, this is a simple way to create some kind of tracking for your site without the use of 3rd party plugin or program. All the information is yours alone.

Leave a Reply