CODECUBE VENTURES

User Tracking

Tracking information about your users is a very important part of being a webmaster. here's the method I use on this site

Of course you could use tracking programs like webtrendslive, but what fun is it if you don't write it yourself ;)

I track each individual session that is started by a browser to my site... the best way of doing this is by using the session_onstart event of the global.asa file. We begin by creating a table in the database with these fields:

  • accessID: autonumber

  • ip: text

  • browser: text

  • referer: text

  • dateaccesed: datetime

  • url: text

Not a very difficult design, but quite useful... the next step is insert this code into your global.asa file


<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnStart

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; _
DBQ=c:\yoursite\myDB.mdb;User ID=;PassWord=;Persist  _
Security   Info=False"

oConn.Execute "Insert Into accessLog(ip, browser, referer, _
dateaccessed, url) VALUES ('" & Request.ServerVariables _
("REMOTE_ADDR")& "', '" & Request.ServerVariables _
("HTTP_USER_AGENT") & "', '" &  Request.ServerVariables _
("HTTP_REFERER") & "', '" &  date &" "& time & "', '" &  _
Request.ServerVariables("URL") & "?" & request.servervariables _
("query_string") &"')"
oConn.Close
Set oConn = Nothing

End Sub
</script>

Obviously you should replace the connection string with the one pertaining to your database.

This simple user tracking script will allow you to see what [browsers](javascript:alert('this is a test');) you audience is using, what sites are sending traffic your way, what times of the day, or days of the week they visit. all very important information to know.

Good luck... and if you use this script in your site... could you Send me an email just so I know I did some good in this world?

Latest post: Digging Up the First Version of CodeCube

See more in the archives